-
Notifications
You must be signed in to change notification settings - Fork 429
Generate overload JntToJac function in ChainJntToJacSolver Class to return Jacobians for all segments #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
bf9b26b
1c3a79f
d4bc889
6ecfa26
b09c906
45e8083
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -97,5 +97,65 @@ namespace KDL | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (error = E_NOERROR); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int ChainJntToJacSolver::JntToJac(const JntArray& q_in, std::vector<Jacobian>& jac, int seg_nr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(locked_joints_.size() != chain.getNrOfJoints()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (error = E_NOT_UP_TO_DATE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unsigned int segmentNr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(seg_nr<0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
segmentNr=chain.getNrOfSegments(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
segmentNr = seg_nr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//Initialize Jacobian to zero since only segmentNr columns are computed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SetToZero(jac[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if( q_in.rows()!=chain.getNrOfJoints() || jac[0].columns() != chain.getNrOfJoints()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (error = E_SIZE_MISMATCH); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else if(segmentNr>chain.getNrOfSegments()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (error = E_OUT_OF_RANGE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else if(jac.size() < segmentNr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (error = E_SIZE_MISMATCH); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
T_tmp = Frame::Identity(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SetToZero(t_tmp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int j=0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int k=0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Frame total; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Loop through segments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (unsigned int i=0;i<segmentNr;i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ( i!=0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
jac[i] = jac[i-1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//Calculate new Frame_base_ee | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//pose of the new end-point expressed in the base | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
total = T_tmp*chain.getSegment(i).pose(q_in(j)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//changing base of new segment's twist to base frame if it is not locked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//t_tmp = T_tmp.M*chain.getSegment(i).twist(1.0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(!locked_joints_[j]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
t_tmp = T_tmp.M*chain.getSegment(i).twist(q_in(j),1.0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
total = T_tmp*chain.getSegment(i).pose(0.0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+128
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//Changing Refpoint of all columns to new ee | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
changeRefPoint(jac[i],total.p-T_tmp.p,jac[i]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//Only increase jointnr if the segment has a joint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(chain.getSegment(i).getJoint().getType()!=Joint::Fixed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//Only put the twist inside if it is not locked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(!locked_joints_[j]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
jac[i].setColumn(k++,t_tmp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
j++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
T_tmp = total; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (error = E_NOERROR); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+144
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,11 +48,12 @@ namespace KDL | |
* KDL::ChainFkSolverVel_recursive | ||
* | ||
* @param q_in input joint positions | ||
* @param jac output jacobian | ||
* @param jac output jacobian of last segment or array of jacobians for each segment | ||
* @param seg_nr The final segment to compute | ||
* @return success/error code | ||
*/ | ||
virtual int JntToJac(const JntArray& q_in, Jacobian& jac, int seg_nr=-1); | ||
virtual int JntToJac(const JntArray& q_in, std::vector<Jacobian>& jac, int seg_nr=-1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add missing docstring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the missing comment on the Jacobian string output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would copy the entire docstring and make it specific for each set of arguments |
||
|
||
/** | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -815,6 +815,43 @@ void SolverTest::FkPosAndIkPosLocal(Chain& chain,ChainFkSolverPos& fksolverpos, | |
} | ||
|
||
|
||
void SolverTest::JacAllSegments() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add this test in python There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can take a look at this |
||
{ | ||
std::cout << "KDL Jac Solver Test for returning all segment Jacobians" << std::endl; | ||
|
||
double eps = 1e-6; | ||
|
||
unsigned int nj = motomansia10.getNrOfJoints(); | ||
unsigned int ns = motomansia10.getNrOfSegments(); | ||
|
||
JntArray q(nj); | ||
Jacobian jac(nj); | ||
std::vector<Jacobian> jac_all(ns, Jacobian(nj)); | ||
|
||
ChainJntToJacSolver jacsolver(motomansia10); | ||
|
||
// random | ||
q(0) = 0.2; | ||
q(1) = 0.6; | ||
q(2) = 1.; | ||
q(3) = 0.5; | ||
q(4) = -1.4; | ||
q(5) = 0.3; | ||
q(6) = -0.8; | ||
|
||
CPPUNIT_ASSERT_EQUAL((int)SolverI::E_NOERROR, jacsolver.JntToJac(q, jac_all, ns)); | ||
for (unsigned int seg=0; seg<ns; seg++) | ||
{ | ||
jacsolver.JntToJac(q, jac, seg+1); | ||
for ( unsigned int i=0; i<jac.rows(); i++ ) { | ||
for ( unsigned int j=0; j<nj; j++ ) { | ||
CPPUNIT_ASSERT(Equal(jac(i,j), jac_all[seg](i,j), eps)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
void SolverTest::VereshchaginTest() | ||
{ | ||
std::cout << "KDL Vereshchagin Hybrid Dynamics Tests" <<std::endl; | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -469,7 +469,9 @@ void init_kinfam(pybind11::module &m) | |||||||
// ------------------------------ | ||||||||
py::class_<ChainJntToJacSolver, SolverI> chain_jnt_to_jac_solver(m, "ChainJntToJacSolver"); | ||||||||
chain_jnt_to_jac_solver.def(py::init<const Chain&>(), py::arg("chain")); | ||||||||
chain_jnt_to_jac_solver.def("JntToJac", &ChainJntToJacSolver::JntToJac, | ||||||||
chain_jnt_to_jac_solver.def("JntToJac", (int (ChainJntToJacSolver::*)(const JntArray&, Jacobian&, int)) &ChainJntToJacSolver::JntToJac, | ||||||||
py::arg("q_in"), py::arg("jac"), py::arg("seg_nr")=-1); | ||||||||
chain_jnt_to_jac_solver.def("JntToJac", (int (ChainJntToJacSolver::*)(const JntArray&, std::vector<Jacobian>&, int)) &ChainJntToJacSolver::JntToJac, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work yet, see also orocos_kinematics_dynamics/python_orocos_kdl/PyKDL/kinfam.cpp Lines 349 to 351 in ec5d67e
There are multiple ways to work around this. docs I don't like making custom vectors. I would go for converting this to a lamda function, which accepts a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take a look at #497 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made these changes for Craig. These were just a copy/paste of existing code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I am saying is that pybind can't handle references of container arguments. So when a reference container argument is an output of the function, you don't get the update value of the argument. I will be same as when you called the function. So see #497 for how I fixed it for another function with a reference container argument. |
||||||||
py::arg("q_in"), py::arg("jac"), py::arg("seg_nr")=-1); | ||||||||
chain_jnt_to_jac_solver.def("setLockedJoints", &ChainJntToJacSolver::setLockedJoints, py::arg("locked_joints")); | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain why you take the jacobian of the previous segment