rbprmbuilder.impl.hh 16.1 KB
Newer Older
Steve Tonneau's avatar
Steve Tonneau committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright (c) 2014 CNRS
// Author: Florent Lamiraux
//
// This file is part of hpp-manipulation-corba.
// hpp-manipulation-corba is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-manipulation-corba is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Lesser Public License for more details.  You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-manipulation-corba.  If not, see
// <http://www.gnu.org/licenses/>.

#ifndef HPP_RBPRM_CORBA_BUILDER_IMPL_HH
# define HPP_RBPRM_CORBA_BUILDER_IMPL_HH

# include <hpp/core/problem-solver.hh>
22
# include <hpp/core/path.hh>
Steve Tonneau's avatar
Steve Tonneau committed
23
# include "rbprmbuilder.hh"
Steve Tonneau's avatar
Steve Tonneau committed
24
# include <hpp/rbprm/rbprm-device.hh>
Steve Tonneau's avatar
Steve Tonneau committed
25
# include <hpp/rbprm/rbprm-fullbody.hh>
Steve Tonneau's avatar
Steve Tonneau committed
26
27
# include <hpp/rbprm/rbprm-shooter.hh>
# include <hpp/rbprm/rbprm-validation.hh>
28
# include <hpp/rbprm/sampling/analysis.hh>
29
30
31
32
# include <hpp/core/collision-path-validation-report.hh>
# include <hpp/core/problem-solver.hh>
# include <hpp/core/discretized-collision-checking.hh>
# include <hpp/core/straight-path.hh>
33
# include <hpp/rbprm/rbprm-path-validation.hh>
34
35
# include <hpp/fcl/BVH/BVH_model.h>
# include <hpp/core/config-validations.hh>
36
#include <hpp/rbprm/dynamic/dynamic-path-validation.hh>
Steve Tonneau's avatar
Steve Tonneau committed
37
38
39
40
namespace hpp {
  namespace rbprm {
    namespace impl {
      using CORBA::Short;
41
			typedef std::map<std::string, std::vector<boost::shared_ptr<model::CollisionObject> > > affMap_t;
Steve Tonneau's avatar
Steve Tonneau committed
42

Steve Tonneau's avatar
Steve Tonneau committed
43
44
45
    struct BindShooter
    {
        BindShooter(const std::size_t shootLimit = 10000,
Steve Tonneau's avatar
Steve Tonneau committed
46
                    const std::size_t displacementLimit = 1000)
Steve Tonneau's avatar
Steve Tonneau committed
47
48
49
50
51
52
            : shootLimit_(shootLimit)
            , displacementLimit_(displacementLimit) {}

        hpp::rbprm::RbPrmShooterPtr_t create (const hpp::model::DevicePtr_t& robot)
        {
            hpp::model::RbPrmDevicePtr_t robotcast = boost::static_pointer_cast<hpp::model::RbPrmDevice>(robot);
53
		        if (affMap_.empty ()) {
54
55
    	        throw hpp::Error ("No affordances found. Unable to create shooter object.");
      		  }
Steve Tonneau's avatar
Steve Tonneau committed
56
            rbprm::RbPrmShooterPtr_t shooter = hpp::rbprm::RbPrmShooter::create
57
                    (robotcast, problemSolver_->problem ()->collisionObstacles(), affMap_,
58
										romFilter_,affFilter_,shootLimit_,displacementLimit_);
Steve Tonneau's avatar
Steve Tonneau committed
59
60
61
            if(!so3Bounds_.empty())
                shooter->BoundSO3(so3Bounds_);
            return shooter;
Steve Tonneau's avatar
Steve Tonneau committed
62
        }
63
64
65
66

        hpp::core::PathValidationPtr_t createPathValidation (const hpp::model::DevicePtr_t& robot, const hpp::model::value_type& val)
        {
            hpp::model::RbPrmDevicePtr_t robotcast = boost::static_pointer_cast<hpp::model::RbPrmDevice>(robot);
67
68
69
70
71
            affMap_ = problemSolver_->map
              <std::vector<boost::shared_ptr<model::CollisionObject> > > ();
            if (affMap_.empty ()) {
              throw hpp::Error ("No affordances found. Unable to create Path Validaton object.");
            }
72
            hpp::rbprm::RbPrmValidationPtr_t validation
73
              (hpp::rbprm::RbPrmValidation::create(robotcast, romFilter_, affFilter_, affMap_));
74
            hpp::rbprm::RbPrmPathValidationPtr_t collisionChecking = hpp::rbprm::RbPrmPathValidation::create(robot,val);
75
            collisionChecking->add (validation);
76
77
            problemSolver_->problem()->configValidation(core::ConfigValidations::create ());
            problemSolver_->problem()->configValidations()->add(validation);
78
            return collisionChecking;
79
80
        }

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
        hpp::core::PathValidationPtr_t createDynamicPathValidation (const hpp::model::DevicePtr_t& robot, const hpp::model::value_type& val)
        {
          hpp::model::RbPrmDevicePtr_t robotcast = boost::static_pointer_cast<hpp::model::RbPrmDevice>(robot);
          affMap_ = problemSolver_->map
            <std::vector<boost::shared_ptr<model::CollisionObject> > > ();
          if (affMap_.empty ()) {
            throw hpp::Error ("No affordances found. Unable to create Path Validaton object.");
          }
          hpp::rbprm::RbPrmValidationPtr_t validation
            (hpp::rbprm::RbPrmValidation::create(robotcast, romFilter_, affFilter_, affMap_));
          hpp::rbprm::DynamicPathValidationPtr_t collisionChecking = hpp::rbprm::DynamicPathValidation::create(robot,val);
          collisionChecking->add (validation);
          problemSolver_->problem()->configValidation(core::ConfigValidations::create ());
          problemSolver_->problem()->configValidations()->add(validation);
          // build the dynamicValidation :
          double sizeFootX,sizeFootY,mass,mu;
          bool rectangularContact;
          try {
            sizeFootX = problemSolver_->problem()->get<double> (std::string("sizeFootX"))/2.;
            sizeFootY = problemSolver_->problem()->get<double> (std::string("sizeFootY"))/2.;
            rectangularContact = 1;
          } catch (const std::exception& e) {
            hppDout(warning,"Warning : size of foot not definied, use 0 (contact point)");
            sizeFootX =0;
            sizeFootY =0;
            rectangularContact = 0;
          }
          mass = robot->mass();
          mu = 0.5; // FIXME : store it in problem ?
          DynamicValidationPtr_t dynamicVal = DynamicValidation::create(rectangularContact,sizeFootX,sizeFootY,mass,mu);
          collisionChecking->addDynamicValidator(dynamicVal);

          return collisionChecking;
        }

Steve Tonneau's avatar
Steve Tonneau committed
116
        hpp::core::ProblemSolverPtr_t problemSolver_;
Steve Tonneau's avatar
Steve Tonneau committed
117
        std::vector<std::string> romFilter_;
118
        std::map<std::string, std::vector<std::string> > affFilter_;
Steve Tonneau's avatar
Steve Tonneau committed
119
120
        std::size_t shootLimit_;
        std::size_t displacementLimit_;
Steve Tonneau's avatar
Steve Tonneau committed
121
        std::vector<double> so3Bounds_;
122
				affMap_t affMap_;
Steve Tonneau's avatar
Steve Tonneau committed
123
124
    };

Steve Tonneau's avatar
Steve Tonneau committed
125
126
127
      class RbprmBuilder : public virtual POA_hpp::corbaserver::rbprm::RbprmBuilder
      {
        public:
Steve Tonneau's avatar
Steve Tonneau committed
128
        RbprmBuilder ();
Steve Tonneau's avatar
Steve Tonneau committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

        virtual void loadRobotRomModel (const char* robotName,
                 const char* rootJointType,
                 const char* packageName,
                 const char* modelName,
                 const char* urdfSuffix,
                 const char* srdfSuffix) throw (hpp::Error);

        virtual void loadRobotCompleteModel (const char* robotName,
                 const char* rootJointType,
                 const char* packageName,
                 const char* modelName,
                 const char* urdfSuffix,
                 const char* srdfSuffix) throw (hpp::Error);

Steve Tonneau's avatar
Steve Tonneau committed
144
145
146
147
148
149
150
151

        virtual void loadFullBodyRobot (const char* robotName,
                 const char* rootJointType,
                 const char* packageName,
                 const char* modelName,
                 const char* urdfSuffix,
                 const char* srdfSuffix) throw (hpp::Error);

152
153
        virtual void loadFullBodyRobotFromExistingRobot () throw (hpp::Error);

154
        void setStaticStability(const bool staticStability) throw (hpp::Error);
155

Steve Tonneau's avatar
Steve Tonneau committed
156
        virtual void setFilter(const hpp::Names_t& roms) throw (hpp::Error);
157
				virtual void setAffordanceFilter(const char* romName, const hpp::Names_t& affordances) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
158
159
        virtual void boundSO3(const hpp::floatSeq& limitszyx) throw (hpp::Error);

Steve Tonneau's avatar
Steve Tonneau committed
160

Steve Tonneau's avatar
Steve Tonneau committed
161
        virtual hpp::floatSeq* getSampleConfig(const char* limb, unsigned short sampleId) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
162
        virtual hpp::floatSeq* getSamplePosition(const char* limb, unsigned short sampleId) throw (hpp::Error);
163
        virtual hpp::floatSeqSeq* getEffectorPosition(const char* limb, const hpp::floatSeq& configuration) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
164
        virtual CORBA::UShort getNumSamples(const char* limb) throw (hpp::Error);
165
        virtual hpp::floatSeq* getOctreeNodeIds(const char* limb) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
166
        virtual double getSampleValue(const char* limb, const char* valueName, unsigned short sampleId) throw (hpp::Error);
167
        virtual double getEffectorDistance(unsigned short  state1, unsigned short  state2) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
168

Steve Tonneau's avatar
Steve Tonneau committed
169
        virtual hpp::floatSeq* generateContacts(const hpp::floatSeq& configuration,
170
                                                const hpp::floatSeq& direction, const hpp::floatSeq& acceleration, const double robustnessThreshold) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
171

172
173
        virtual hpp::floatSeq* generateGroundContact(const hpp::Names_t& contactLimbs) throw (hpp::Error);

174
175
176
177
        virtual hpp::floatSeq* getContactSamplesIds(const char* limb,
                                                   const hpp::floatSeq& configuration,
                                                   const hpp::floatSeq& direction) throw (hpp::Error);

Steve Tonneau's avatar
Steve Tonneau committed
178
        virtual hpp::floatSeqSeq* getContactSamplesProjected(const char* limb,
Steve Tonneau's avatar
Steve Tonneau committed
179
180
181
182
                                                   const hpp::floatSeq& configuration,
                                                   const hpp::floatSeq& direction,
                                                   unsigned short numSamples) throw (hpp::Error);

183
184
185
        virtual hpp::floatSeq* getSamplesIdsInOctreeNode(const char* limb,
                                                   double octreeNodeId) throw (hpp::Error);

186
        virtual void addLimb(const char* id, const char* limb, const char* effector, const hpp::floatSeq& offset, const hpp::floatSeq& normal, double x, double y,
187
188
189
190
                             unsigned short samples, const char *heuristicName, double resolution, const char *contactType,
                             double disableEffectorCollision) throw (hpp::Error);
        virtual void addLimbDatabase(const char* databasePath, const char* id, const char* heuristicName, double loadValues,
                                     double disableEffectorCollision) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
191

Steve Tonneau's avatar
Steve Tonneau committed
192
193
        virtual void setStartState(const hpp::floatSeq& configuration, const hpp::Names_t& contactLimbs) throw (hpp::Error);
        virtual void setEndState(const hpp::floatSeq& configuration, const hpp::Names_t& contactLimbs) throw (hpp::Error);
194
        virtual hpp::floatSeq*  computeContactForConfig(const hpp::floatSeq& configuration, const char* limbNam) throw (hpp::Error);
195
        virtual hpp::floatSeqSeq* computeContactPoints(unsigned short cId) throw (hpp::Error);
196
        virtual hpp::floatSeqSeq* computeContactPointsForLimb(unsigned short cId, const char* limbName) throw (hpp::Error);
197
198
        virtual hpp::floatSeqSeq* interpolate(double timestep, double path, double robustnessTreshold, unsigned short filterStates) throw (hpp::Error);
        virtual hpp::floatSeqSeq* interpolateConfigs(const hpp::floatSeqSeq& configs, double robustnessTreshold, unsigned short filterStates) throw (hpp::Error);
199
200
        virtual hpp::floatSeqSeq* getContactCone(unsigned short stateId, double friction) throw (hpp::Error);
        virtual hpp::floatSeqSeq* getContactIntermediateCone(unsigned short stateId, double friction) throw (hpp::Error);
201
202
        virtual CORBA::Short generateComTraj(const hpp::floatSeqSeq& positions, const hpp::floatSeqSeq& velocities,
                                             const hpp::floatSeqSeq& accelerations, const double dt) throw (hpp::Error);
203
        virtual CORBA::Short generateRootPath(const hpp::floatSeqSeq& rootPositions,
204
                                      const hpp::floatSeq& q1, const hpp::floatSeq& q2) throw (hpp::Error);
205
206
        virtual CORBA::Short limbRRT(double state1, double state2, unsigned short numOptimizations) throw (hpp::Error);
        virtual CORBA::Short limbRRTFromRootPath(double state1, double state2, unsigned short path, unsigned short numOptimizations) throw (hpp::Error);
207
        virtual CORBA::Short configToPath(const hpp::floatSeqSeq& configs) throw (hpp::Error);
208
        virtual CORBA::Short comRRT(double state1, double state2, unsigned short path, unsigned short numOptimizations) throw (hpp::Error);
209
210
211
212
213

        typedef core::PathPtr_t (*t_rrt)
            (RbPrmFullBodyPtr_t, core::ProblemPtr_t, const core::PathPtr_t,
             const  State &, const State &, const  std::size_t, const bool);

214
        hpp::floatSeq* rrt(t_rrt functor , double state1,
215
216
217
                           unsigned short comTraj1, unsigned short comTraj2, unsigned short comTraj3,
                           unsigned short numOptimizations) throw (hpp::Error);

218
        virtual hpp::floatSeq* comRRTFromPos(double state1,
219
220
221
                                           unsigned short comTraj1,
                                           unsigned short comTraj2,
                                           unsigned short comTraj3,
Steve Tonneau's avatar
Steve Tonneau committed
222
                                           unsigned short numOptimizations) throw (hpp::Error);
223
        virtual hpp::floatSeq* effectorRRT(double state1,
224
225
226
                                           unsigned short comTraj1,
                                           unsigned short comTraj2,
                                           unsigned short comTraj3,
227
                                           unsigned short numOptimizations) throw (hpp::Error);
228
229
230
231
        virtual hpp::floatSeq* effectorRRTFromPath(double state1,
                                           unsigned short path,
                                           double path_from,
                                           double path_to,
232
233
234
                                           unsigned short comTraj1,
                                           unsigned short comTraj2,
                                           unsigned short comTraj3,
235
236
                                           unsigned short numOptimizations,
                                           const hpp::Names_t& trackedEffectors) throw (hpp::Error);
237
        virtual hpp::floatSeq* projectToCom(double state, const hpp::floatSeq& targetCom) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
238
        virtual CORBA::Short createState(const hpp::floatSeq& configuration, const hpp::Names_t& contactLimbs) throw (hpp::Error);
239
        virtual hpp::floatSeq* getConfigAtState(unsigned short stateId) throw (hpp::Error);
240
        double projectStateToCOMEigen(unsigned short stateId, const model::Configuration_t& com_target)throw (hpp::Error);
241
        virtual double projectStateToCOM(unsigned short stateId, const hpp::floatSeq& com) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
242
        virtual void saveComputedStates(const char* filepath) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
243
        virtual void saveLimbDatabase(const char* limbname,const char* filepath) throw (hpp::Error);
244
        virtual hpp::floatSeq* getOctreeBox(const char* limbName, double sampleId) throw (hpp::Error);
245
246
        virtual CORBA::Short  isLimbInContact(const char* limbName, double state) throw (hpp::Error);
        virtual CORBA::Short  isLimbInContactIntermediary(const char* limbName, double state) throw (hpp::Error);
247
        virtual hpp::floatSeqSeq* getOctreeBoxes(const char* limbName, const hpp::floatSeq& configuration) throw (hpp::Error);
248
        virtual hpp::floatSeq* getOctreeTransform(const char* limbName, const hpp::floatSeq& configuration) throw (hpp::Error);
249
        virtual CORBA::Short isConfigBalanced(const hpp::floatSeq& config, const hpp::Names_t& contactLimbs, double robustnessTreshold) throw (hpp::Error);
250
        virtual void runSampleAnalysis(const char* analysis, double isstatic) throw (hpp::Error);
251
        virtual hpp::floatSeq* runLimbSampleAnalysis(const char* limbname, const char* analysis, double isstatic) throw (hpp::Error);
252
        virtual void dumpProfile(const char* logFile) throw (hpp::Error);
253
        virtual double getTimeAtState(unsigned short stateId)throw (hpp::Error);
254

Steve Tonneau's avatar
Steve Tonneau committed
255
        public:
Steve Tonneau's avatar
Steve Tonneau committed
256
257
258
        void SetProblemSolver (hpp::core::ProblemSolverPtr_t problemSolver);

        private:
Steve Tonneau's avatar
Steve Tonneau committed
259
260
261
262
        /// \brief Pointer to hppPlanner object of hpp::corbaServer::Server.
        core::ProblemSolverPtr_t problemSolver_;

        private:
Steve Tonneau's avatar
Steve Tonneau committed
263
        model::T_Rom romDevices_;
Steve Tonneau's avatar
Steve Tonneau committed
264
        rbprm::RbPrmFullBodyPtr_t fullBody_;
Steve Tonneau's avatar
Steve Tonneau committed
265
        bool romLoaded_;
Steve Tonneau's avatar
Steve Tonneau committed
266
        bool fullBodyLoaded_;
Steve Tonneau's avatar
Steve Tonneau committed
267
        BindShooter bindShooter_;
Steve Tonneau's avatar
Steve Tonneau committed
268
269
        rbprm::State startState_;
        rbprm::State endState_;
Steve Tonneau's avatar
Steve Tonneau committed
270
        std::vector<rbprm::State> lastStatesComputed_;
271
        rbprm::T_StateFrame lastStatesComputedTime_;
Steve Tonneau's avatar
Steve Tonneau committed
272
        sampling::AnalysisFactory* analysisFactory_;
Steve Tonneau's avatar
Steve Tonneau committed
273
274
275
276
277
278
      }; // class RobotBuilder
    } // namespace impl
  } // namespace manipulation
} // namespace hpp

#endif // HPP_RBPRM_CORBA_BUILDER_IMPL_HH