JointTests.cpp
Go to the documentation of this file.
1 //
2 // Created by jordan on 3/5/17.
3 //
4 
5 #include <gtest/gtest.h>
6 #include "rdl_dynamics/Joint.h"
7 #include "UnitTestUtils.hpp"
8 #include "rdl_dynamics/Model.h"
9 
10 using namespace RobotDynamics;
11 
12 class JointTestsFixture : public testing::Test
13 {
14 };
15 
16 TEST_F(JointTestsFixture, testJointJcalc_XJ)
17 {
18  Model m;
19  Body b(1., Vector3d(1., 0., 0.), Vector3d(1., 1., 1.));
20  Joint j(JointTypeRevolute, Vector3d(1., 0., 0.));
21  unsigned int id = m.addBody(0, RobotDynamics::Math::SpatialTransform(), j, b);
22  VectorNd q(m.q_size);
23  q[0] = 0.1;
24  SpatialTransform X_calc = RobotDynamics::jcalc_XJ(m, id, q);
25 
27 
30  try
31  {
32  X_calc = RobotDynamics::jcalc_XJ(m, id, q);
33  FAIL();
34  }
36  {
37  EXPECT_STREQ(e.what(), "Error: invalid joint type!");
38  }
39 }
40 
41 TEST_F(JointTestsFixture, testJointTypeConstructor)
42 {
44  EXPECT_EQ(j1.mDoFCount, 1);
45  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEq(SpatialVector(1., 0., 0., 0., 0., 0.), *j1.mJointAxes));
46 
48  EXPECT_EQ(j2.mDoFCount, 1);
49  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEq(SpatialVector(0., 1., 0., 0., 0., 0.), *j2.mJointAxes));
50 
52  EXPECT_EQ(j3.mDoFCount, 1);
53  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEq(SpatialVector(0., 0., 1., 0., 0., 0.), *j3.mJointAxes));
54 
55  Joint j4(JointType5DoF);
56  EXPECT_EQ(j4.mDoFCount, 5);
57 
58  try
59  {
61  FAIL();
62  }
64  {
65  EXPECT_STREQ(e.what(), "Error: Invalid use of Joint constructor Joint(JointType type). Only allowed when type != JointTypeCustom");
66  }
67 
68  try
69  {
71  FAIL();
72  }
74  {
75  EXPECT_STREQ(e.what(), "Error: Invalid use of Joint constructor Joint(JointType type).");
76  }
77 }
78 
79 TEST_F(JointTestsFixture, testJointNumDegFreedomConstructor)
80 {
81  try
82  {
83  Joint j1(JointType6DoF, 3);
84  FAIL();
85  }
87  {
88  EXPECT_STREQ(e.what(), "Error: Invalid use of Joint constructor Joint(JointType type, int degreesOfFreedom). Only allowed when type == JointTypeCustom.");
89  }
90 
91  Joint j1(JointTypeCustom, 1);
92  EXPECT_EQ(j1.mDoFCount, 1);
93 }
94 
95 TEST_F(JointTestsFixture, testJointTypeAxisConstructor)
96 {
97  Joint j(JointTypeRevolute, Vector3d(1., 0., 0.));
98 
99  EXPECT_TRUE(unit_test_utils::checkSpatialVectorsEq(*j.mJointAxes, SpatialVector(1., 0., 0., 0., 0., 0.)));
100 }
101 
102 TEST_F(JointTestsFixture, testValidateSpatialAxis)
103 {
104  SpatialVector v(1., 1., 1., 1., 1., 1.);
105  Joint j;
106 
107  EXPECT_FALSE(j.validate_spatial_axis(v));
108 }
109 
110 int main(int argc, char** argv)
111 {
112  ::testing::InitGoogleTest(&argc, argv);
113  return RUN_ALL_TESTS();
114 }
int main(int argc, char **argv)
Definition: JointTests.cpp:110
Describes all properties of a single body.
Definition: Body.h:30
User defined joints of varying size.
Definition: Joint.h:213
const double TEST_PREC
SpatialMatrix toMatrix() const
Return transform as 6x6 spatial matrix.
unsigned int appendBody(const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Adds a Body to the model such that the previously added Body is the Parent.
Definition: Model.cc:517
unsigned int addBody(const unsigned int parent_id, const Math::SpatialTransform &joint_frame, const Joint &joint, const Body &body, std::string body_name="")
Connects a given body to the model.
Definition: Model.cc:271
bool validate_spatial_axis(Math::SpatialVector &axis)
Checks whether we have pure rotational or translational axis.
Definition: Joint.h:598
unsigned int q_size
The size of the -vector. For models without spherical joints the value is the same as Model::dof_coun...
Definition: Model.h:178
Compact representation of spatial transformations.
Emulated 6 DoF joint.
Definition: Joint.h:212
virtual const char * what() const
Describes a joint relative to the predecessor body.
Definition: Joint.h:228
3 DoF joint that uses Euler XYZ convention (faster than emulated
Definition: Joint.h:199
Emulated 5 DoF joint.
Definition: Joint.h:211
Math::SpatialTransform jcalc_XJ(Model &model, unsigned int joint_id, const Math::VectorNd &q)
Definition: Joint.cc:215
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
Eigen::VectorXd VectorNd
Definition: rdl_eigenmath.h:25
unsigned int mDoFCount
Number of degrees of freedom of the joint. Note: CustomJoints.
Definition: Joint.h:633
Math::SpatialVector * mJointAxes
The spatial axes of the joint.
Definition: Joint.h:625
static bool checkSpatialMatrixEpsilonClose(const RobotDynamics::Math::SpatialMatrix &t1, const RobotDynamics::Math::SpatialMatrix &t2, const double epsilon)
Contains all information about the rigid body model.
Definition: Model.h:121
static bool checkSpatialVectorsEq(const RobotDynamics::Math::SpatialVector &v1, const RobotDynamics::Math::SpatialVector &v2)
A custom exception.
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21
TEST_F(JointTestsFixture, testJointJcalc_XJ)
Definition: JointTests.cpp:16


rdl_dynamics
Author(s):
autogenerated on Tue Apr 20 2021 02:25:27