GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
#define BOOST_TEST_MODULE test - projection |
||
2 |
#include <boost/test/included/unit_test.hpp> |
||
3 |
#include <hpp/core/fwd.hh> |
||
4 |
#include <hpp/pinocchio/configuration.hh> |
||
5 |
#include <hpp/rbprm/projection/projection.hh> |
||
6 |
#include <pinocchio/fwd.hpp> |
||
7 |
|||
8 |
#include "tools-fullbody.hh" |
||
9 |
using namespace hpp; |
||
10 |
using namespace rbprm; |
||
11 |
using core::value_type; |
||
12 |
|||
13 |
BOOST_AUTO_TEST_SUITE(test_projection) |
||
14 |
|||
15 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(projectToComPositionHyQ) { |
16 |
✓✗ | 4 |
RbPrmFullBodyPtr_t fullBody = loadHyQ(); |
17 |
|||
18 |
✓✗✓✗ |
4 |
core::Configuration_t q_ref(fullBody->device_->configSize()); |
19 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
2 |
q_ref << 0.0, 0.0, 0.6838277139631803, 0.0, 0.0, 0.0, 1.0, |
20 |
✓✗✓✗ ✓✗ |
2 |
0.14279812395541294, 0.934392553166556, -0.9968239786882757, |
21 |
✓✗✓✗ ✓✗ |
2 |
-0.06521258938340457, -0.8831796268418511, 1.150049183494211, |
22 |
✓✗✓✗ ✓✗ |
2 |
-0.06927610020154493, 0.9507443168724581, -0.8739975339028809, |
23 |
✓✗✓✗ ✓✗ |
2 |
0.03995660287873871, -0.9577096766517215, 0.93846028213260710; |
24 |
✓✗ | 4 |
const std::string rLegId("rfleg"); |
25 |
✓✗ | 4 |
const std::string lLegId("lfleg"); |
26 |
✓✗ | 4 |
const std::string rhLegId("rhleg"); |
27 |
✓✗ | 4 |
const std::string lhLegId("lhleg"); |
28 |
|||
29 |
4 |
std::vector<std::string> allLimbs; |
|
30 |
✓✗ | 2 |
allLimbs.push_back(rLegId); |
31 |
✓✗ | 2 |
allLimbs.push_back(lLegId); |
32 |
✓✗ | 2 |
allLimbs.push_back(rhLegId); |
33 |
✓✗ | 2 |
allLimbs.push_back(lhLegId); |
34 |
|||
35 |
✓✗✓✗ |
6 |
State s_init = createState(fullBody, q_ref, allLimbs); |
36 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(s_init.nbContacts, 4); |
37 |
✓✗✓✗ |
2 |
fullBody->device_->currentConfiguration(q_ref); |
38 |
2 |
hpp::pinocchio::Computation_t newflag = |
|
39 |
static_cast<hpp::pinocchio::Computation_t>( |
||
40 |
hpp::pinocchio::JOINT_POSITION | hpp::pinocchio::JACOBIAN | |
||
41 |
hpp::pinocchio::COM); |
||
42 |
✓✗ | 2 |
fullBody->device_->controlComputation(newflag); |
43 |
✓✗ | 2 |
fullBody->device_->computeForwardKinematics(); |
44 |
✓✗✓✗ |
2 |
fcl::Vec3f com_init = fullBody->device_->positionCenterOfMass(); |
45 |
// com position with reference configuration given |
||
46 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_CLOSE(com_init[0], 0.038820542472487805, 1e-6); |
47 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_CLOSE(com_init[1], 0.013905920702454319, 1e-6); |
48 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_CLOSE(com_init[2], 0.64079567046650698, 1e-6); |
49 |
|||
50 |
✓✗ | 2 |
fcl::Vec3f com_goal = com_init; |
51 |
// set an easy com goal position, close to the reference one |
||
52 |
✓✗ | 2 |
com_goal[0] = 0.; |
53 |
✓✗ | 2 |
com_goal[1] = -0.1; |
54 |
✓✗ | 2 |
com_goal[2] = 0.64; |
55 |
|||
56 |
// check if the projection is successfull and the new com is correct |
||
57 |
rbprm::projection::ProjectionReport rep = |
||
58 |
✓✗ | 6 |
rbprm::projection::projectToComPosition(fullBody, com_goal, s_init); |
59 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(rep.success_); |
60 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(rep.result_.nbContacts, 4); |
61 |
|||
62 |
✓✗✓✗ |
2 |
fullBody->device_->currentConfiguration(rep.result_.configuration_); |
63 |
✓✗ | 2 |
fullBody->device_->computeForwardKinematics(); |
64 |
✓✗✓✗ |
2 |
fcl::Vec3f com_pino = fullBody->device_->positionCenterOfMass(); |
65 |
✓✓ | 8 |
for (size_t i = 0; i < 3; ++i) |
66 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
6 |
BOOST_CHECK_SMALL(com_pino[i] - com_goal[i], |
67 |
1e-4); // precision should be the same as the error |
||
68 |
// treshold of the config projector |
||
69 |
|||
70 |
// check if contact position are preserved : |
||
71 |
10 |
for (std::vector<std::string>::const_iterator cit = allLimbs.begin(); |
|
72 |
✓✓ | 18 |
cit != allLimbs.end(); ++cit) { |
73 |
✓✗ | 16 |
rbprm::RbPrmLimbPtr_t limb = fullBody->GetLimbs().at(*cit); |
74 |
8 |
const std::string& limbName = *cit; |
|
75 |
const fcl::Vec3f position = |
||
76 |
✓✗✓✗ ✓✗ |
8 |
limb->effector_.currentTransformation().translation(); |
77 |
✓✓ | 32 |
for (size_t i = 0; i < 3; ++i) |
78 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
24 |
BOOST_CHECK_SMALL(position[i] - s_init.contactPositions_[limbName][i], |
79 |
1e-4); |
||
80 |
} |
||
81 |
|||
82 |
// set a com position a little farther |
||
83 |
✓✗ | 2 |
com_goal[0] = 0.1; |
84 |
✓✗ | 2 |
com_goal[1] = -0.05; |
85 |
✓✗ | 2 |
com_goal[2] = 0.66; |
86 |
// check if the projection is successfull and the new com is correct |
||
87 |
✓✗✓✗ |
2 |
rep = rbprm::projection::projectToComPosition(fullBody, com_goal, s_init); |
88 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(rep.success_); |
89 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(rep.result_.nbContacts, 4); |
90 |
|||
91 |
✓✗✓✗ |
2 |
fullBody->device_->currentConfiguration(rep.result_.configuration_); |
92 |
✓✗ | 2 |
fullBody->device_->computeForwardKinematics(); |
93 |
✓✗✓✗ |
2 |
com_pino = fullBody->device_->positionCenterOfMass(); |
94 |
✓✓ | 8 |
for (size_t i = 0; i < 3; ++i) |
95 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
6 |
BOOST_CHECK_SMALL(com_pino[i] - com_goal[i], |
96 |
1e-4); // precision should be the same as the error |
||
97 |
// treshold of the config projector |
||
98 |
|||
99 |
// check if contact position are preserved : |
||
100 |
10 |
for (std::vector<std::string>::const_iterator cit = allLimbs.begin(); |
|
101 |
✓✓ | 18 |
cit != allLimbs.end(); ++cit) { |
102 |
✓✗ | 16 |
rbprm::RbPrmLimbPtr_t limb = fullBody->GetLimbs().at(*cit); |
103 |
8 |
const std::string& limbName = *cit; |
|
104 |
const fcl::Vec3f position = |
||
105 |
✓✗✓✗ ✓✗ |
8 |
limb->effector_.currentTransformation().translation(); |
106 |
✓✓ | 32 |
for (size_t i = 0; i < 3; ++i) |
107 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
24 |
BOOST_CHECK_SMALL(position[i] - s_init.contactPositions_[limbName][i], |
108 |
1e-4); |
||
109 |
} |
||
110 |
|||
111 |
2 |
srand((unsigned int)(time(NULL))); |
|
112 |
✓✓ | 202 |
for (size_t k = 0; k < 100; ++k) { |
113 |
// randomly sample CoM position close to the reference one : |
||
114 |
✓✗ | 200 |
com_goal[0] = -0.3 + 0.6 * (value_type(rand()) / value_type(RAND_MAX)); |
115 |
✓✗ | 200 |
com_goal[1] = -0.3 + 0.6 * (value_type(rand()) / value_type(RAND_MAX)); |
116 |
✓✗ | 200 |
com_goal[2] = 0.62 + 0.06 * (value_type(rand()) / value_type(RAND_MAX)); |
117 |
// check if the projection is successfull and the new com is correct |
||
118 |
✓✗✓✗ |
200 |
rep = rbprm::projection::projectToComPosition(fullBody, com_goal, s_init); |
119 |
✓✓ | 200 |
if (rep.success_) { |
120 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
130 |
BOOST_CHECK_EQUAL(rep.result_.nbContacts, 4); |
121 |
|||
122 |
✓✗✓✗ |
130 |
fullBody->device_->currentConfiguration(rep.result_.configuration_); |
123 |
✓✗ | 130 |
fullBody->device_->computeForwardKinematics(); |
124 |
✓✗✓✗ |
130 |
com_pino = fullBody->device_->positionCenterOfMass(); |
125 |
✓✓ | 520 |
for (size_t i = 0; i < 3; ++i) |
126 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
390 |
BOOST_CHECK_SMALL(com_pino[i] - com_goal[i], |
127 |
1e-4); // precision should be the same as the error |
||
128 |
// treshold of the config projector |
||
129 |
|||
130 |
// check if contact position are preserved : |
||
131 |
650 |
for (std::vector<std::string>::const_iterator cit = allLimbs.begin(); |
|
132 |
✓✓ | 1170 |
cit != allLimbs.end(); ++cit) { |
133 |
✓✗ | 1040 |
rbprm::RbPrmLimbPtr_t limb = fullBody->GetLimbs().at(*cit); |
134 |
520 |
const std::string& limbName = *cit; |
|
135 |
const fcl::Vec3f position = |
||
136 |
✓✗✓✗ ✓✗ |
520 |
limb->effector_.currentTransformation().translation(); |
137 |
✓✓ | 2080 |
for (size_t i = 0; i < 3; ++i) |
138 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1560 |
BOOST_CHECK_SMALL(position[i] - s_init.contactPositions_[limbName][i], |
139 |
1e-4); |
||
140 |
} |
||
141 |
} |
||
142 |
} |
||
143 |
2 |
} |
|
144 |
|||
145 |
/* |
||
146 |
BOOST_AUTO_TEST_CASE (projectToComPositionSimpleHumanoid) { |
||
147 |
|||
148 |
RbPrmFullBodyPtr_t fullBody = loadSimpleHumanoid(); |
||
149 |
const std::string rLegId("rleg"); |
||
150 |
const std::string lLegId("lleg"); |
||
151 |
|||
152 |
std::vector<std::string> allLimbs; |
||
153 |
allLimbs.push_back(rLegId); |
||
154 |
allLimbs.push_back(lLegId); |
||
155 |
|||
156 |
core::Configuration_t q_ref(fullBody->device_->neutralConfiguration()); |
||
157 |
std::cout<<"q ref = "<<q_ref<<std::endl; |
||
158 |
State s_init = createState(fullBody,q_ref,allLimbs); |
||
159 |
BOOST_CHECK_EQUAL(s_init.nbContacts,2); |
||
160 |
fullBody->device_->currentConfiguration(q_ref); |
||
161 |
pinocchio::Computation_t newflag = static_cast <pinocchio::Computation_t> |
||
162 |
(pinocchio::JOINT_POSITION | pinocchio::JACOBIAN | pinocchio::COM); |
||
163 |
fullBody->device_->controlComputation (newflag); |
||
164 |
fullBody->device_->computeForwardKinematics(); |
||
165 |
fcl::Vec3f com_init = fullBody->device_->positionCenterOfMass(); |
||
166 |
std::cout<<"com_init = "<<com_init<<std::endl; |
||
167 |
fcl::Vec3f com_pino,com_goal; |
||
168 |
rbprm::projection::ProjectionReport rep; |
||
169 |
srand((unsigned int)(time(NULL))); |
||
170 |
for(size_t k = 0 ; k < 100 ; ++k){ |
||
171 |
//randomly sample CoM position close to the reference one : |
||
172 |
com_goal[0] = com_init[0]-0.2 + 0.4*(value_type(rand()) / |
||
173 |
value_type(RAND_MAX)); com_goal[1] = com_init[1]-0.2 + 0.4*(value_type(rand()) / |
||
174 |
value_type(RAND_MAX)); com_goal[2] = com_init[2]-0.1 + 0.2*(value_type(rand()) / |
||
175 |
value_type(RAND_MAX)); |
||
176 |
// check if the projection is successfull and the new com is correct |
||
177 |
rep = rbprm::projection::projectToComPosition(fullBody,com_goal,s_init); |
||
178 |
if(rep.success_){ |
||
179 |
std::cout<<"com goal : "<<com_goal<<std::endl; |
||
180 |
BOOST_CHECK_EQUAL(rep.result_.nbContacts,2); |
||
181 |
|||
182 |
fullBody->device_->currentConfiguration(rep.result_.configuration_); |
||
183 |
fullBody->device_->computeForwardKinematics(); |
||
184 |
com_pino = fullBody->device_->positionCenterOfMass(); |
||
185 |
std::cout<<"com pino : "<<com_pino<<std::endl; |
||
186 |
for(size_t i = 0 ; i < 3 ; ++i) |
||
187 |
BOOST_CHECK_SMALL(com_pino[i]-com_goal[i],1e-4); // precision should be |
||
188 |
the same as the error treshold of the config projector |
||
189 |
|||
190 |
|||
191 |
// check if contact position are preserved : |
||
192 |
for(std::vector<std::string>::const_iterator cit = allLimbs.begin(); cit |
||
193 |
!= allLimbs.end(); ++cit) |
||
194 |
{ |
||
195 |
rbprm::RbPrmLimbPtr_t limb = fullBody->GetLimbs().at(*cit); |
||
196 |
const std::string& limbName = *cit; |
||
197 |
const fcl::Vec3f position = |
||
198 |
limb->effector_.currentTransformation().translation(); for(size_t i = 0 ; i < 3 |
||
199 |
; ++i) BOOST_CHECK_SMALL(position[i] - |
||
200 |
s_init.contactPositions_[limbName][i],1e-4); |
||
201 |
} |
||
202 |
} |
||
203 |
} |
||
204 |
} |
||
205 |
|||
206 |
*/ |
||
207 |
|||
208 |
BOOST_AUTO_TEST_SUITE_END() |
Generated by: GCOVR (Version 4.2) |