| Directory: | ./ |
|---|---|
| File: | tests/relative-com.cc |
| Date: | 2025-05-05 12:19:30 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 30 | 30 | 100.0% |
| Branches: | 97 | 194 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2023, CNRS | ||
| 2 | // Authors: Florent Lamiraux | ||
| 3 | // | ||
| 4 | |||
| 5 | // Redistribution and use in source and binary forms, with or without | ||
| 6 | // modification, are permitted provided that the following conditions are | ||
| 7 | // met: | ||
| 8 | // | ||
| 9 | // 1. Redistributions of source code must retain the above copyright | ||
| 10 | // notice, this list of conditions and the following disclaimer. | ||
| 11 | // | ||
| 12 | // 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | // notice, this list of conditions and the following disclaimer in the | ||
| 14 | // documentation and/or other materials provided with the distribution. | ||
| 15 | // | ||
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 20 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
| 27 | // DAMAGE. | ||
| 28 | |||
| 29 | #include <hpp/constraints/generic-transformation.hh> | ||
| 30 | #include <hpp/constraints/relative-com.hh> | ||
| 31 | #include <hpp/pinocchio/simple-device.hh> | ||
| 32 | |||
| 33 | #define BOOST_TEST_MODULE RelativeCom | ||
| 34 | #include <boost/test/included/unit_test.hpp> | ||
| 35 | |||
| 36 | using hpp::pinocchio::Configuration_t; | ||
| 37 | using hpp::pinocchio::DevicePtr_t; | ||
| 38 | using hpp::pinocchio::JointPtr_t; | ||
| 39 | using hpp::pinocchio::LiegroupElement; | ||
| 40 | using hpp::pinocchio::LiegroupSpacePtr_t; | ||
| 41 | using hpp::pinocchio::Transform3s; | ||
| 42 | using hpp::pinocchio::vector3_t; | ||
| 43 | using hpp::pinocchio::unittest::HumanoidRomeo; | ||
| 44 | using hpp::pinocchio::unittest::makeDevice; | ||
| 45 | |||
| 46 | using hpp::constraints::DifferentiableFunctionPtr_t; | ||
| 47 | using hpp::constraints::GenericTransformation; | ||
| 48 | using hpp::constraints::OrientationBit; | ||
| 49 | using hpp::constraints::PositionBit; | ||
| 50 | using hpp::constraints::RelativeBit; | ||
| 51 | using hpp::constraints::RelativeCom; | ||
| 52 | using hpp::constraints::RelativeComPtr_t; | ||
| 53 | |||
| 54 |
33/66✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
|
4 | BOOST_AUTO_TEST_CASE(relative_com) { |
| 55 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
4 | DevicePtr_t robot(makeDevice(HumanoidRomeo)); |
| 56 |
2/4✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
4 | JointPtr_t leftAnkle(robot->getJointByName("LAnkleRoll")); |
| 57 |
2/4✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
4 | JointPtr_t rightAnkle(robot->getJointByName("RAnkleRoll")); |
| 58 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
2 | assert(leftAnkle); |
| 59 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
2 | assert(rightAnkle); |
| 60 | // Create relative com constraint | ||
| 61 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | vector3_t reference; |
| 62 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | reference.setZero(); |
| 63 | RelativeComPtr_t rc( | ||
| 64 |
4/8✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
|
4 | RelativeCom::create("relative-com", robot, leftAnkle, reference)); |
| 65 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | Configuration_t q0(robot->neutralConfiguration()); |
| 66 | // Create relative pose constraint between ankles. | ||
| 67 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | Transform3s ref1, ref2; |
| 68 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ref1.setIdentity(); |
| 69 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ref2.setIdentity(); |
| 70 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
2 | ref2.translation() << 0, -0.2, 0; |
| 71 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | std::vector<bool> mask(6, true); |
| 72 | DifferentiableFunctionPtr_t fp( | ||
| 73 | GenericTransformation < PositionBit | OrientationBit | | ||
| 74 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
4 | RelativeBit > ::create("foot-pose", robot, leftAnkle, rightAnkle, ref1, |
| 75 | 2 | ref2, mask)); | |
| 76 | |||
| 77 | // Get function values in neutral configuration. | ||
| 78 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2 | LiegroupElement rc0(rc->outputSpace()); |
| 79 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2 | LiegroupElement fp0(fp->outputSpace()); |
| 80 | |||
| 81 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | rc->value(rc0, q0); |
| 82 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | fp->value(fp0, q0); |
| 83 | |||
| 84 | // Translate root joint | ||
| 85 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Configuration_t q1(q0); |
| 86 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
2 | q1.head<3>() << 1., 2., 3.; |
| 87 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2 | LiegroupElement rc1(rc->outputSpace()); |
| 88 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2 | LiegroupElement fp1(fp->outputSpace()); |
| 89 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | rc->value(rc1, q1); |
| 90 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | fp->value(fp1, q1); |
| 91 |
8/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 1 times.
|
2 | BOOST_CHECK((rc1 - rc0).norm() < 1e-8); |
| 92 |
8/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 1 times.
|
2 | BOOST_CHECK((fp1 - fp0).norm() < 1e-8); |
| 93 | 2 | } | |
| 94 |