| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// |
| 2 |
|
|
// Copyright (c) 2016 CNRS |
| 3 |
|
|
// Author: NMansard |
| 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 <hpp/pinocchio/collision-object.hh> |
| 32 |
|
|
#include <hpp/pinocchio/device.hh> |
| 33 |
|
|
#include <hpp/pinocchio/joint-collection.hh> |
| 34 |
|
|
#include <hpp/pinocchio/joint.hh> |
| 35 |
|
|
#include <pinocchio/multibody/geometry.hpp> |
| 36 |
|
|
#include <pinocchio/multibody/model.hpp> |
| 37 |
|
|
#include <pinocchio/spatial/fcl-pinocchio-conversions.hpp> |
| 38 |
|
|
|
| 39 |
|
|
namespace hpp { |
| 40 |
|
|
namespace pinocchio { |
| 41 |
|
|
|
| 42 |
|
✗ |
CollisionObject::CollisionObject(DevicePtr_t device, |
| 43 |
|
✗ |
const GeomIndex geomInModel) |
| 44 |
|
✗ |
: devicePtr(device), |
| 45 |
|
✗ |
geomModel_(devicePtr->geomModelPtr()), |
| 46 |
|
✗ |
jointIndex_(0), |
| 47 |
|
✗ |
geomInModelIndex(geomInModel) { |
| 48 |
|
✗ |
jointIndex_ = pinocchio().parentJoint; |
| 49 |
|
✗ |
selfAssert(); |
| 50 |
|
|
} |
| 51 |
|
|
|
| 52 |
|
✗ |
CollisionObject::CollisionObject(GeomModelPtr_t geomModel, |
| 53 |
|
|
GeomDataPtr_t geomData, |
| 54 |
|
✗ |
const GeomIndex geomInModel) |
| 55 |
|
✗ |
: devicePtr(), |
| 56 |
|
✗ |
geomModel_(geomModel), |
| 57 |
|
✗ |
geomData_(geomData), |
| 58 |
|
✗ |
jointIndex_(0), |
| 59 |
|
✗ |
geomInModelIndex(geomInModel) { |
| 60 |
|
✗ |
jointIndex_ = pinocchio().parentJoint; |
| 61 |
|
✗ |
selfAssert(); |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
✗ |
const std::string& CollisionObject::name() const { return pinocchio().name; } |
| 65 |
|
|
|
| 66 |
|
|
// This function should rather return a shared_ptr<const> |
| 67 |
|
✗ |
const ::pinocchio::GeometryObject& CollisionObject::pinocchio() const { |
| 68 |
|
✗ |
return geomModel_->geometryObjects[geomInModelIndex]; |
| 69 |
|
|
} |
| 70 |
|
✗ |
::pinocchio::GeometryObject& CollisionObject::pinocchio() { |
| 71 |
|
✗ |
return geomModel_->geometryObjects[geomInModelIndex]; |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
|
✗ |
CollisionGeometryPtr_t CollisionObject::geometry() const { |
| 75 |
|
✗ |
return pinocchio().geometry; |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
|
✗ |
FclCollisionObjectPtr_t CollisionObject::fcl(GeomData& geomData) const { |
| 79 |
|
|
return FclCollisionObjectPtr_t(new FclCollisionObject( |
| 80 |
|
✗ |
geometry(), toFclTransform3f(geomData.oMg[geomInModelIndex]))); |
| 81 |
|
|
} |
| 82 |
|
|
|
| 83 |
|
✗ |
FclConstCollisionObjectPtr_t CollisionObject::fcl( |
| 84 |
|
|
const GeomData& geomData) const { |
| 85 |
|
|
return FclCollisionObjectPtr_t(new FclCollisionObject( |
| 86 |
|
✗ |
geometry(), toFclTransform3f(geomData.oMg[geomInModelIndex]))); |
| 87 |
|
|
} |
| 88 |
|
|
|
| 89 |
|
✗ |
FclConstCollisionObjectPtr_t CollisionObject::fcl() const { |
| 90 |
|
✗ |
return fcl(geomData()); |
| 91 |
|
|
} |
| 92 |
|
✗ |
FclCollisionObjectPtr_t CollisionObject::fcl() { return fcl(geomData()); } |
| 93 |
|
|
|
| 94 |
|
✗ |
FclCollisionObjectPtr_t CollisionObject::fcl(DeviceData& d) const { |
| 95 |
|
|
return FclCollisionObjectPtr_t(new FclCollisionObject( |
| 96 |
|
✗ |
geometry(), toFclTransform3f(geomData(d).oMg[geomInModelIndex]))); |
| 97 |
|
|
} |
| 98 |
|
|
|
| 99 |
|
✗ |
FclConstCollisionObjectPtr_t CollisionObject::fcl(const DeviceData& d) const { |
| 100 |
|
|
return FclCollisionObjectPtr_t(new FclCollisionObject( |
| 101 |
|
✗ |
geometry(), toFclTransform3f(geomData(d).oMg[geomInModelIndex]))); |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
|
✗ |
JointPtr_t CollisionObject::joint() { |
| 105 |
|
✗ |
if (!devicePtr) return JointPtr_t(); |
| 106 |
|
✗ |
return Joint::create(devicePtr, jointIndex_); |
| 107 |
|
|
} |
| 108 |
|
|
|
| 109 |
|
✗ |
JointConstPtr_t CollisionObject::joint() const { |
| 110 |
|
✗ |
if (!devicePtr) return JointConstPtr_t(); |
| 111 |
|
✗ |
return Joint::create(devicePtr, jointIndex_); |
| 112 |
|
|
} |
| 113 |
|
|
|
| 114 |
|
✗ |
const Transform3s& CollisionObject::positionInJointFrame() const { |
| 115 |
|
✗ |
return pinocchio().placement; |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
✗ |
fcl::Transform3s CollisionObject::getFclTransform() const { |
| 119 |
|
✗ |
return ::pinocchio::toFclTransform3f(geomData().oMg[geomInModelIndex]); |
| 120 |
|
|
} |
| 121 |
|
✗ |
const Transform3s& CollisionObject::getTransform() const { |
| 122 |
|
✗ |
return geomData().oMg[geomInModelIndex]; |
| 123 |
|
|
} |
| 124 |
|
✗ |
const Transform3s& CollisionObject::getTransform(const DeviceData& d) const { |
| 125 |
|
✗ |
return geomData(d).oMg[geomInModelIndex]; |
| 126 |
|
|
} |
| 127 |
|
|
|
| 128 |
|
✗ |
void CollisionObject::move(const Transform3s& position) { |
| 129 |
|
|
// move does not work but for object attached to the universe (joint 0) |
| 130 |
|
✗ |
assert(jointIndex_ == 0); |
| 131 |
|
✗ |
geomData().oMg[geomInModelIndex] = position; |
| 132 |
|
✗ |
pinocchio().placement = position; |
| 133 |
|
|
} |
| 134 |
|
|
|
| 135 |
|
✗ |
void CollisionObject::selfAssert() const { |
| 136 |
|
✗ |
assert(geomModel_); |
| 137 |
|
✗ |
assert(devicePtr || geomData_); |
| 138 |
|
✗ |
assert(!devicePtr || |
| 139 |
|
|
devicePtr->model().joints.size() > std::size_t(jointIndex_)); |
| 140 |
|
✗ |
assert(geomModel_->geometryObjects.size() > geomInModelIndex); |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
✗ |
GeomData& CollisionObject::geomData() const { |
| 144 |
|
✗ |
if (devicePtr) // Object of the robot. |
| 145 |
|
✗ |
return geomData(devicePtr->d()); |
| 146 |
|
|
else // Object of the environment. |
| 147 |
|
✗ |
return *geomData_; |
| 148 |
|
|
} |
| 149 |
|
|
|
| 150 |
|
✗ |
GeomData& CollisionObject::geomData(DeviceData& d) const { |
| 151 |
|
✗ |
if (geomData_) |
| 152 |
|
✗ |
return *geomData_; |
| 153 |
|
|
else |
| 154 |
|
✗ |
return *d.geomData_; |
| 155 |
|
|
} |
| 156 |
|
|
|
| 157 |
|
✗ |
const GeomData& CollisionObject::geomData(const DeviceData& d) const { |
| 158 |
|
✗ |
if (geomData_) |
| 159 |
|
✗ |
return *geomData_; |
| 160 |
|
|
else |
| 161 |
|
✗ |
return *d.geomData_; |
| 162 |
|
|
} |
| 163 |
|
|
} // namespace pinocchio |
| 164 |
|
|
} // namespace hpp |
| 165 |
|
|
|