Kinematic chains
A KDL::Chain is
- a kinematic description of a serial chain of bodies connected by joints.
- build out of KDL::Segments.
A Segment contains
- a KDL::Frame describing the link, it is the pose between the root and the tip of the segment. It cannot only contain a translational part but also a rotational part.
- a joint located at the root of a segment, it can be a translational or a rotational joint, or a fixed joint if the segment is fixed rigidly.
To start from the bottom:
KDL::Joint
When constructing a Joint, you have to define the type of the joint, you can choose from the following:
Joint rx = Joint(Joint::RotX); Joint ry = Joint(Joint::RotY); Joint rz = Joint(Joint::RotZ); Joint tx = Joint(Joint::TransX); Joint ty = Joint(Joint::TransY); Joint tz = Joint(Joint::TransZ); Joint fixed = Joint(Joint::None);
A joint is 1D.
You can get the pose and twist of the joint:
double q = M_PI/4; Frame f = rx.pose(q); double qdot = 0.1; Twist t = rx.twist(qdot);
KDL::Segment
When constructing a Segment you have to give the Joint at the root and the Frame describing the pose to the tip, the constructor takes copies of the arguments, you cannot change the frame or joint afterwards!!!:
Segment s = Segment(Joint(Joint::RotX), Frame(Rotation::RPY(0.0,M_PI/4,0.0), Vector(0.1,0.2,0.3) ));
A segment is still 1D, you can get the pose and the twist of the tip of the segment wrt the root:
double q=M_PI/2; Frame f = s.pose(q); double qdot=0.1; Twist t = s.twist(q,qdot);
When asking the twist of the tip you have to give the position value of the joint because the twist is expressed in the root frame of the segment but the reference point of the Twist is at the tip of the segment.
You can get the pose of the link of the segment, this does not include the pose of the joint!!!
Frame F_link = segment1.getFrameToTip();
KDL::Chain
A Chain has a default constructor, creating an empty chain without any segments and a copy-constructor, creating a copy of an existing chain:
Chain chain1(); Chain chain2(chain3);
Chain are constructed by adding Segments or adding existing chains, to the end of the chain, these functions add copies of the arguments, not the arguments themselves!!!:
chain1.addSegment(segment1); chain1.addChain(chain2);
You can get the number of joints and number of segments (this is not always the same since a segment can have a Joint::None, which is not included in the number of joints):
unsigned int nj = chain1.getNrOfJoints(); unsigned int js = chain1.getNrOfSegments();
You can iterate over the segments of a chain by getting a reference to each successive segment:
Segment& segment3 = chain1.getSegment(3);
