Skip to content

Commit ecf3ed5

Browse files
author
Ruben Smits
committed
Merge pull request orocos#58 from ahoarau/fk_solvers_all_seg_frames_ret
Add possibility to return all the FK frames in a vector
2 parents 967d219 + 6a08716 commit ecf3ed5

File tree

5 files changed

+95
-5
lines changed

5 files changed

+95
-5
lines changed

orocos_kdl/src/chainfksolver.hpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@
3131
#include "solveri.hpp"
3232

3333
namespace KDL {
34-
3534
/**
3635
* \brief This <strong>abstract</strong> class encapsulates a
3736
* solver for the forward position kinematics for a KDL::Chain.
3837
*
3938
* @ingroup KinematicFamily
4039
*/
41-
4240
//Forward definition
4341
class ChainFkSolverPos : public KDL::SolverI {
4442
public:
@@ -52,6 +50,16 @@ namespace KDL {
5250
* @return if < 0 something went wrong
5351
*/
5452
virtual int JntToCart(const JntArray& q_in, Frame& p_out,int segmentNr=-1)=0;
53+
/**
54+
* Calculate forward position kinematics for a KDL::Chain,
55+
* from joint coordinates to cartesian pose.
56+
*
57+
* @param q_in input joint coordinates
58+
* @param p_out reference to a vector of output cartesian poses for all segments
59+
*
60+
* @return if < 0 something went wrong
61+
*/
62+
virtual int JntToCart(const JntArray& q_in, std::vector<KDL::Frame>& p_out,int segmentNr=-1)=0;
5563
virtual ~ChainFkSolverPos(){};
5664
};
5765

@@ -73,7 +81,16 @@ namespace KDL {
7381
* @return if < 0 something went wrong
7482
*/
7583
virtual int JntToCart(const JntArrayVel& q_in, FrameVel& out,int segmentNr=-1)=0;
76-
84+
/**
85+
* Calculate forward position and velocity kinematics, from
86+
* joint coordinates to cartesian coordinates.
87+
*
88+
* @param q_in input joint coordinates (position and velocity)
89+
* @param out output cartesian coordinates for all segments (position and velocity)
90+
*
91+
* @return if < 0 something went wrong
92+
*/
93+
virtual int JntToCart(const JntArrayVel& q_in, std::vector<KDL::FrameVel>& out,int segmentNr=-1)=0;
7794
virtual ~ChainFkSolverVel(){};
7895
};
7996

@@ -98,7 +115,19 @@ namespace KDL {
98115
* @return if < 0 something went wrong
99116
*/
100117
virtual int JntToCart(const JntArrayAcc& q_in, FrameAcc& out,int segmentNr=-1)=0;
101-
118+
/**
119+
* Calculate forward position, velocity and accelaration
120+
* kinematics, from joint coordinates to cartesian coordinates
121+
*
122+
* @param q_in input joint coordinates (position, velocity and
123+
* acceleration
124+
@param out output cartesian coordinates (position, velocity
125+
* and acceleration for all segments
126+
*
127+
* @return if < 0 something went wrong
128+
*/
129+
virtual int JntToCart(const JntArrayAcc& q_in, std::vector<FrameAcc>& out,int segmentNr=-1)=0;
130+
102131
virtual ~ChainFkSolverAcc()=0;
103132
};
104133

orocos_kdl/src/chainfksolverpos_recursive.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,33 @@ namespace KDL {
5656
return 0;
5757
}
5858
}
59+
int ChainFkSolverPos_recursive::JntToCart(const JntArray& q_in, std::vector<Frame>& p_out, int seg_nr) {
60+
unsigned int segmentNr;
61+
if(seg_nr<0)
62+
segmentNr=chain.getNrOfSegments();
63+
else
64+
segmentNr = seg_nr;
5965

66+
if(q_in.rows()!=chain.getNrOfJoints())
67+
return -1;
68+
else if(segmentNr>chain.getNrOfSegments())
69+
return -1;
70+
else if(p_out.size() != segmentNr)
71+
return -1;
72+
else{
73+
std::fill(p_out.begin(),p_out.end(),Frame::Identity());
74+
int j=0;
75+
for(unsigned int i=0;i<segmentNr;i++){
76+
if(chain.getSegment(i).getJoint().getType()!=Joint::None){
77+
p_out[i] = p_out[i]*chain.getSegment(i).pose(q_in(j));
78+
j++;
79+
}else{
80+
p_out[i] = p_out[i]*chain.getSegment(i).pose(0.0);
81+
}
82+
}
83+
return 0;
84+
}
85+
}
6086

6187
ChainFkSolverPos_recursive::~ChainFkSolverPos_recursive()
6288
{

orocos_kdl/src/chainfksolverpos_recursive.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace KDL {
4040
~ChainFkSolverPos_recursive();
4141

4242
virtual int JntToCart(const JntArray& q_in, Frame& p_out, int segmentNr=-1);
43+
virtual int JntToCart(const JntArray& q_in, std::vector<Frame>& p_out, int segmentNr=-1);
4344

4445
private:
4546
const Chain chain;

orocos_kdl/src/chainfksolvervel_recursive.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,38 @@ namespace KDL
6363
return 0;
6464
}
6565
}
66-
}
6766

67+
int ChainFkSolverVel_recursive::JntToCart(const JntArrayVel& in,std::vector<FrameVel>& out,int seg_nr)
68+
{
69+
unsigned int segmentNr;
70+
if(seg_nr<0)
71+
segmentNr=chain.getNrOfSegments();
72+
else
73+
segmentNr = seg_nr;
74+
75+
76+
77+
if(!(in.q.rows()==chain.getNrOfJoints()&&in.qdot.rows()==chain.getNrOfJoints()))
78+
return -1;
79+
else if(segmentNr>chain.getNrOfSegments())
80+
return -1;
81+
else if(out.size()!=chain.getNrOfSegments())
82+
return -1;
83+
else{
84+
std::fill(out.begin(),out.end(),FrameVel::Identity());
85+
int j=0;
86+
for (unsigned int i=0;i<segmentNr;i++) {
87+
//Calculate new Frame_base_ee
88+
if(chain.getSegment(i).getJoint().getType()!=Joint::None){
89+
out[i]=out[i]*FrameVel(chain.getSegment(i).pose(in.q(j)),
90+
chain.getSegment(i).twist(in.q(j),in.qdot(j)));
91+
j++;//Only increase jointnr if the segment has a joint
92+
}else{
93+
out[i]=out[i]*FrameVel(chain.getSegment(i).pose(0.0),
94+
chain.getSegment(i).twist(0.0,0.0));
95+
}
96+
}
97+
return 0;
98+
}
99+
}
100+
}

orocos_kdl/src/chainfksolvervel_recursive.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace KDL
4141
~ChainFkSolverVel_recursive();
4242

4343
virtual int JntToCart(const JntArrayVel& q_in,FrameVel& out,int segmentNr=-1);
44+
virtual int JntToCart(const JntArrayVel& q_in,std::vector<FrameVel>& out,int segmentNr=-1);
4445
private:
4546
const Chain chain;
4647
};

0 commit comments

Comments
 (0)