1 |
|
|
// |
2 |
|
|
// Copyright (c) 2014 CNRS |
3 |
|
|
// Authors: Steve Tonneau (steve.tonneau@laas.fr) |
4 |
|
|
// |
5 |
|
|
// This file is part of hpp-rbprm. |
6 |
|
|
// hpp-rbprm is free software: you can redistribute it |
7 |
|
|
// and/or modify it under the terms of the GNU Lesser General Public |
8 |
|
|
// License as published by the Free Software Foundation, either version |
9 |
|
|
// 3 of the License, or (at your option) any later version. |
10 |
|
|
// |
11 |
|
|
// hpp-rbprm is distributed in the hope that it will be |
12 |
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
13 |
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
|
// General Lesser Public License for more details. You should have |
15 |
|
|
// received a copy of the GNU Lesser General Public License along with |
16 |
|
|
// hpp-core If not, see |
17 |
|
|
// <http://www.gnu.org/licenses/>. |
18 |
|
|
|
19 |
|
|
#ifndef HPP_RBPRM_FULLBODY_HH |
20 |
|
|
#define HPP_RBPRM_FULLBODY_HH |
21 |
|
|
|
22 |
|
|
#include <hpp/core/collision-validation.hh> |
23 |
|
|
#include <hpp/core/problem-solver.hh> |
24 |
|
|
#include <hpp/pinocchio/device.hh> |
25 |
|
|
#include <hpp/rbprm/config.hh> |
26 |
|
|
#include <hpp/rbprm/interpolation/spline/bezier-path.hh> |
27 |
|
|
#include <hpp/rbprm/rbprm-limb.hh> |
28 |
|
|
#include <hpp/rbprm/rbprm-state.hh> |
29 |
|
|
#include <hpp/rbprm/reports.hh> |
30 |
|
|
#include <hpp/rbprm/sampling/heuristic.hh> |
31 |
|
|
#include <vector> |
32 |
|
|
|
33 |
|
|
namespace hpp { |
34 |
|
|
namespace rbprm { |
35 |
|
|
|
36 |
|
|
using core::size_type; |
37 |
|
|
|
38 |
|
|
HPP_PREDEF_CLASS(RbPrmFullBody); |
39 |
|
|
|
40 |
|
|
/// Encapsulation of a Device class to handle the generation of contacts |
41 |
|
|
/// configurations for the user defined limbs of the Device. |
42 |
|
|
/// Uses an internal representation for the limbs, and handles |
43 |
|
|
/// collisions and balance criteria for generating their subconfigurations. |
44 |
|
|
/// |
45 |
|
|
class RbPrmFullBody; |
46 |
|
|
typedef shared_ptr<RbPrmFullBody> RbPrmFullBodyPtr_t; |
47 |
|
|
typedef hpp::core::Container<hpp::core::AffordanceObjects_t> affMap_t; |
48 |
|
|
typedef std::map<std::string, std::vector<bezier_Ptr> > |
49 |
|
|
EffectorTrajectoriesMap_t; |
50 |
|
|
|
51 |
|
|
class HPP_RBPRM_DLLAPI RbPrmFullBody { |
52 |
|
|
public: |
53 |
|
|
static RbPrmFullBodyPtr_t create(const pinocchio::DevicePtr_t& device); |
54 |
|
|
|
55 |
|
|
public: |
56 |
|
|
virtual ~RbPrmFullBody(); |
57 |
|
|
|
58 |
|
|
public: |
59 |
|
|
/// Creates a Limb for the robot, |
60 |
|
|
/// identified by its name. Stores a sample |
61 |
|
|
/// container, used for requests |
62 |
|
|
/// |
63 |
|
|
/// \param id: user defined id for the limb. Must be unique. |
64 |
|
|
/// The id is used if several contact points are defined for the same limb |
65 |
|
|
/// (ex: the knee and the foot) \param name: name of the joint corresponding |
66 |
|
|
/// to the root of the limb. \param effectorName name of the joint to be |
67 |
|
|
/// considered as the effector of the limb \param offset position of the |
68 |
|
|
/// effector in joint coordinates relatively to the effector joint \param unit |
69 |
|
|
/// normal vector of the contact point, expressed in the effector joint |
70 |
|
|
/// coordinates \param x width of the default support polygon of the effector |
71 |
|
|
/// \param y height of the default support polygon of the effector |
72 |
|
|
/// \param collisionObjects objects to be considered for collisions with the |
73 |
|
|
/// limb. TODO remove \param nbSamples number of samples to generate for the |
74 |
|
|
/// limb \param resolution, resolution of the octree voxels. The samples |
75 |
|
|
/// generated are stored in an octree data structure to perform efficient |
76 |
|
|
/// proximity requests. The resulution of the octree, in meters, specifies the |
77 |
|
|
/// size of the unit voxel of the octree. The larger they are, the more |
78 |
|
|
/// samples will be considered as candidates for contact. This can be |
79 |
|
|
/// problematic in terms of performance. The default value is 3 cm. \param |
80 |
|
|
/// resolution, resolution of the octree voxels. The samples generated are |
81 |
|
|
/// stored in an octree data \param disableEffectorCollision, whether |
82 |
|
|
/// collision detection should be disabled for end effector bones |
83 |
|
|
void AddLimb(const std::string& id, const std::string& name, |
84 |
|
|
const std::string& effectorName, const fcl::Vec3f& offset, |
85 |
|
|
const fcl::Vec3f& limbOffset, const fcl::Vec3f& normal, |
86 |
|
|
const double x, const double y, |
87 |
|
|
const core::ObjectStdVector_t& collisionObjects, |
88 |
|
|
const std::size_t nbSamples, |
89 |
|
|
const std::string& heuristic = "static", |
90 |
|
|
const double resolution = 0.03, ContactType contactType = _6_DOF, |
91 |
|
|
const bool disableEffectorCollision = false, |
92 |
|
|
const bool grasp = false, |
93 |
|
|
const std::string& kinematicConstraintsPath = std::string(), |
94 |
|
|
const double kinematicConstraintsMin = 0.); |
95 |
|
|
|
96 |
|
|
/// Creates a Limb for the robot, |
97 |
|
|
/// identified by its name. Stores a sample |
98 |
|
|
/// container, used for requests |
99 |
|
|
/// |
100 |
|
|
/// \param database: path to the sample database used for the limbs |
101 |
|
|
/// \param id: user defined id for the limb. Must be unique. |
102 |
|
|
/// The id is used if several contact points are defined for the same limb |
103 |
|
|
/// (ex: the knee and the foot) \param collisionObjects objects to be |
104 |
|
|
/// considered for collisions with the limb. TODO remove structure to perform |
105 |
|
|
/// efficient proximity requests. The resulution of the octree, in meters, |
106 |
|
|
/// specifies the size of the unit voxel of the octree. The larger they are, |
107 |
|
|
/// the more samples will be considered as candidates for contact. This can be |
108 |
|
|
/// problematic in terms of performance. The default value is 3 cm. \param |
109 |
|
|
/// disableEffectorCollision, whether collision detection should be disabled |
110 |
|
|
/// for end effector bones |
111 |
|
|
void AddLimb(const std::string& database, const std::string& id, |
112 |
|
|
const core::ObjectStdVector_t& collisionObjects, |
113 |
|
|
const std::string& heuristicName, const bool loadValues, |
114 |
|
|
const bool disableEffectorCollision = false, |
115 |
|
|
const bool grasp = false); |
116 |
|
|
|
117 |
|
|
/// |
118 |
|
|
/// \brief AddNonContactingLimb add a limb not used for contact generation |
119 |
|
|
/// \param id: user defined id for the limb. Must be unique. |
120 |
|
|
/// The id is used if several contact points are defined for the same limb |
121 |
|
|
/// (ex: the knee and the foot) \param name: name of the joint corresponding |
122 |
|
|
/// to the root of the limb. \param effectorName name of the joint to be |
123 |
|
|
/// considered as the effector of the limb \param collisionObjects objects to |
124 |
|
|
/// be considered for collisions with the limb. TODO remove \param nbSamples |
125 |
|
|
/// number of samples to generate for the limb |
126 |
|
|
void AddNonContactingLimb( |
127 |
|
|
const std::string& id, const std::string& name, |
128 |
|
|
const std::string& effectorName, |
129 |
|
|
const hpp::core::ObjectStdVector_t& collisionObjects, |
130 |
|
|
const std::size_t nbSamples); |
131 |
|
|
|
132 |
|
|
/// Add a new heuristic for biasing sample candidate selection |
133 |
|
|
/// |
134 |
|
|
/// \param name: name used to identify the heuristic |
135 |
|
|
/// \param func the actual heuristic method |
136 |
|
|
/// \return whether the heuristic has been added. False is returned if a |
137 |
|
|
/// heuristic with that name already exists. |
138 |
|
|
bool AddHeuristic(const std::string& name, const sampling::heuristic func); |
139 |
|
|
|
140 |
|
|
public: |
141 |
|
|
typedef std::map<std::string, std::vector<std::string> > T_LimbGroup; |
142 |
|
|
|
143 |
|
|
public: |
144 |
|
1112 |
const rbprm::T_Limb& GetLimbs() { return limbs_; } |
145 |
|
|
const rbprm::RbPrmLimbPtr_t GetLimb(std::string name, |
146 |
|
|
bool onlyWithContact = false); |
147 |
|
|
const rbprm::T_Limb& GetNonContactingLimbs() { return nonContactingLimbs_; } |
148 |
|
|
const T_LimbGroup& GetGroups() { return limbGroups_; } |
149 |
|
|
const core::CollisionValidationPtr_t& GetCollisionValidation() { |
150 |
|
|
return collisionValidation_; |
151 |
|
|
} |
152 |
|
|
const std::map<std::string, core::CollisionValidationPtr_t>& |
153 |
|
|
GetLimbCollisionValidation() { |
154 |
|
|
return limbcollisionValidations_; |
155 |
|
|
} |
156 |
|
|
const pinocchio::DevicePtr_t device_; |
157 |
|
|
void staticStability(bool staticStability) { |
158 |
|
|
staticStability_ = staticStability; |
159 |
|
|
} |
160 |
|
|
bool staticStability() const { return staticStability_; } |
161 |
|
64 |
double getFriction() const { return mu_; } |
162 |
|
|
void setFriction(double mu) { mu_ = mu; } |
163 |
|
|
pinocchio::Configuration_t referenceConfig() { return reference_; } |
164 |
|
|
void referenceConfig(pinocchio::Configuration_t referenceConfig); |
165 |
|
|
pinocchio::Configuration_t postureWeights() { return postureWeights_; } |
166 |
|
|
void postureWeights(pinocchio::Configuration_t postureWeights); |
167 |
|
|
bool usePosturalTaskContactCreation() { |
168 |
|
|
return usePosturalTaskContactCreation_; |
169 |
|
|
} |
170 |
|
|
void usePosturalTaskContactCreation(bool usePosturalTaskContactCreation) { |
171 |
|
|
usePosturalTaskContactCreation_ = usePosturalTaskContactCreation; |
172 |
|
|
} |
173 |
|
|
bool addEffectorTrajectory(const size_t pathId, |
174 |
|
|
const std::string& effectorName, |
175 |
|
|
const bezier_Ptr& trajectory); |
176 |
|
|
bool addEffectorTrajectory(const size_t pathId, |
177 |
|
|
const std::string& effectorName, |
178 |
|
|
const std::vector<bezier_Ptr>& trajectories); |
179 |
|
|
bool getEffectorsTrajectories(const size_t pathId, |
180 |
|
|
EffectorTrajectoriesMap_t& result); |
181 |
|
|
bool getEffectorTrajectory(const size_t pathId, |
182 |
|
|
const std::string& effectorName, |
183 |
|
|
std::vector<bezier_Ptr>& result); |
184 |
|
|
bool toggleNonContactingLimb(std::string name); |
185 |
|
|
|
186 |
|
|
private: |
187 |
|
|
core::CollisionValidationPtr_t collisionValidation_; |
188 |
|
|
std::map<std::string, core::CollisionValidationPtr_t> |
189 |
|
|
limbcollisionValidations_; |
190 |
|
|
rbprm::T_Limb limbs_; |
191 |
|
|
rbprm::T_Limb nonContactingLimbs_; // this is the list of limbs that are not |
192 |
|
|
// used during contact generation. |
193 |
|
|
T_LimbGroup limbGroups_; |
194 |
|
|
sampling::HeuristicFactory factory_; |
195 |
|
|
bool staticStability_; |
196 |
|
|
double mu_; |
197 |
|
|
pinocchio::Configuration_t reference_; |
198 |
|
|
pinocchio::Configuration_t postureWeights_; // weight used to compute the |
199 |
|
|
// distance in the postural tasks |
200 |
|
|
bool usePosturalTaskContactCreation_; // if true, during the contact creation |
201 |
|
|
// the orientation of the feet along |
202 |
|
|
// the contact normal is optimized for |
203 |
|
|
// a postural task |
204 |
|
|
std::map<size_t, EffectorTrajectoriesMap_t> |
205 |
|
|
effectorsTrajectoriesMaps_; // the map link the pathIndex (the same as in |
206 |
|
|
// the wholeBody paths in problem solver) to |
207 |
|
|
// a map of trajectories for each effectors. |
208 |
|
|
private: |
209 |
|
|
void AddLimbPrivate(rbprm::RbPrmLimbPtr_t limb, const std::string& id, |
210 |
|
|
const std::string& name, |
211 |
|
|
const hpp::core::ObjectStdVector_t& collisionObjects, |
212 |
|
|
const bool disableEffectorCollision, |
213 |
|
|
const bool nonContactingLimb = false); |
214 |
|
|
|
215 |
|
|
protected: |
216 |
|
|
RbPrmFullBody(const pinocchio::DevicePtr_t& device); |
217 |
|
|
|
218 |
|
|
/// |
219 |
|
|
/// \brief Initialization. |
220 |
|
|
/// |
221 |
|
|
void init(const RbPrmFullBodyWkPtr_t& weakPtr); |
222 |
|
|
|
223 |
|
|
private: |
224 |
|
|
RbPrmFullBodyWkPtr_t weakPtr_; |
225 |
|
|
}; // class RbPrmDevice |
226 |
|
|
} // namespace rbprm |
227 |
|
|
|
228 |
|
|
} // namespace hpp |
229 |
|
|
|
230 |
|
|
#endif // HPP_RBPRM_DEVICE_HH |