GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: unittest/all-joints.cpp Lines: 74 74 100.0 %
Date: 2024-01-23 21:41:47 Branches: 223 444 50.2 %

Line Branch Exec Source
1
//
2
// Copyright(c) 2015-2021 CNRS INRIA
3
// Copyright(c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4
//
5
6
#include <boost/test/unit_test.hpp>
7
#include <iostream>
8
9
#include "pinocchio/math/fwd.hpp"
10
#include "pinocchio/multibody/joint/joints.hpp"
11
#include "pinocchio/algorithm/rnea.hpp"
12
#include "pinocchio/algorithm/aba.hpp"
13
#include "pinocchio/algorithm/crba.hpp"
14
#include "pinocchio/algorithm/jacobian.hpp"
15
#include "pinocchio/algorithm/compute-all-terms.hpp"
16
17
using namespace pinocchio;
18
19
template<typename JointModel_> struct init;
20
21
template<typename JointModel_>
22
struct init
23
{
24
102
  static JointModel_ run()
25
  {
26
102
    JointModel_ jmodel;
27
102
    jmodel.setIndexes(0,0,0);
28
102
    return jmodel;
29
  }
30
};
31
32
template<typename Scalar, int Options>
33
struct init<pinocchio::JointModelRevoluteUnalignedTpl<Scalar,Options> >
34
{
35
  typedef pinocchio::JointModelRevoluteUnalignedTpl<Scalar,Options> JointModel;
36
37
3
  static JointModel run()
38
  {
39
    typedef typename JointModel::Vector3 Vector3;
40

3
    JointModel jmodel(Vector3::Random().normalized());
41
42
3
    jmodel.setIndexes(0,0,0);
43
3
    return jmodel;
44
  }
45
};
46
47
template<typename Scalar, int Options>
48
struct init<pinocchio::JointModelRevoluteUnboundedUnalignedTpl<Scalar,Options> >
49
{
50
  typedef pinocchio::JointModelRevoluteUnboundedUnalignedTpl<Scalar,Options> JointModel;
51
52
3
  static JointModel run()
53
  {
54
    typedef typename JointModel::Vector3 Vector3;
55

3
    JointModel jmodel(Vector3::Random().normalized());
56
57
3
    jmodel.setIndexes(0,0,0);
58
3
    return jmodel;
59
  }
60
};
61
62
template<typename Scalar, int Options>
63
struct init<pinocchio::JointModelPrismaticUnalignedTpl<Scalar,Options> >
64
{
65
  typedef pinocchio::JointModelPrismaticUnalignedTpl<Scalar,Options> JointModel;
66
67
3
  static JointModel run()
68
  {
69
    typedef typename JointModel::Vector3 Vector3;
70

3
    JointModel jmodel(Vector3::Random().normalized());
71
72
3
    jmodel.setIndexes(0,0,0);
73
3
    return jmodel;
74
  }
75
};
76
77
template<typename Scalar, int Options, template<typename,int> class JointCollection>
78
struct init<pinocchio::JointModelTpl<Scalar,Options,JointCollection> >
79
{
80
  typedef pinocchio::JointModelTpl<Scalar,Options,JointCollection> JointModel;
81
82
3
  static JointModel run()
83
  {
84
    typedef pinocchio::JointModelRevoluteTpl<Scalar,Options,0> JointModelRX;
85
3
    JointModel jmodel((JointModelRX()));
86
87
3
    jmodel.setIndexes(0,0,0);
88
3
    return jmodel;
89
  }
90
};
91
92
template<typename Scalar, int Options, template<typename,int> class JointCollection>
93
struct init<pinocchio::JointModelCompositeTpl<Scalar,Options,JointCollection> >
94
{
95
  typedef pinocchio::JointModelCompositeTpl<Scalar,Options,JointCollection> JointModel;
96
97
3
  static JointModel run()
98
  {
99
    typedef pinocchio::JointModelRevoluteTpl<Scalar,Options,0> JointModelRX;
100
    typedef pinocchio::JointModelRevoluteTpl<Scalar,Options,1> JointModelRY;
101

3
    JointModel jmodel((JointModelRX()));
102

3
    jmodel.addJoint(JointModelRY());
103
104
3
    jmodel.setIndexes(0,0,0);
105
3
    return jmodel;
106
  }
107
};
108
109
template<typename JointModel_>
110
struct init<pinocchio::JointModelMimic<JointModel_> >
111
{
112
  typedef pinocchio::JointModelMimic<JointModel_> JointModel;
113
114
18
  static JointModel run()
115
  {
116
18
    JointModel_ jmodel_ref = init<JointModel_>::run();
117
118
18
    JointModel jmodel(jmodel_ref,1.,0.);
119
18
    jmodel.setIndexes(0,0,0);
120
121
36
    return jmodel;
122
  }
123
};
124
125
BOOST_AUTO_TEST_SUITE(joint_model_base_test)
126
127
template<typename TestDerived>
128
struct TestJointModel
129
{
130
  template<typename JointModel>
131
132
  void operator()(const pinocchio::JointModelBase<JointModel> &) const
132
  {
133
144
    JointModel jmodel = init<JointModel>::run();
134
264
    return TestDerived::test(jmodel);
135
  }
136
};
137
138
struct TestJointModelIsEqual : TestJointModel<TestJointModelIsEqual>
139
{
140
  template<typename JointModel>
141
44
  static void test(const JointModelBase<JointModel> & jmodel)
142
  {
143
48
    JointModel jmodel_copy = jmodel.derived();
144



44
    BOOST_CHECK(jmodel_copy == jmodel);
145
146
48
    JointModel jmodel_any;
147



44
    BOOST_CHECK(jmodel_any != jmodel);
148



44
    BOOST_CHECK(!jmodel_any.isEqual(jmodel));
149
44
  }
150
};
151
152
















4
BOOST_AUTO_TEST_CASE(isEqual)
153
{
154
  typedef JointCollectionDefault::JointModelVariant JointModelVariant;
155
2
  boost::mpl::for_each<JointModelVariant::types>(TestJointModelIsEqual());
156
157
2
  JointModelRX joint_revolutex;
158
2
  JointModelRY joint_revolutey;
159
160



2
  BOOST_CHECK(joint_revolutex != joint_revolutey);
161
162
4
  JointModel jmodelx(joint_revolutex);
163
2
  jmodelx.setIndexes(0,0,0);
164

2
  TestJointModelIsEqual()(JointModel());
165
166
4
  JointModel jmodel_any;
167



2
  BOOST_CHECK(jmodel_any != jmodelx);
168
2
}
169
170
struct TestJointModelCast : TestJointModel<TestJointModelCast>
171
{
172
  template<typename JointModel>
173
44
  static void test(const JointModelBase<JointModel> & jmodel)
174
  {
175
    typedef typename JointModel::Scalar Scalar;
176



44
    BOOST_CHECK(jmodel == jmodel);
177



44
    BOOST_CHECK(jmodel.template cast<Scalar>().isEqual(jmodel));
178



44
    BOOST_CHECK(jmodel.template cast<Scalar>() == jmodel);
179




44
    BOOST_CHECK(jmodel.template cast<long double>().template cast<double>() == jmodel);
180
44
  }
181
};
182
183
















4
BOOST_AUTO_TEST_CASE(cast)
184
{
185
  typedef JointCollectionDefault::JointModelVariant JointModelVariant;
186
2
  boost::mpl::for_each<JointModelVariant::types>(TestJointModelCast());
187
188

2
  TestJointModelCast()(JointModel());
189
2
}
190
191
struct TestJointModelDisp : TestJointModel<TestJointModelDisp>
192
{
193
  template<typename JointModel>
194
44
  static void test(const JointModelBase<JointModel> & jmodel)
195
  {
196
    typedef typename JointModel::JointDataDerived JointData;
197
198


44
    std::cout << "shortname: " << jmodel.shortname() << std::endl;
199


44
    std::cout << "classname: " << jmodel.classname() << std::endl;
200

44
    std::cout << "disp:\n" << jmodel << std::endl;
201
202
48
    JointData jdata = jmodel.createData();
203
204


44
    std::cout << "shortname: " << jdata.shortname() << std::endl;
205


44
    std::cout << "classname: " << jdata.classname() << std::endl;
206

44
    std::cout << "disp:\n" << jdata << std::endl;
207
44
  }
208
};
209
210
















4
BOOST_AUTO_TEST_CASE(test_disp)
211
{
212
  typedef JointCollectionDefault::JointModelVariant JointModelVariant;
213
2
  boost::mpl::for_each<JointModelVariant::types>(TestJointModelDisp());
214
215

2
  TestJointModelDisp()(JointModel());
216
2
}
217
218
BOOST_AUTO_TEST_SUITE_END()