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
00037 #ifndef PLANNING_ENVIRONMENT_UTIL_KINEMATIC_STATE_CONSTRAINT_EVALUATOR_
00038 #define PLANNING_ENVIRONMENT_UTIL_KINEMATIC_STATE_CONSTRAINT_EVALUATOR_
00039
00040 #include <planning_models/kinematic_model.h>
00041 #include <planning_models/kinematic_state.h>
00042 #include <motion_planning_msgs/Constraints.h>
00043 #include <geometric_shapes_msgs/Shape.h>
00044 #include <geometric_shapes/bodies.h>
00045 #include <geometry_msgs/Pose.h>
00046 #include <iostream>
00047 #include <vector>
00048
00049 #include <boost/scoped_ptr.hpp>
00050
00051 namespace planning_environment
00052 {
00053 bool createConstraintRegionFromMsg(const geometric_shapes_msgs::Shape &constraint_region_shape,
00054 const geometry_msgs::Pose &constraint_region_pose,
00055 boost::scoped_ptr<bodies::Body> &body);
00056
00057 class KinematicConstraintEvaluator
00058 {
00059 public:
00060
00061 KinematicConstraintEvaluator(void)
00062 {
00063 }
00064
00065 virtual ~KinematicConstraintEvaluator(void)
00066 {
00067 }
00068
00070 virtual void clear(void) = 0;
00071
00073 virtual bool use(const ros::Message *kc) = 0;
00074
00076 virtual bool decide(const planning_models::KinematicState *state,
00077 bool verbose=false) const = 0;
00078
00080 virtual void print(std::ostream &out = std::cout) const
00081 {
00082 }
00083 };
00084
00085 class JointConstraintEvaluator : public KinematicConstraintEvaluator
00086 {
00087 public:
00088
00089 JointConstraintEvaluator(void) : KinematicConstraintEvaluator()
00090 {
00091 m_joint = NULL;
00092 }
00093
00095 virtual bool use(const ros::Message *kc);
00096
00098 bool use(const motion_planning_msgs::JointConstraint &jc);
00099
00101 virtual bool decide(const planning_models::KinematicState *state,
00102 bool verbose=false) const;
00103
00105 virtual void clear(void);
00106
00108 virtual void print(std::ostream &out = std::cout) const;
00109
00111 const motion_planning_msgs::JointConstraint& getConstraintMessage(void) const;
00112
00113 protected:
00114
00115 motion_planning_msgs::JointConstraint m_jc;
00116 const planning_models::KinematicModel::JointModel *m_joint;
00117 };
00118
00119
00120 class OrientationConstraintEvaluator : public KinematicConstraintEvaluator
00121 {
00122 public:
00123
00124 OrientationConstraintEvaluator(void) : KinematicConstraintEvaluator()
00125 {
00126 }
00127
00129 virtual bool use(const ros::Message *kc);
00130
00132 bool use(const motion_planning_msgs::OrientationConstraint &pc);
00133
00135 virtual void clear(void);
00136
00138 virtual bool decide(const planning_models::KinematicState* state,
00139 bool verbose=false) const;
00140
00142 void evaluate(const planning_models::KinematicState* state, double &distAng, bool verbose=false) const;
00143
00145 bool decide(double dAng, bool verbose=false) const;
00146
00148 void print(std::ostream &out = std::cout) const;
00149
00151 const motion_planning_msgs::OrientationConstraint& getConstraintMessage(void) const;
00152
00153 protected:
00154
00155 motion_planning_msgs::OrientationConstraint m_oc;
00156 double m_roll, m_pitch, m_yaw;
00157 btMatrix3x3 m_rotation_matrix;
00158 boost::scoped_ptr<bodies::Body> m_constraint_region;
00159
00160 };
00161
00162 class VisibilityConstraintEvaluator : public KinematicConstraintEvaluator
00163 {
00164 public:
00165
00166 VisibilityConstraintEvaluator(void) : KinematicConstraintEvaluator()
00167 {
00168 }
00169
00171 virtual bool use(const ros::Message *kc);
00172
00174 bool use(const motion_planning_msgs::VisibilityConstraint &vc);
00175
00177 virtual void clear(void);
00178
00180 virtual bool decide(const planning_models::KinematicState* state,
00181 bool verbose=false) const;
00182
00184 void print(std::ostream &out = std::cout) const;
00185
00187 const motion_planning_msgs::VisibilityConstraint& getConstraintMessage(void) const;
00188
00189 protected:
00190 motion_planning_msgs::VisibilityConstraint m_vc;
00191 btTransform m_sensor_offset_pose;
00192 };
00193
00194 class PositionConstraintEvaluator : public KinematicConstraintEvaluator
00195 {
00196 public:
00197
00198 PositionConstraintEvaluator(void) : KinematicConstraintEvaluator()
00199 {
00200 }
00201
00203 virtual bool use(const ros::Message *kc);
00204
00206 bool use(const motion_planning_msgs::PositionConstraint &pc);
00207
00209 virtual void clear(void);
00210
00212 virtual bool decide(const planning_models::KinematicState* state,
00213 bool verbose=false) const;
00214
00216 void evaluate(const planning_models::KinematicState* state, double& distPos, bool verbose=false) const;
00217
00219 bool decide(double dPos, bool verbose=false) const;
00220
00222 void print(std::ostream &out = std::cout) const;
00223
00225 const motion_planning_msgs::PositionConstraint& getConstraintMessage(void) const;
00226
00227 protected:
00228
00229 motion_planning_msgs::PositionConstraint m_pc;
00230 double m_x, m_y, m_z;
00231 btVector3 m_offset;
00232 boost::scoped_ptr<bodies::Body> m_constraint_region;
00233 };
00234
00235 class KinematicConstraintEvaluatorSet
00236 {
00237 public:
00238
00239 KinematicConstraintEvaluatorSet(void)
00240 {
00241 }
00242
00243 ~KinematicConstraintEvaluatorSet(void)
00244 {
00245 clear();
00246 }
00247
00249 void clear(void);
00250
00252 bool add(const std::vector<motion_planning_msgs::JointConstraint> &jc);
00253
00255 bool add(const std::vector<motion_planning_msgs::PositionConstraint> &pc);
00256
00258 bool add(const std::vector<motion_planning_msgs::OrientationConstraint> &pc);
00259
00261 bool add(const std::vector<motion_planning_msgs::VisibilityConstraint> &pc);
00262
00264 bool decide(const planning_models::KinematicState* state,
00265 bool verbose=false) const;
00266
00268 void print(std::ostream &out = std::cout) const;
00269
00271 const std::vector<motion_planning_msgs::PositionConstraint>& getPositionConstraints(void) const
00272 {
00273 return m_pc;
00274 }
00275
00277 const std::vector<motion_planning_msgs::OrientationConstraint>& getOrientationConstraints(void) const
00278 {
00279 return m_oc;
00280 }
00281
00283 const std::vector<motion_planning_msgs::JointConstraint>& getJointConstraints(void) const
00284 {
00285 return m_jc;
00286 }
00287
00288 protected:
00289
00290 std::vector<KinematicConstraintEvaluator*> m_kce;
00291 std::vector<motion_planning_msgs::JointConstraint> m_jc;
00292
00293 std::vector<motion_planning_msgs::PositionConstraint> m_pc;
00294 std::vector<motion_planning_msgs::OrientationConstraint> m_oc;
00295 std::vector<motion_planning_msgs::VisibilityConstraint> m_vc;
00296 };
00297 }
00298
00299
00300 #endif