12 #include<Eigen/StdVector> 15 #ifndef __EIGENDEF_FOR_VECTOR__ 16 #define __EIGENDEF_FOR_VECTOR__ 17 EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Twistd)
18 EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Matrix<
double, 6, 6>)
19 EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Rotation3d)
58 std::vector< Matrix<double,6,Dynamic> >
segJdot;
69 Pimpl(
const std::string& robotName)
71 q = VectorXd::Zero(3);
72 dq = VectorXd::Zero(3);
73 Hroot = Displacementd(0,0,0);
74 Troot = Twistd(0,0,0,0,0,0);
76 actuatedDofs = VectorXd::Ones(3);
77 lowerLimits = VectorXd::Constant(3, -10.);
78 upperLimits = VectorXd::Constant(3, 10.);
80 comPosition = Vector3d(0,0,0);
81 comVelocity = Vector3d(0,0,0);
82 comJdotQdot = Vector3d(0,0,0);
83 comJacobian = Matrix<double,3,3>::Zero();
84 comJacobianDot = Matrix<double,3,3>::Zero();
86 M = MatrixXd::Zero(3,3);
87 Minv = MatrixXd::Zero(3,3);
88 B = MatrixXd::Identity(3,3) * 0.001;
89 n = VectorXd::Zero(3);
90 l = VectorXd::Zero(3);
91 g = VectorXd::Zero(3);
93 for (
int i=0; i<4; i++)
95 segPosition.push_back(Displacementd(0,0,0));
96 segVelocity.push_back(Twistd(0,0,0,0,0,0));
97 segJacobian.push_back( Matrix<double,6,3>::Zero() );
98 segJdot.push_back( Matrix<double,6,3>::Zero() );
99 segJdotQdot.push_back(Twistd(0,0,0,0,0,0));
100 jointJacobian.push_back( Matrix<double,6,3>::Zero() );
101 segMass.push_back(1.);
102 segCoM.push_back( Vector3d(0,0,0) );
103 segMassMatrix.push_back( Matrix<double,6,6>::Zero() );
104 segMomentsOfInertia.push_back( Vector3d(0.1,0.1,0.1) );
105 segInertiaAxes.push_back( Rotation3d(1,0,0,0) );
107 std::stringstream name;
108 name <<robotName<<
".segment_"<<i;
109 segName.push_back( name.str() );
111 segNLEffects.push_back( Matrix<double,6,6>::Zero() );
117 segJacobian[0] << 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0;
118 jointJacobian[0] << 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0;
120 segJacobian[1] << 0,0,0, 0,0,0, 0,0,0, 1,0,0, 0,0,0, 0,0,0;
121 jointJacobian[1] << 0,0,0, 0,0,0, 0,0,0, 1,0,0, 0,0,0, 0,0,0;
123 segJacobian[2] << 0,0,0, 0,0,0, 0,0,0, 1,0,0, 0,1,0, 0,0,0;
124 jointJacobian[2] << 0,0,0, 0,0,0, 0,0,0, 1,0,0, 0,1,0, 0,0,0;
126 segJacobian[3] << 0,0,0, 0,0,0, 0,0,0, 1,0,0, 0,1,0, 0,0,1;
127 jointJacobian[3] << 0,0,0, 0,0,0, 0,0,0, 1,0,0, 0,1,0, 0,0,1;
129 for (
int i=0; i<4; i++)
131 segMassMatrix[i].diagonal() << segMomentsOfInertia[i][0], segMomentsOfInertia[i][1], segMomentsOfInertia[i][2], segMass[i], segMass[i], segMass[i];
135 g << 0, 0, 9.80665*segMass[3];
137 for (
int i=1; i<4; i++)
139 M += segJacobian[i].transpose() * segMassMatrix[i] * segJacobian[i];
144 comJacobian = ( segMass[0]*segJacobian[0].bottomRows<3>()
145 + segMass[1]*segJacobian[1].bottomRows<3>()
146 + segMass[2]*segJacobian[2].bottomRows<3>()
147 + segMass[3]*segJacobian[3].bottomRows<3>()
148 )/( segMass[0]+segMass[1]+segMass[2]+segMass[3] );
157 :
ocra::Model(robotName, 3, false)
158 , pimpl( new
Pimpl(robotName))
198 return pimpl->actuatedDofs;
203 return pimpl->lowerLimits;
208 return pimpl->upperLimits;
224 return pimpl->comPosition;
229 return pimpl->comVelocity;
234 return pimpl->comJdotQdot;
239 return pimpl->comJacobian;
244 return pimpl->comJacobianDot;
281 return pimpl->segPosition[index];
286 return pimpl->segVelocity[index];
291 return pimpl->segJacobian[index];
296 return pimpl->segJdot[index];
302 return pimpl->segJdotQdot[index];
308 return pimpl->jointJacobian[index];
314 return pimpl->segMass[index];
320 return pimpl->segCoM[index];
326 return pimpl->segMassMatrix[index];
332 return pimpl->segMomentsOfInertia[index];
339 return pimpl->segInertiaAxes[index];
358 pimpl->Hroot = H_root;
365 pimpl->Troot = T_root;
374 if (pimpl->segName[i] == name)
380 throw( std::string(
"error, cannot find segment with name ") + name );
385 return pimpl->segName[index];
398 pimpl->segPosition[1].x() =pimpl->q[0];
400 pimpl->segPosition[2].x() =pimpl->q[0];
401 pimpl->segPosition[2].y() =pimpl->q[1];
403 pimpl->segPosition[3].x() =pimpl->q[0];
404 pimpl->segPosition[3].y() =pimpl->q[1];
405 pimpl->segPosition[3].z() =pimpl->q[2];
408 pimpl->segVelocity[1].vx() =pimpl->dq[0];
410 pimpl->segVelocity[2].vx() =pimpl->dq[0];
411 pimpl->segVelocity[2].vy() =pimpl->dq[1];
413 pimpl->segVelocity[3].vx() =pimpl->dq[0];
414 pimpl->segVelocity[3].vy() =pimpl->dq[1];
415 pimpl->segVelocity[3].vz() =pimpl->dq[2];
418 pimpl->comPosition = ( pimpl->segMass[0] * pimpl->segPosition[0].getTranslation()
419 + pimpl->segMass[1] * pimpl->segPosition[1].getTranslation()
420 + pimpl->segMass[2] * pimpl->segPosition[2].getTranslation()
421 + pimpl->segMass[3] * pimpl->segPosition[3].getTranslation()
424 pimpl->comVelocity = ( pimpl->segMass[0] * pimpl->segVelocity[0].getLinearVelocity()
425 + pimpl->segMass[1] * pimpl->segVelocity[1].getLinearVelocity()
426 + pimpl->segMass[2] * pimpl->segVelocity[2].getLinearVelocity()
427 + pimpl->segMass[3] * pimpl->segVelocity[3].getLinearVelocity()
440 std::cout<<
"nb segments: "<<
nbSegments()<<
"\n";
445 std::cout<<
"total mass: "<<
getMass()<<
"\n";
virtual void doSetJointPositions(const Eigen::VectorXd &q)
virtual const Eigen::Rotation3d & getSegmentInertiaAxes(int index) const
virtual const Eigen::Vector3d & getCoMVelocity() const
virtual const Eigen::Matrix< double, 3, Eigen::Dynamic > & getCoMJacobian() const
virtual const Eigen::MatrixXd & getInertiaMatrix() const
virtual const Eigen::VectorXd & getJointPositions() const
virtual const Eigen::Twistd & getSegmentVelocity(int index) const
std::vector< Matrix< double, 6, Dynamic > > segJdot
virtual const Eigen::Matrix< double, 6, Eigen::Dynamic > & getJointJacobian(int index) const
virtual double getMass() const
virtual const Eigen::Vector3d & getSegmentMomentsOfInertia(int index) const
Matrix< double, 3, Dynamic > comJacobianDot
virtual const Eigen::MatrixXd & getDampingMatrix() const
std::vector< Matrix< double, 6, 6 > > segNLEffects
virtual int doGetSegmentIndex(const std::string &name) const
Pimpl(const std::string &robotName)
Model3T(const std::string &robotName)
ocra::Model * Create(const std::string &robotName)
Matrix< double, 3, Dynamic > comJacobian
virtual const Eigen::Vector3d & getCoMJdotQdot() const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
virtual const Eigen::Matrix< double, 6, Eigen::Dynamic > & getSegmentJacobian(int index) const
virtual const Eigen::VectorXd & getGravityTerms() const
virtual const Eigen::VectorXd & getJointLowerLimits() const
std::vector< Rotation3d > segInertiaAxes
int getSegmentIndex(const std::string &name) const
std::vector< std::string > segName
virtual const std::string & doGetSegmentName(int index) const
std::vector< Matrix< double, 6, Dynamic > > segJacobian
virtual const Eigen::VectorXd & getActuatedDofs() const
std::vector< Twistd > segVelocity
virtual const Eigen::VectorXd & getJointUpperLimits() const
virtual void doSetFreeFlyerPosition(const Eigen::Displacementd &H_root)
virtual const Eigen::Twistd & getFreeFlyerVelocity() const
virtual const Eigen::Displacementd & getSegmentPosition(int index) const
virtual const Eigen::Vector3d & getSegmentCoM(int index) const
virtual const Eigen::VectorXd & getJointVelocities() const
const std::string & getSegmentName(int index) const
std::vector< Twistd > segJdotQdot
std::vector< double > segMass
virtual void doSetJointVelocities(const Eigen::VectorXd &q_dot)
virtual int nbSegments() const
virtual const Eigen::Matrix< double, 6, 6 > & getSegmentMassMatrix(int index) const
virtual const Eigen::Matrix< double, 6, Eigen::Dynamic > & getSegmentJdot(int index) const
virtual const Eigen::MatrixXd & getInertiaMatrixInverse() const
virtual const Eigen::VectorXd & getNonLinearTerms() const
virtual const Eigen::Twistd & getSegmentJdotQdot(int index) const
std::vector< Vector3d > segMomentsOfInertia
std::vector< Matrix< double, 6, 6 > > segMassMatrix
virtual const Eigen::Matrix< double, 3, Eigen::Dynamic > & getCoMJacobianDot() const
virtual void doSetFreeFlyerVelocity(const Eigen::Twistd &T_root)
std::vector< Matrix< double, 6, Dynamic > > jointJacobian
std::vector< Vector3d > segCoM
std::vector< Displacementd > segPosition
virtual const Eigen::Vector3d & getCoMPosition() const
virtual double getSegmentMass(int index) const
virtual const Eigen::Displacementd & getFreeFlyerPosition() const
virtual const Eigen::VectorXd & getLinearTerms() const