| Directory: | ./ |
|---|---|
| File: | src/humanoid-robot.cc |
| Date: | 2025-05-04 12:09:19 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 36 | 64 | 56.2% |
| Branches: | 22 | 72 | 30.6% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2016 CNRS | ||
| 3 | // Author: Joseph Mirabel from Florent Lamiraux | ||
| 4 | // | ||
| 5 | // | ||
| 6 | |||
| 7 | // Redistribution and use in source and binary forms, with or without | ||
| 8 | // modification, are permitted provided that the following conditions are | ||
| 9 | // met: | ||
| 10 | // | ||
| 11 | // 1. Redistributions of source code must retain the above copyright | ||
| 12 | // notice, this list of conditions and the following disclaimer. | ||
| 13 | // | ||
| 14 | // 2. Redistributions in binary form must reproduce the above copyright | ||
| 15 | // notice, this list of conditions and the following disclaimer in the | ||
| 16 | // documentation and/or other materials provided with the distribution. | ||
| 17 | // | ||
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 22 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
| 29 | // DAMAGE. | ||
| 30 | |||
| 31 | #include <boost/serialization/weak_ptr.hpp> | ||
| 32 | #include <hpp/pinocchio/humanoid-robot.hh> | ||
| 33 | #include <hpp/pinocchio/joint.hh> | ||
| 34 | #include <hpp/pinocchio/serialization.hh> | ||
| 35 | #include <hpp/util/serialization.hh> | ||
| 36 | #include <pinocchio/serialization/eigen.hpp> | ||
| 37 | |||
| 38 | namespace hpp { | ||
| 39 | namespace pinocchio { | ||
| 40 | |||
| 41 | 2 | HumanoidRobot::HumanoidRobot(const std::string& name) | |
| 42 |
2/4✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | : Device(name), weakPtr_(), gazeOrigin_(0, 0, 0), gazeDirection_(1, 0, 0) {} |
| 43 | |||
| 44 | // ======================================================================== | ||
| 45 | |||
| 46 | ✗ | HumanoidRobot::HumanoidRobot(const HumanoidRobot& other) | |
| 47 | : Device(other), | ||
| 48 | ✗ | weakPtr_(), | |
| 49 | ✗ | gazeOrigin_(other.gazeOrigin_), | |
| 50 | ✗ | gazeDirection_(other.gazeDirection_) {} | |
| 51 | |||
| 52 | // ======================================================================== | ||
| 53 | |||
| 54 | 12 | HumanoidRobot::~HumanoidRobot() {} | |
| 55 | |||
| 56 | // ======================================================================== | ||
| 57 | |||
| 58 | 2 | HumanoidRobotPtr_t HumanoidRobot::create(const std::string& name) { | |
| 59 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | HumanoidRobot* hppHumanoidRobot = new HumanoidRobot(name); |
| 60 | 2 | HumanoidRobotPtr_t hppHumanoidRobotPtr_t(hppHumanoidRobot); | |
| 61 | |||
| 62 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | hppHumanoidRobot->init(hppHumanoidRobotPtr_t); |
| 63 | 2 | return hppHumanoidRobotPtr_t; | |
| 64 | } | ||
| 65 | |||
| 66 | // ======================================================================== | ||
| 67 | |||
| 68 | ✗ | DevicePtr_t HumanoidRobot::clone() const { | |
| 69 | ✗ | HumanoidRobot* ptr = new HumanoidRobot(*this); | |
| 70 | ✗ | HumanoidRobotPtr_t shPtr(ptr); | |
| 71 | ✗ | ptr->initCopy(shPtr, *this); | |
| 72 | ✗ | return shPtr; | |
| 73 | } | ||
| 74 | |||
| 75 | // ======================================================================== | ||
| 76 | |||
| 77 | 2 | void HumanoidRobot::init(const HumanoidRobotWkPtr_t& weakPtr) { | |
| 78 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | Device::init(weakPtr); |
| 79 | 2 | weakPtr_ = weakPtr; | |
| 80 | 2 | } | |
| 81 | |||
| 82 | // ======================================================================== | ||
| 83 | |||
| 84 | ✗ | void HumanoidRobot::initCopy(const HumanoidRobotWkPtr_t& weakPtr, | |
| 85 | const HumanoidRobot& other) { | ||
| 86 | // Cannot call HumanoidRobot::init because Device::init would be called | ||
| 87 | // twice. | ||
| 88 | ✗ | weakPtr_ = weakPtr; | |
| 89 | ✗ | Device::initCopy(weakPtr, other); | |
| 90 | // TODO the HumanoidRobot will be never be deleted as these joints have | ||
| 91 | // a shared pointer to the device. | ||
| 92 | ✗ | DevicePtr_t d = weakPtr_.lock(); | |
| 93 | ✗ | waist_ = Joint::create(d, other.waist_->index()); | |
| 94 | ✗ | chest_ = Joint::create(d, other.chest_->index()); | |
| 95 | ✗ | leftWrist_ = Joint::create(d, other.leftWrist_->index()); | |
| 96 | ✗ | rightWrist_ = Joint::create(d, other.rightWrist_->index()); | |
| 97 | ✗ | leftAnkle_ = Joint::create(d, other.leftAnkle_->index()); | |
| 98 | ✗ | rightAnkle_ = Joint::create(d, other.rightAnkle_->index()); | |
| 99 | ✗ | gazeJoint_ = Joint::create(d, other.gazeJoint_->index()); | |
| 100 | } | ||
| 101 | |||
| 102 | // ======================================================================== | ||
| 103 | |||
| 104 | /// \brief Get Joint corresponding to the waist. | ||
| 105 | ✗ | JointPtr_t HumanoidRobot::waist() const { return waist_; } | |
| 106 | |||
| 107 | /// Set waist joint | ||
| 108 | 2 | void HumanoidRobot::waist(const JointPtr_t& joint) { waist_ = joint; } | |
| 109 | |||
| 110 | /// \brief Get Joint corresponding to the chest. | ||
| 111 | ✗ | JointPtr_t HumanoidRobot::chest() const { return chest_; } | |
| 112 | |||
| 113 | /// Set chest joint | ||
| 114 | ✗ | void HumanoidRobot::chest(const JointPtr_t& joint) { chest_ = joint; } | |
| 115 | |||
| 116 | /// \brief Get Joint corresponding to the left wrist. | ||
| 117 | ✗ | JointPtr_t HumanoidRobot::leftWrist() const { return leftWrist_; } | |
| 118 | |||
| 119 | /// Set left wrist | ||
| 120 | 2 | void HumanoidRobot::leftWrist(const JointPtr_t& joint) { leftWrist_ = joint; } | |
| 121 | |||
| 122 | /// \brief Get Joint corresponding to the right wrist. | ||
| 123 | ✗ | JointPtr_t HumanoidRobot::rightWrist() const { return rightWrist_; } | |
| 124 | |||
| 125 | /// Set right wrist | ||
| 126 | 2 | void HumanoidRobot::rightWrist(const JointPtr_t& joint) { rightWrist_ = joint; } | |
| 127 | |||
| 128 | /// \brief Get Joint corresponding to the left ankle. | ||
| 129 | ✗ | JointPtr_t HumanoidRobot::leftAnkle() const { return leftAnkle_; } | |
| 130 | |||
| 131 | /// Set letf ankle | ||
| 132 | 2 | void HumanoidRobot::leftAnkle(const JointPtr_t& joint) { leftAnkle_ = joint; } | |
| 133 | |||
| 134 | /// \brief Get Joint corresponding to the right ankle. | ||
| 135 | ✗ | JointPtr_t HumanoidRobot::rightAnkle() const { return rightAnkle_; } | |
| 136 | |||
| 137 | /// Set right ankle | ||
| 138 | 2 | void HumanoidRobot::rightAnkle(const JointPtr_t& joint) { rightAnkle_ = joint; } | |
| 139 | |||
| 140 | /// \brief Get gaze joint | ||
| 141 | ✗ | JointPtr_t HumanoidRobot::gazeJoint() const { return gazeJoint_; } | |
| 142 | |||
| 143 | /// Set gaze joint | ||
| 144 | 2 | void HumanoidRobot::gazeJoint(const JointPtr_t& joint) { gazeJoint_ = joint; } | |
| 145 | |||
| 146 | template <class Archive> | ||
| 147 | 4 | void HumanoidRobot::serialize(Archive& ar, const unsigned int version) { | |
| 148 | (void)version; | ||
| 149 | 4 | auto* har = hpp::serialization::cast(&ar); | |
| 150 | |||
| 151 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | ar& boost::serialization::make_nvp( |
| 152 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | "base", boost::serialization::base_object<Device>(*this)); |
| 153 | // TODO we should throw if a Device instance with name name_ and not of | ||
| 154 | // type HumanoidRobot is found. | ||
| 155 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
8 | bool written = (!har || har->template getChildClass<Device, HumanoidRobot>( |
| 156 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | name_, false) != this); |
| 157 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(written); |
| 158 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
4 | if (written) { |
| 159 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(weakPtr_); |
| 160 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(waist_); |
| 161 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(chest_); |
| 162 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(leftWrist_); |
| 163 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(rightWrist_); |
| 164 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(leftAnkle_); |
| 165 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(rightAnkle_); |
| 166 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(gazeJoint_); |
| 167 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(gazeOrigin_); |
| 168 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | ar& BOOST_SERIALIZATION_NVP(gazeDirection_); |
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | HPP_SERIALIZATION_IMPLEMENT(HumanoidRobot); | ||
| 173 | } // namespace pinocchio | ||
| 174 | } // namespace hpp | ||
| 175 | |||
| 176 | BOOST_CLASS_EXPORT_IMPLEMENT(hpp::pinocchio::HumanoidRobot) | ||
| 177 |