Index: src/chainjnttojacsolver.hpp =================================================================== --- src/chainjnttojacsolver.hpp (revision 34658) +++ src/chainjnttojacsolver.hpp (working copy) @@ -53,15 +53,19 @@ * * @return always returns 0 */ - int JntToJac(const JntArray& q_in,Jacobian& jac); + int JntToJac(const JntArray& q_in,Jacobian& jac, bool coupled=false); int setLockedJoints(const std::vector locked_joints); + + std::vector getLockedJoints(); + private: const Chain chain; Twist t_tmp; Frame T_tmp; std::vector locked_joints_; int nr_of_unlocked_joints_; + Jacobian jac_tmp; }; } #endif Index: src/chain.hpp =================================================================== --- src/chain.hpp (revision 34658) +++ src/chain.hpp (working copy) @@ -24,6 +24,7 @@ #include "segment.hpp" #include +#include namespace KDL { /** @@ -35,9 +36,14 @@ class Chain { private: int nrOfJoints; + int nrOfIndJoints; int nrOfSegments; + int nrOfUnlockedJoints; + std::vector locked_joints; public: std::vector segments; + Eigen::MatrixXd cm; + /** * The constructor of a chain, a new chain is always empty. * @@ -61,6 +67,16 @@ void addChain(const Chain& chain); /** + * Sets the joints that are locked and the coupling matrix. + * locked_joints is an std vector of bools that indicates which joints + * are locked (true), and which ones are not locked (false). + * cm matrix helps define a kinematic structure with coupled joints + * @param cm The coupling matrix + */ + + int setCoupling(const std::vector locked_joints,const Eigen::MatrixXd& cm); + + /** * Request the total number of joints in the chain.\n * Important: It is not the * same as the total number of segments since a segment does not @@ -69,7 +85,15 @@ * @return total nr of joints */ unsigned int getNrOfJoints()const {return nrOfJoints;}; + /** + * Request the total number of independent joints in the chain. + * It's the Coupling matrix rank. + * @return total nr of independ joints + */ + unsigned int getNrOfIndJoints()const {return nrOfIndJoints;}; + + /** * Request the total number of segments in the chain. * @return total number of segments */ @@ -85,6 +109,11 @@ */ const Segment& getSegment(unsigned int nr)const; + std::vector getLockedJoints() const; + + unsigned int getNrOfUnlockedJoints()const {return nrOfUnlockedJoints;}; + + virtual ~Chain(); }; Index: src/chainiksolvervel_wdls.hpp =================================================================== --- src/chainiksolvervel_wdls.hpp (revision 34658) +++ src/chainiksolvervel_wdls.hpp (working copy) @@ -148,6 +148,7 @@ int maxiter; Eigen::VectorXd tmp; Eigen::MatrixXd tmp_jac; + Eigen::MatrixXd tmp_jac_coupling; Eigen::MatrixXd tmp_jac_weight1; Eigen::MatrixXd tmp_jac_weight2; Eigen::MatrixXd tmp_ts; Index: src/chainjnttojacsolver.cpp =================================================================== --- src/chainjnttojacsolver.cpp (revision 34658) +++ src/chainjnttojacsolver.cpp (working copy) @@ -23,9 +23,9 @@ namespace KDL { - ChainJntToJacSolver::ChainJntToJacSolver(const Chain& _chain): - chain(_chain),locked_joints_(chain.getNrOfJoints(),false), - nr_of_unlocked_joints_(chain.getNrOfJoints()) + ChainJntToJacSolver::ChainJntToJacSolver(const Chain& _chain): + chain(_chain),locked_joints_(chain.getLockedJoints()), + nr_of_unlocked_joints_(chain.getNrOfUnlockedJoints()),jac_tmp(chain.getNrOfUnlockedJoints()) { } @@ -43,12 +43,26 @@ if(!locked_joints_[i]) nr_of_unlocked_joints_++; } + jac_tmp.resize(nr_of_unlocked_joints_); + return(0); } - int ChainJntToJacSolver::JntToJac(const JntArray& q_in,Jacobian& jac) + std::vector ChainJntToJacSolver::getLockedJoints() { - if(q_in.rows()!=chain.getNrOfJoints()||nr_of_unlocked_joints_!=jac.columns()) + return(locked_joints_); + } + + int ChainJntToJacSolver::JntToJac(const JntArray& q_in,Jacobian& jac,bool coupled) + { + int jac_columns; + if(coupled) + jac_columns=chain.getNrOfIndJoints(); + else + jac_columns=nr_of_unlocked_joints_; + if(q_in.rows()!=chain.getNrOfJoints()||jac_columns!=jac.columns()) { + //std::cout<<"incorrect jacobian size or qin size"<getScale(); +%End const char* getTypeName() const; %MethodCode sipRes=sipCpp->getTypeName().data(); @@ -86,10 +90,51 @@ void addSegment(const Segment& segment); void addChain(const Chain& chain); - + int setCoupling(SIP_PYLIST,SIP_PYLIST); +%MethodCode + //void setCoupling(const std::vector locked_joints,const Eigen::MatrixXd& cm); + //cm has to have exactly number of joints rows, and maximum number of joints colums + //unsigned int nOfJoints=sipCpp->chain.getNrOfJoints(); //To check that we are receiving valid data dimensions. This doesn't work, chain is a private member. todo: How can we check for this? Maybe this check should be done when operating with the matrix, and not here? Maybe this check should be done inside the c++ code. + Py_ssize_t length; + PyObject *list=a0; + length=PyList_Size(list); + std::vector locked_joints(length,false); + for (Py_ssize_t r=0;rsetCoupling(locked_joints,cm); + +%End + unsigned int getNrOfJoints()const; + unsigned int getNrOfIndJoints()const; unsigned int getNrOfSegments()const; - + unsigned int getNrOfUnlockedJoints()const; const Segment& getSegment(unsigned int nr)const; }; @@ -326,7 +371,8 @@ PyObject *row; row=PyList_GetItem(list,r); if (numCols!=PyList_Size(row)) { - sipIsErr=1; //todo: raise exception + sipIsErr=1; //todo: raise exception. This means that the other rows don't + // have the same size } for (Py_ssize_t c=0;csetWeightJS(Mq); %End @@ -383,7 +430,23 @@ %End public: ChainJntToJacSolver(const Chain& chain); - int JntToJac(const JntArray& q_in,Jacobian& jac); + int JntToJac(const JntArray& q_in,Jacobian& jac, bool coupled=false); + int setLockedJoints(SIP_PYLIST); +%MethodCode + Py_ssize_t py_size; + double c_item; + PyObject *list=a0; + py_size=PyList_Size(list); + std::vector locked_joints(py_size,false); + for (Py_ssize_t r=0;rsetLockedJoints(locked_joints); + +%End }; Index: src/chain.cpp =================================================================== --- src/chain.cpp (revision 34658) +++ src/chain.cpp (working copy) @@ -20,6 +20,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "chain.hpp" +#include namespace KDL { using namespace std; @@ -27,47 +28,104 @@ Chain::Chain(): segments(0), nrOfJoints(0), - nrOfSegments(0) + nrOfIndJoints(0), + nrOfSegments(0), + cm(), + nrOfUnlockedJoints(0), + locked_joints(0) { } Chain::Chain(const Chain& in):nrOfJoints(0), - nrOfSegments(0) + nrOfSegments(0),nrOfUnlockedJoints(0), + nrOfIndJoints(0),segments(0),cm(), + locked_joints(0) { + //std::cout<<"copying chain constructor"<addSegment(in.getSegment(i)); + this->setCoupling(in.getLockedJoints(),in.cm); } Chain& Chain::operator=(const Chain& arg) { + //std::cout<<"copying operator chain"<setCoupling(arg.getLockedJoints(),arg.cm); return *this; } void Chain::addSegment(const Segment& segment) { + //std::cout<<"add Segment"<addSegment(chain.getSegment(i)); + locked_joints.back()=chain.getLockedJoints()[i]; + } } + int Chain::setCoupling(const std::vector locked_joints,const Eigen::MatrixXd& cm) + { + if(locked_joints.size()!=locked_joints.size()) + return -1; + int nrOfUnlockedJoints_(0); + //std::cout<<"Locked Joints"<locked_joints=locked_joints; + nrOfUnlockedJoints=nrOfUnlockedJoints_; + this->cm=cm; + //std::cout<cm< Chain::getLockedJoints() const + { + return(locked_joints); + } + + Chain::~Chain() { } Index: src/chainiksolvervel_wdls.cpp =================================================================== --- src/chainiksolvervel_wdls.cpp (revision 34658) +++ src/chainiksolvervel_wdls.cpp (working copy) @@ -28,20 +28,21 @@ ChainIkSolverVel_wdls::ChainIkSolverVel_wdls(const Chain& _chain,double _eps,int _maxiter): chain(_chain), jnt2jac(chain), - jac(chain.getNrOfJoints()), - U(MatrixXd::Zero(6,chain.getNrOfJoints())), - S(VectorXd::Zero(chain.getNrOfJoints())), - V(MatrixXd::Zero(chain.getNrOfJoints(),chain.getNrOfJoints())), + jac(chain.getNrOfIndJoints()), + U(MatrixXd::Zero(6,chain.getNrOfIndJoints())), + S(VectorXd::Zero(chain.getNrOfIndJoints())), + V(MatrixXd::Zero(chain.getNrOfIndJoints(),chain.getNrOfIndJoints())), eps(_eps), maxiter(_maxiter), - tmp(VectorXd::Zero(chain.getNrOfJoints())), - tmp_jac(MatrixXd::Zero(6,chain.getNrOfJoints())), - tmp_jac_weight1(MatrixXd::Zero(6,chain.getNrOfJoints())), - tmp_jac_weight2(MatrixXd::Zero(6,chain.getNrOfJoints())), + tmp(VectorXd::Zero(chain.getNrOfIndJoints())), + tmp_jac(MatrixXd::Zero(6,chain.getNrOfUnlockedJoints())), + tmp_jac_coupling(MatrixXd::Zero(6,chain.getNrOfIndJoints())), + tmp_jac_weight1(MatrixXd::Zero(6,chain.getNrOfIndJoints())), + tmp_jac_weight2(MatrixXd::Zero(6,chain.getNrOfIndJoints())), tmp_ts(MatrixXd::Zero(6,6)), - tmp_js(MatrixXd::Zero(chain.getNrOfJoints(),chain.getNrOfJoints())), + tmp_js(MatrixXd::Zero(chain.getNrOfIndJoints(),chain.getNrOfIndJoints())), weight_ts(MatrixXd::Identity(6,6)), - weight_js(MatrixXd::Identity(chain.getNrOfJoints(),chain.getNrOfJoints())), + weight_js(MatrixXd::Identity(chain.getNrOfIndJoints(),chain.getNrOfIndJoints())), lambda(0.0) { } @@ -65,8 +66,11 @@ int ChainIkSolverVel_wdls::CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out) { - jnt2jac.JntToJac(q_in,jac); + jnt2jac.JntToJac(q_in,jac,true); + //std::cout<<"Num Ind joints:"<