rbprmbuilder.impl.hh 9.48 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
22
// 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>
# include "rbprmbuilder.hh"
Steve Tonneau's avatar
Steve Tonneau committed
23
# include <hpp/rbprm/rbprm-device.hh>
Steve Tonneau's avatar
Steve Tonneau committed
24
# include <hpp/rbprm/rbprm-fullbody.hh>
Steve Tonneau's avatar
Steve Tonneau committed
25
26
# include <hpp/rbprm/rbprm-shooter.hh>
# include <hpp/rbprm/rbprm-validation.hh>
27
# include <hpp/rbprm/sampling/analysis.hh>
28
29
30
31
# 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>
Steve Tonneau's avatar
Steve Tonneau committed
32

33
34
#include <hpp/fcl/BVH/BVH_model.h>

Steve Tonneau's avatar
Steve Tonneau committed
35
36
37
38
namespace hpp {
  namespace rbprm {
    namespace impl {
      using CORBA::Short;
39
			typedef std::map<std::string, std::vector<boost::shared_ptr<model::CollisionObject> > > affMap_t;
Steve Tonneau's avatar
Steve Tonneau committed
40

Steve Tonneau's avatar
Steve Tonneau committed
41
42
43
    struct BindShooter
    {
        BindShooter(const std::size_t shootLimit = 10000,
Steve Tonneau's avatar
Steve Tonneau committed
44
                    const std::size_t displacementLimit = 1000)
Steve Tonneau's avatar
Steve Tonneau committed
45
46
47
48
49
50
            : 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);
51
		        if (affMap_.empty ()) {
52
53
    	        throw hpp::Error ("No affordances found. Unable to create shooter object.");
      		  }
Steve Tonneau's avatar
Steve Tonneau committed
54
            rbprm::RbPrmShooterPtr_t shooter = hpp::rbprm::RbPrmShooter::create
55
                    (robotcast, problemSolver_->problem ()->collisionObstacles(), affMap_,
56
										romFilter_,affFilter_,shootLimit_,displacementLimit_);
Steve Tonneau's avatar
Steve Tonneau committed
57
58
59
            if(!so3Bounds_.empty())
                shooter->BoundSO3(so3Bounds_);
            return shooter;
Steve Tonneau's avatar
Steve Tonneau committed
60
        }
61
62
63
64

        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);
65
66
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.");
      		  }
            hpp::rbprm::RbPrmValidationPtr_t validation
							(hpp::rbprm::RbPrmValidation::create(robotcast, romFilter_, affFilter_, affMap_));
72
73
74
            hpp::core::DiscretizedCollisionCheckingPtr_t collisionChecking = hpp::core::DiscretizedCollisionChecking::create(robot,val);
            collisionChecking->add (validation);
            return collisionChecking;
75
76
        }

Steve Tonneau's avatar
Steve Tonneau committed
77
        hpp::core::ProblemSolverPtr_t problemSolver_;
Steve Tonneau's avatar
Steve Tonneau committed
78
        std::vector<std::string> romFilter_;
79
        std::map<std::string, std::vector<std::string> > affFilter_;
Steve Tonneau's avatar
Steve Tonneau committed
80
81
        std::size_t shootLimit_;
        std::size_t displacementLimit_;
Steve Tonneau's avatar
Steve Tonneau committed
82
        std::vector<double> so3Bounds_;
83
				affMap_t affMap_;
Steve Tonneau's avatar
Steve Tonneau committed
84
85
    };

Steve Tonneau's avatar
Steve Tonneau committed
86
87
88
      class RbprmBuilder : public virtual POA_hpp::corbaserver::rbprm::RbprmBuilder
      {
        public:
Steve Tonneau's avatar
Steve Tonneau committed
89
        RbprmBuilder ();
Steve Tonneau's avatar
Steve Tonneau committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

        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
105
106
107
108
109
110
111
112

        virtual void loadFullBodyRobot (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
113
        virtual void setFilter(const hpp::Names_t& roms) throw (hpp::Error);
114
				virtual void setAffordanceFilter(const char* romName, const hpp::Names_t& affordances) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
115
116
        virtual void boundSO3(const hpp::floatSeq& limitszyx) throw (hpp::Error);

Steve Tonneau's avatar
Steve Tonneau committed
117

Steve Tonneau's avatar
Steve Tonneau committed
118
        virtual hpp::floatSeq* getSampleConfig(const char* limb, unsigned short sampleId) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
119
        virtual hpp::floatSeq* getSamplePosition(const char* limb, unsigned short sampleId) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
120
        virtual CORBA::UShort getNumSamples(const char* limb) throw (hpp::Error);
121
        virtual hpp::floatSeq* getOctreeNodeIds(const char* limb) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
122
        virtual double getSampleValue(const char* limb, const char* valueName, unsigned short sampleId) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
123

Steve Tonneau's avatar
Steve Tonneau committed
124
125
126
        virtual hpp::floatSeq* generateContacts(const hpp::floatSeq& configuration,
                                                const hpp::floatSeq& direction) throw (hpp::Error);

127
128
129
130
        virtual hpp::floatSeq* getContactSamplesIds(const char* limb,
                                                   const hpp::floatSeq& configuration,
                                                   const hpp::floatSeq& direction) throw (hpp::Error);

131
132
133
        virtual hpp::floatSeq* getSamplesIdsInOctreeNode(const char* limb,
                                                   double octreeNodeId) throw (hpp::Error);

134
        virtual void addLimb(const char* id, const char* limb, const char* effector, const hpp::floatSeq& offset, const hpp::floatSeq& normal, double x, double y,
135
136
137
138
                             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
139

Steve Tonneau's avatar
Steve Tonneau committed
140
141
        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);
142
        virtual hpp::floatSeqSeq* computeContactPoints(unsigned short cId) throw (hpp::Error);
143
144
        virtual hpp::floatSeqSeq* interpolate(double timestep, double path, double robustnessTreshold) throw (hpp::Error);
        virtual hpp::floatSeqSeq* interpolateConfigs(const hpp::floatSeqSeq& configs, double robustnessTreshold) throw (hpp::Error);
145
146
147
148
        virtual hpp::floatSeqSeq* getContactCone(unsigned short stateId) throw (hpp::Error);
        virtual hpp::floatSeqSeq* getContactIntermediateCone(unsigned short stateId) throw (hpp::Error);
        virtual void generateRootPath(const hpp::floatSeqSeq& rootPositions,
                                      const hpp::floatSeq& q1, const hpp::floatSeq& q2) throw (hpp::Error);
149
        virtual void interpolateBetweenStates(double state1, double state2, unsigned short numOptimizations) throw (hpp::Error);
150
        virtual void interpolateBetweenStatesFromPath(double state1, double state2, unsigned short path, unsigned short numOptimizations) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
151
        virtual void saveComputedStates(const char* filepath) throw (hpp::Error);
Steve Tonneau's avatar
Steve Tonneau committed
152
        virtual void saveLimbDatabase(const char* limbname,const char* filepath) throw (hpp::Error);
153
154
        virtual hpp::floatSeq* getOctreeBox(const char* limbName, double sampleId) throw (hpp::Error);
        virtual hpp::floatSeqSeq* getOctreeBoxes(const char* limbName, const hpp::floatSeq& configuration) throw (hpp::Error);
155
        virtual hpp::floatSeq* getOctreeTransform(const char* limbName, const hpp::floatSeq& configuration) throw (hpp::Error);
156
        virtual CORBA::Short isConfigBalanced(const hpp::floatSeq& config, const hpp::Names_t& contactLimbs, double robustnessTreshold) throw (hpp::Error);
157
        virtual void runSampleAnalysis(const char* analysis, double isstatic) throw (hpp::Error);
158
        virtual hpp::floatSeq* runLimbSampleAnalysis(const char* limbname, const char* analysis, double isstatic) throw (hpp::Error);
159

Steve Tonneau's avatar
Steve Tonneau committed
160
        public:
Steve Tonneau's avatar
Steve Tonneau committed
161
162
163
        void SetProblemSolver (hpp::core::ProblemSolverPtr_t problemSolver);

        private:
Steve Tonneau's avatar
Steve Tonneau committed
164
165
166
167
        /// \brief Pointer to hppPlanner object of hpp::corbaServer::Server.
        core::ProblemSolverPtr_t problemSolver_;

        private:
Steve Tonneau's avatar
Steve Tonneau committed
168
        model::T_Rom romDevices_;
Steve Tonneau's avatar
Steve Tonneau committed
169
        rbprm::RbPrmFullBodyPtr_t fullBody_;
Steve Tonneau's avatar
Steve Tonneau committed
170
        bool romLoaded_;
Steve Tonneau's avatar
Steve Tonneau committed
171
        bool fullBodyLoaded_;
Steve Tonneau's avatar
Steve Tonneau committed
172
        BindShooter bindShooter_;
Steve Tonneau's avatar
Steve Tonneau committed
173
174
        rbprm::State startState_;
        rbprm::State endState_;
Steve Tonneau's avatar
Steve Tonneau committed
175
        std::vector<rbprm::State> lastStatesComputed_;
176
        rbprm::T_StateFrame lastStatesComputedTime_;
Steve Tonneau's avatar
Steve Tonneau committed
177
        sampling::AnalysisFactory* analysisFactory_;
Steve Tonneau's avatar
Steve Tonneau committed
178
179
180
181
182
183
      }; // class RobotBuilder
    } // namespace impl
  } // namespace manipulation
} // namespace hpp

#endif // HPP_RBPRM_CORBA_BUILDER_IMPL_HH