00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef OMPL_CONTROL_CONTROL_SPACE_
00038 #define OMPL_CONTROL_CONTROL_SPACE_
00039
00040 #include "ompl/base/StateSpace.h"
00041 #include "ompl/control/Control.h"
00042 #include "ompl/control/ControlSampler.h"
00043 #include "ompl/control/ControlSpaceTypes.h"
00044 #include "ompl/util/Console.h"
00045 #include "ompl/util/ClassForward.h"
00046 #include <boost/concept_check.hpp>
00047 #include <boost/noncopyable.hpp>
00048 #include <iostream>
00049 #include <vector>
00050
00051 namespace ompl
00052 {
00053
00054 namespace control
00055 {
00056
00058
00059 ClassForward(ControlSpace);
00061
00066 class ControlSpace : private boost::noncopyable
00067 {
00068 public:
00069
00071 ControlSpace(const base::StateSpacePtr &stateSpace);
00072
00073 virtual ~ControlSpace(void);
00074
00076 template<class T>
00077 T* as(void)
00078 {
00080 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00081
00082 return static_cast<T*>(this);
00083 }
00084
00086 template<class T>
00087 const T* as(void) const
00088 {
00090 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00091
00092 return static_cast<const T*>(this);
00093 }
00094
00096 const std::string& getName(void) const;
00097
00099 void setName(const std::string &name);
00100
00104 int getType(void) const
00105 {
00106 return type_;
00107 }
00108
00110 const base::StateSpacePtr& getStateSpace(void) const
00111 {
00112 return stateSpace_;
00113 }
00114
00116 virtual unsigned int getDimension(void) const = 0;
00117
00119 virtual Control* allocControl(void) const = 0;
00120
00122 virtual void freeControl(Control *control) const = 0;
00123
00125 virtual void copyControl(Control *destination, const Control *source) const = 0;
00126
00128 virtual bool equalControls(const Control *control1, const Control *control2) const = 0;
00129
00131 virtual void nullControl(Control *control) const = 0;
00132
00134 virtual ControlSamplerPtr allocDefaultControlSampler(void) const = 0;
00135
00139 virtual ControlSamplerPtr allocControlSampler(void) const;
00140
00142 void setControlSamplerAllocator(const ControlSamplerAllocator &csa);
00143
00145 void clearControlSamplerAllocator(void);
00146
00151 virtual double* getValueAddressAtIndex(Control *control, const unsigned int index) const;
00152
00154 virtual void printControl(const Control *control, std::ostream &out) const;
00155
00157 virtual void printSettings(std::ostream &out) const;
00158
00160 virtual void setup(void);
00161
00162 protected:
00163
00165 int type_;
00166
00168 base::StateSpacePtr stateSpace_;
00169
00171 ControlSamplerAllocator csa_;
00172
00173 private:
00174
00176 std::string name_;
00177 };
00178
00180 class CompoundControlSpace : public ControlSpace
00181 {
00182 public:
00183
00185 typedef CompoundControl ControlType;
00186
00188 CompoundControlSpace(const base::StateSpacePtr &stateSpace) : ControlSpace(stateSpace), componentCount_(0), locked_(false)
00189 {
00190 }
00191
00192 virtual ~CompoundControlSpace(void)
00193 {
00194 }
00195
00197 template<class T>
00198 T* as(const unsigned int index) const
00199 {
00201 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, ControlSpace*>));
00202
00203 return static_cast<T*>(getSubSpace(index).get());
00204 }
00205
00207 virtual void addSubSpace(const ControlSpacePtr &component);
00208
00210 unsigned int getSubSpaceCount(void) const;
00211
00213 const ControlSpacePtr& getSubSpace(const unsigned int index) const;
00214
00216 const ControlSpacePtr& getSubSpace(const std::string &name) const;
00217
00218 virtual unsigned int getDimension(void) const;
00219
00220 virtual Control* allocControl(void) const;
00221
00222 virtual void freeControl(Control *control) const;
00223
00224 virtual void copyControl(Control *destination, const Control *source) const;
00225
00226 virtual bool equalControls(const Control *control1, const Control *control2) const;
00227
00228 virtual void nullControl(Control *control) const;
00229
00230 virtual ControlSamplerPtr allocDefaultControlSampler(void) const;
00231
00232 virtual double* getValueAddressAtIndex(Control *control, const unsigned int index) const;
00233
00234 virtual void printControl(const Control *control, std::ostream &out = std::cout) const;
00235
00236 virtual void printSettings(std::ostream &out) const;
00237
00238 virtual void setup(void);
00239
00245 void lock(void);
00246
00247 protected:
00248
00250 std::vector<ControlSpacePtr> components_;
00251
00253 unsigned int componentCount_;
00254
00256 bool locked_;
00257 };
00258 }
00259 }
00260
00261 #endif