5 #ifndef __RDL_UNIT_TEST_UTILS_HP__ 6 #define __RDL_UNIT_TEST_UTILS_HP__ 29 for (
unsigned int i = 0; i < model.
ndof0_vec.rows(); i++)
37 for (
unsigned int i = 0; i < model.
q0_vec.rows(); i++)
45 for (
unsigned int i = 0; i < model.
nbodies0_vec.rows(); i++)
53 for (
unsigned int i = 0; i < model.
ndof0_mat.rows(); i++)
55 for (
unsigned int j = 0; j < model.
ndof0_mat.cols(); j++)
64 for (
unsigned int i = 0; i < model.
three_x_qd0.rows(); i++)
66 for (
unsigned int j = 0; j < model.
three_x_qd0.cols(); j++)
79 for (
unsigned int j = 0; j < custom_joint->
mDoFCount; j++)
94 double val = (2000.0 * rand() / RAND_MAX - 1000.0);
95 return static_cast<T
>(val);
101 double val = (fabs((max - min)) * rand() / RAND_MAX + min);
102 return static_cast<T
>(val);
108 point.
x() = getRandomNumber<double>();
109 point.
y() = getRandomNumber<double>();
110 point.
z() = getRandomNumber<double>();
115 template <
typename T>
118 double angle = 2 * (M_PI - 0.01) * rand() / RAND_MAX - (M_PI - 0.01);
119 return static_cast<T
>(angle);
124 for (
int i = 0; i < 6; i++)
126 for (
int j = 0; j < 6; j++)
128 if (fabs(t1(i, j) - t2(i, j)) > epsilon)
140 for (
int i = 0; i < 3; i++)
142 for (
int j = 0; j < 3; j++)
144 if (fabs(t1(i, j) - t2(i, j)) > epsilon)
156 if (t1.rows() != t2.rows() || t1.cols() != t2.cols())
161 for (
int i = 0; i < t1.rows(); i++)
163 for (
int j = 0; j < t1.cols(); j++)
165 if (fabs(t1(i, j) - t2(i, j)) > epsilon)
177 if (t1.rows() != t2.rows() || t1.cols() != t2.cols())
182 for (
int i = 0; i < t1.rows(); i++)
184 for (
int j = 0; j < t1.cols(); j++)
186 if (t1(i, j) != t2(i, j))
198 for (
int i = 0; i < 3; i++)
200 for (
int j = 0; j < 3; j++)
202 if (t1(i, j) != t2(i, j))
214 for (
int i = 0; i < 3; i++)
227 for (
int i = 0; i < 4; i++)
240 if (v1.rows() != v2.rows())
245 for (
int i = 0; i < v1.rows(); i++)
258 for (
int i = 0; i < 3; i++)
260 if (fabs(v1(i) - v2(i)) > epsilon)
277 for (
int i = 0; i < 4; i++)
279 if (fabs(v1(i) - v2(i)) > epsilon)
290 if (v1.rows() != v2.rows())
295 for (
int i = 0; i < v1.rows(); i++)
297 if (fabs(v1(i) - v2(i)) > epsilon)
308 for (
int i = 0; i < 6; i++)
310 if (fabs(v1(i) - v2(i)) > epsilon)
321 for (
int i = 0; i < 6; i++)
334 for (
int i = 0; i < frames.size(); i++)
342 int index = rand() % frames.size();
344 return frames[index];
360 if (frame->getParentFrame() ==
nullptr)
367 while (parent !=
nullptr)
369 transform = parent->getTransformToParent() * transform;
370 parent = parent->getParentFrame();
417 for (
unsigned int i = 0; i < model.
mBodies.size(); i++)
422 unsigned int q_index = model.
mJoints[i].q_index;
428 x[model.
q_size + q_index + 1] = x_0[model.
q_size + q_index + 1] + h * dx[model.
dof_count + q_index + 1];
429 x[model.
q_size + q_index + 2] = x_0[model.
q_size + q_index + 2] + h * dx[model.
dof_count + q_index + 2];
432 Vector3d w_n(QDot[q_index], QDot[q_index + 1], QDot[q_index + 2]);
433 Vector3d w_bar = (w_np1 + w_n) / 2.0;
434 Vector3d w_bar_axis = w_bar / w_bar.norm();
435 Vector3d first_order_term = (h / 24.0) * (w_n.cross(w_np1));
444 x[q_index] = new_q[0];
445 x[q_index + 1] = new_q[1];
446 x[q_index + 2] = new_q[2];
451 unsigned int idx = model.
mJoints[i].q_index;
452 x[idx] = x_0[idx] + h * dx[idx];
498 q = q_n + (h / 2.) * k1.head(model.
q_size);
499 qdot = qdot_n + (h / 2.) * k1.tail(model.
qdot_size);
506 q = q_n + (h / 2.) * k2.head(model.
q_size);
507 qdot = qdot_n + (h / 2.) * k2.tail(model.
qdot_size);
514 q = q_n + h * k3.head(model.
q_size);
515 qdot = qdot_n + h * k3.tail(model.
qdot_size);
527 x = x_0 + (h / 6.) * (k1 + 2. * k2 + 2. * k3 + k4);
531 #endif //__UNIT_TEST_UTILS__ EIGEN_STRONG_INLINE double & x()
static bool checkVectorNdEpsilonClose(const RobotDynamics::Math::VectorNd &v1, const RobotDynamics::Math::VectorNd &v2, const double epsilon)
std::vector< SpatialForce, Eigen::aligned_allocator< SpatialForce > > SpatialForceV
std::vector< Joint > mJoints
All joints.
ReferenceFramePtr getReferenceFrame() const
Get a pointer to the reference frame this FrameObject is expressed in.
static ReferenceFramePtr createRandomUnchangingFrame(const std::string &frameName, ReferenceFramePtr parentFrame, const unsigned int movableBodyId)
Math::Quaternion GetQuaternion(unsigned int i, const Math::VectorNd &Q) const
Gets the quaternion for body i (only valid if body i is connected by a JointTypeSpherical joint) ...
std::vector< unsigned int > multdof3_w_index
CustomJoint is a struct used to create a joint with user defined parameters. This is accomplished by ...
SpatialTransform Xroty(const double &yrot)
Get transform with zero translation and pure rotation about y axis.
FrameVector linear() const
Get copy of linear component.
static ReferenceFramePtr getARandomFrame(std::vector< ReferenceFramePtr > frames)
bool checkModelZeroVectorsAndMatrices(RobotDynamics::Model &model)
FrameVector angular() const
Get copy of angular component.
static Quaternion toQuaternion(const Vector3d &axis, double angle_rad)
Get quaternion representation of axis and angle.
static bool checkVector4dEpsilonClose(const RobotDynamics::Math::Vector4d &v1, const RobotDynamics::Math::Vector4d &v2, const double epsilon)
Math::VectorNd nbodies0_vec
static Point3d getRandomPoint3()
static bool checkMatrix3dEq(const RobotDynamics::Math::Matrix3d &t1, const RobotDynamics::Math::Matrix3d &t2)
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
static bool checkVector3dEq(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2)
unsigned int q_size
The size of the -vector. For models without spherical joints the value is the same as Model::dof_coun...
std::vector< Body > mBodies
All bodies 0 ... N_B, including the base.
static T getRandomNumber(T min, T max)
static RobotDynamics::Math::SpatialTransform getTransformToRootByClimbingTree(ReferenceFramePtr frame)
ReferenceFrame object used to tell what frame objects are expressed in. Every ReferenceFrame has a po...
Quaternion that are used for singularity free joints.
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
static bool checkMatrixNdEpsilonClose(const RobotDynamics::Math::MatrixNd &t1, const RobotDynamics::Math::MatrixNd &t2, const double epsilon)
static T getRandomAngle()
void integrateRk4(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::VectorNd &x, const Math::VectorNd &tau, double h, Math::SpatialForceV *f_ext=nullptr)
Using a Runge-Kutta 4th order algorithm, integrate the system dynamics one step.
std::vector< CustomJoint * > mCustomJoints
static bool checkSpatialMatrixEpsilonClose(const RobotDynamics::Math::SpatialMatrix &t1, const RobotDynamics::Math::SpatialMatrix &t2, const double epsilon)
Contains all information about the rigid body model.
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)
static bool checkVector4dEq(const RobotDynamics::Math::Vector4d &v1, const RobotDynamics::Math::Vector4d &v2)
EIGEN_STRONG_INLINE double & y()
void integrateEuler(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, Math::VectorNd &x, const Math::VectorNd &tau, double h, Math::SpatialForceV *f_ext=nullptr)
Using simple Euler integration, integrate the system dynamics one step.
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::MatrixNd three_x_qd0
static bool checkMatrixNdEq(const RobotDynamics::Math::MatrixNd &t1, const RobotDynamics::Math::MatrixNd &t2)
static RobotDynamics::Math::SpatialTransform createRandomSpatialTransform()
3 DoF joint using Quaternions for joint positional variables and
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.
EIGEN_STRONG_INLINE double & z()
static bool checkVectorNdEq(const RobotDynamics::Math::VectorNd &v1, const RobotDynamics::Math::VectorNd &v2)
static void updateAllFrames(std::vector< ReferenceFramePtr > frames)
unsigned int dof_count
number of degrees of freedoms of the model
static bool checkFrameVectorPairEpsilonClose(const RobotDynamics::Math::FrameVectorPair &v1, const RobotDynamics::Math::FrameVectorPair &v2, const double epsilon)
Namespace for all structures of the RobotDynamics library.
static bool checkMatrix3dEpsilonClose(const RobotDynamics::Math::Matrix3d &t1, const RobotDynamics::Math::Matrix3d &t2, const double epsilon)
unsigned int qdot_size
The size of the.