1 #include <gtest/gtest.h> 22 S = MatrixNd::Zero(6, 3);
23 S_o = MatrixNd::Zero(6, 3);
28 double q0 = q[model.
mJoints[joint_id].q_index];
29 double q1 = q[model.
mJoints[joint_id].q_index + 1];
30 double q2 = q[model.
mJoints[joint_id].q_index + 2];
39 model.
X_J[joint_id].E =
40 Matrix3d(c0 * c1, s0 * c1, -s1, c0 * s1 * s2 - s0 * c2, s0 * s1 * s2 + c0 * c2, c1 * s2, c0 * s1 * c2 + s0 * s2, s0 * s1 * c2 - c0 * s2, c1 * c2);
42 c0 * s1 * c2 + s0 * s2, s0 * s1 * c2 - c0 * s2, c1 * c2),
55 double qdot0 = qdot[model.
mJoints[joint_id].q_index];
56 double qdot1 = qdot[model.
mJoints[joint_id].q_index + 1];
57 double qdot2 = qdot[model.
mJoints[joint_id].q_index + 2];
60 model.
v_J[joint_id].set(S * qdotv);
62 S_o(0, 0) = -c1 * qdot1;
63 S_o(1, 0) = -s1 * s2 * qdot1 + c1 * c2 * qdot2;
64 S_o(1, 1) = -s2 * qdot2;
65 S_o(2, 0) = -s1 * c2 * qdot1 - c1 * s2 * qdot2;
66 S_o(2, 1) = -c2 * qdot2;
68 model.
c_J[joint_id] = S_o * qdotv;
76 double q0 = q[model.
mJoints[joint_id].q_index];
77 double q1 = q[model.
mJoints[joint_id].q_index + 1];
78 double q2 = q[model.
mJoints[joint_id].q_index + 2];
88 c0 * s1 * c2 + s0 * s2, s0 * s1 * c2 - c0 * s2, c1 * c2),
113 Matrix3d inertia = Matrix3d::Identity(3, 3);
116 custom_body_id = custom_model.addBodyCustomJoint(0,
SpatialTransform(), custom_joint, body);
118 q = VectorNd::Zero(reference_model.q_size);
119 qdot = VectorNd::Zero(reference_model.qdot_size);
120 qddot = VectorNd::Zero(reference_model.qdot_size);
121 tau = VectorNd::Zero(reference_model.qdot_size);
148 for (
unsigned int i = 0; i < 3; i++)
159 custom_model.bodyFrames[custom_body_id]->getTransformToRoot().E));
168 for (
unsigned int i = 0; i < 3; i++)
206 for (
unsigned int i = 0; i < 3; i++)
213 VectorNd tau_ref = VectorNd::Zero(tau.size());
214 VectorNd tau_cust = VectorNd::Zero(tau.size());
224 for (
unsigned int i = 0; i < 3; i++)
231 MatrixNd H_ref(reference_model.qdot_size, reference_model.qdot_size);
232 MatrixNd H_cust(custom_model.qdot_size, custom_model.qdot_size);
242 for (
unsigned int i = 0; i < 3; i++)
249 VectorNd qddot_ref = VectorNd::Zero(qdot.size());
250 VectorNd qddot_cust = VectorNd::Zero(qdot.size());
260 for (
unsigned int i = 0; i < 3; i++)
268 VectorNd qddot_ref = VectorNd::Zero(qdot.size());
269 VectorNd qddot_cust = VectorNd::Zero(qdot.size());
279 for (
unsigned int i = 0; i < 3; i++)
287 VectorNd tau_ref = VectorNd::Zero(qdot.size());
288 VectorNd tau_cust = VectorNd::Zero(qdot.size());
298 for (
unsigned int i = 0; i < 3; i++)
306 MatrixNd G_cust(3, custom_model.qdot_size);
307 MatrixNd G_ref(3, reference_model.qdot_size);
319 for (
unsigned int i = 0; i < 3; i++)
327 MatrixNd G_cust(6, custom_model.qdot_size);
328 MatrixNd G_ref(6, reference_model.qdot_size);
340 for (
unsigned int i = 0; i < 3; i++)
348 MatrixNd G_cust(6, custom_model.qdot_size);
349 MatrixNd G_ref(6, reference_model.qdot_size);
361 for (
unsigned int i = 0; i < 3; i++)
369 MatrixNd GDot_cust(6, custom_model.qdot_size), GDot_ref(6, custom_model.qdot_size);
381 for (
unsigned int i = 0; i < 3; i++)
389 MatrixNd GDot_cust(3, custom_model.qdot_size), GDot_ref(3, custom_model.qdot_size);
402 for (
unsigned int i = 0; i < 3; i++)
408 MatrixNd A(6, custom_model.qdot_size);
411 Vector3d com, com_velocity, ang_momentum;
427 for (
unsigned int i = 0; i < 3; i++)
435 MatrixNd ADot_cust(6, custom_model.qdot_size), ADot_ref(6, custom_model.qdot_size);
447 for (
unsigned int i = 0; i < 3; i++)
455 MatrixNd GDot_cust(6, custom_model.qdot_size), GDot_ref(6, custom_model.qdot_size);
468 for (
unsigned int i = 0; i < 3; i++)
476 MatrixNd G_cust(6, custom_model.qdot_size);
477 MatrixNd G_ref(6, reference_model.qdot_size);
489 for (
unsigned int i = 0; i < 3; i++)
497 MatrixNd G_cust(6, custom_model.qdot_size);
498 MatrixNd G_ref(6, reference_model.qdot_size);
513 for (
unsigned int i = 0; i < 3; i++)
526 c_cust.
bind(custom_model);
527 c_ref.
bind(reference_model);
550 int main(
int argc,
char** argv)
552 ::testing::InitGoogleTest(&argc, argv);
553 return RUN_ALL_TESTS();
static bool checkVectorNdEpsilonClose(const RobotDynamics::Math::VectorNd &v1, const RobotDynamics::Math::VectorNd &v2, const double epsilon)
void compositeRigidBodyAlgorithm(Model &model, const Math::VectorNd &Q, Math::MatrixNd &H, bool update_kinematics=true)
Computes the joint space inertia matrix by using the Composite Rigid Body Algorithm.
void calcPointJacobian(Model &model, const Math::VectorNd &Q, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics=true)
Computes the 3D point jacobian for a point on a body.
std::vector< Joint > mJoints
All joints.
3 DoF joint that uses Euler ZYX convention (faster than emulated
SpatialVector SpatialVectorZero
Describes all properties of a single body.
std::vector< Math::SpatialVector > c_J
CustomJoint is a struct used to create a joint with user defined parameters. This is accomplished by ...
FrameVector linear() const
Get copy of linear component.
void setAngularPart(const Vector3d &v)
void setLinearPart(const Vector3d &v)
void calcPointJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, Math::MatrixNd &G, bool update_kinematics=true)
Computes the time derivative of the linear components the a point jacobian on a body.
unsigned int addConstraint(unsigned int body_id, const Math::Vector3d &body_point, const Math::Vector3d &world_normal, const char *constraint_name=NULL, double normal_acceleration=0.)
Adds a constraint to the constraint set.
bool checkModelZeroVectorsAndMatrices(RobotDynamics::Model &model)
FrameVector angular() const
Get copy of angular component.
int main(int argc, char **argv)
std::vector< ReferenceFramePtr > bodyFrames
void calcPointJacobian6D(Model &model, const Math::VectorNd &Q, Math::MatrixNd &G, ReferenceFramePtr frame, bool update_kinematics=true)
Compute the 6D point jacobian of the origin of a reference frame If a position of a point is computed...
static bool checkMatrix3dEq(const RobotDynamics::Math::Matrix3d &t1, const RobotDynamics::Math::Matrix3d &t2)
Math::FrameVector calcPointVelocity(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes the velocity of a point on a body.
Structure that contains both constraint information and workspace memory.
unsigned int custom_body_id
void calcPointJacobianDot6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, RobotDynamics::ReferenceFramePtr frame, Math::MatrixNd &G, bool update_kinematics=true)
Computes the time derivative of a point jacobian of a point on a body.
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
virtual void jcalc_X_lambda_S(Model &model, unsigned int joint_id, const Math::VectorNd &q)
virtual void jcalc(Model &model, unsigned int joint_id, const Math::VectorNd &q, const Math::VectorNd &qdot)
void calcCentroidalMomentumMatrixDot(Model &model, const Math::VectorNd &q, const Math::VectorNd &qdot, Math::MatrixNd &Adot, bool update_kinematics=true)
Calculates the time derivative of the centroidal momentum matrix, i.e. the matrix computed by RobotDy...
Describes a joint relative to the predecessor body.
void calcBodySpatialJacobianDot(Model &model, const Math::VectorNd &Q, const Math::VectorNd QDot, unsigned int body_id, Math::MatrixNd &G, const bool update_kinematics=true)
Computes the time derivative of the spatial jacobian for a body. The result will be returned via the ...
static bool checkMatrixNdEpsilonClose(const RobotDynamics::Math::MatrixNd &t1, const RobotDynamics::Math::MatrixNd &t2, const double epsilon)
void calcBodySpatialJacobian(Model &model, const Math::VectorNd &Q, unsigned int body_id, Math::MatrixNd &G, bool update_kinematics=true)
Computes the spatial jacobian for a body. The result will be returned via the G argument and represen...
void updateKinematics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot)
Updates and computes velocities and accelerations of the bodies.
void calcCentroidalMomentumMatrix(Model &model, const Math::VectorNd &q, Math::MatrixNd &A, bool update_kinematics=true)
Calculates the centroidal momentum matrix, for a model. The centroidal momentum matrix is a matrix ...
static bool checkSpatialMatrixEpsilonClose(const RobotDynamics::Math::SpatialMatrix &t1, const RobotDynamics::Math::SpatialMatrix &t2, const double epsilon)
void calcMInvTimesTau(Model &model, const Math::VectorNd &Q, const Math::VectorNd &Tau, Math::VectorNd &QDDot, bool update_kinematics=true)
Computes the effect of multiplying the inverse of the joint space inertia matrix with a vector in lin...
Contains all information about the rigid body model.
void updateKinematicsCustom(Model &model, const Math::VectorNd *Q, const Math::VectorNd *QDot=nullptr, const Math::VectorNd *QDDot=nullptr)
Selectively updates model internal states of body positions, velocities and/or accelerations.
bool bind(const Model &model)
Initializes and allocates memory for the constraint set.
Math types such as vectors and matrices and utility functions.
static bool checkSpatialVectorsEpsilonClose(const RobotDynamics::Math::SpatialVector &v1, const RobotDynamics::Math::SpatialVector &v2, const double epsilon)
unsigned int reference_body_id
void calcCenterOfMass(Model &model, const Math::VectorNd &q, Math::Vector3d &com, bool update_kinematics=true)
Computes the Center of Mass (COM) position.
static bool checkSpatialVectorsEq(const RobotDynamics::Math::SpatialVector &v1, const RobotDynamics::Math::SpatialVector &v2)
A FrameVector is a pair of 3D vector with a ReferenceFrame.
static bool checkVector3dEpsilonClose(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2, const double epsilon)
Math::FrameVectorPair calcPointVelocity6D(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, unsigned int body_id, const Math::Vector3d &point_position, bool update_kinematics=true)
Computes angular and linear velocity of a point that is fixed on a body.
CustomJoint * custom_joint
TEST_F(RdlCustomJointFixture, updateKinematics)
void inverseDynamics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &QDDot, Math::VectorNd &Tau, Math::SpatialForceV *f_ext=nullptr, bool update_kinematics=true)
void forwardDynamics(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, Math::VectorNd &QDDot, Math::SpatialForceV *f_ext=nullptr, bool update_kinematics=true)
Computes forward dynamics with the Articulated Body Algorithm.
std::vector< Math::SpatialTransform > X_J
void nonlinearEffects(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::VectorNd &Tau, bool update_kinematics=true)
Computes the coriolis forces.
Namespace for all structures of the RobotDynamics library.
std::vector< Math::SpatialTransform > X_T
Transformations from the parent body to the frame of the joint.