kinematic_constraint.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 /* Author: Ioan Sucan */
00036 
00037 #ifndef MOVEIT_KINEMATIC_CONSTRAINTS_KINEMATIC_CONSTRAINT_
00038 #define MOVEIT_KINEMATIC_CONSTRAINTS_KINEMATIC_CONSTRAINT_
00039 
00040 #include <moveit/robot_model/robot_model.h>
00041 #include <moveit/robot_state/robot_state.h>
00042 #include <moveit/transforms/transforms.h>
00043 #include <moveit/collision_detection/collision_world.h>
00044 
00045 #include <geometric_shapes/bodies.h>
00046 #include <moveit_msgs/Constraints.h>
00047 
00048 #include <iostream>
00049 #include <vector>
00050 #include <boost/shared_ptr.hpp>
00051 
00053 namespace kinematic_constraints
00054 {
00055 
00057 struct ConstraintEvaluationResult
00058 {
00067   ConstraintEvaluationResult(bool result_satisfied = false, double dist = 0.0) : satisfied(result_satisfied), distance(dist)
00068   {
00069   }
00070 
00071   bool   satisfied;             
00072   double distance;              
00073 };
00074 
00076 class KinematicConstraint
00077 {
00078 public:
00079 
00081   enum ConstraintType
00082     {
00083       UNKNOWN_CONSTRAINT, JOINT_CONSTRAINT, POSITION_CONSTRAINT, ORIENTATION_CONSTRAINT, VISIBILITY_CONSTRAINT
00084     };
00085 
00091   KinematicConstraint(const robot_model::RobotModelConstPtr &model);
00092   virtual ~KinematicConstraint();
00093 
00095   virtual void clear() = 0;
00096 
00105   virtual ConstraintEvaluationResult decide(const robot_state::RobotState &state, bool verbose = false) const = 0;
00106 
00112   virtual bool enabled() const = 0;
00113 
00125   virtual bool equal(const KinematicConstraint &other, double margin) const = 0;
00126 
00133   ConstraintType getType() const
00134   {
00135     return type_;
00136   }
00137 
00143   virtual void print(std::ostream &out = std::cout) const
00144   {
00145   }
00146 
00153   double getConstraintWeight() const
00154   {
00155     return constraint_weight_;
00156   }
00157 
00164   const robot_model::RobotModelConstPtr& getRobotModel() const
00165   {
00166     return robot_model_;
00167   }
00168 
00169 protected:
00170 
00171   ConstraintType                  type_; 
00172   robot_model::RobotModelConstPtr robot_model_; 
00173   double                          constraint_weight_; 
00174 };
00175 
00176 typedef boost::shared_ptr<KinematicConstraint> KinematicConstraintPtr; 
00177 typedef boost::shared_ptr<const KinematicConstraint> KinematicConstraintConstPtr; 
00198 class JointConstraint : public KinematicConstraint
00199 {
00200 public:
00206   JointConstraint(const robot_model::RobotModelConstPtr &model) :
00207     KinematicConstraint(model), joint_model_(NULL), joint_variable_index_(-1)
00208   {
00209     type_ = JOINT_CONSTRAINT;
00210   }
00211 
00225   bool configure(const moveit_msgs::JointConstraint &jc);
00226 
00242   virtual bool equal(const KinematicConstraint &other, double margin) const;
00243 
00244   virtual ConstraintEvaluationResult decide(const robot_state::RobotState &state, bool verbose = false) const;
00245   virtual bool enabled() const;
00246   virtual void clear();
00247   virtual void print(std::ostream &out = std::cout) const;
00248 
00254   const robot_model::JointModel* getJointModel() const
00255   {
00256     return joint_model_;
00257   }
00266   const std::string& getLocalVariableName() const
00267   {
00268     return local_variable_name_;
00269   }
00270 
00278   const std::string& getJointVariableName() const
00279   {
00280     return joint_variable_name_;
00281   }
00282 
00283   int getJointVariableIndex() const
00284   {
00285     return joint_variable_index_;
00286   }
00287   
00294   double getDesiredJointPosition() const
00295   {
00296     return joint_position_;
00297   }
00298 
00305   double getJointToleranceAbove() const
00306   {
00307     return joint_tolerance_above_;
00308   }
00309 
00316   double getJointToleranceBelow() const
00317   {
00318     return joint_tolerance_below_;
00319   }
00320 
00321 protected:
00322 
00323   const robot_model::JointModel *joint_model_; 
00324   bool                                               joint_is_continuous_; 
00325   std::string                                        local_variable_name_; 
00326   std::string                                        joint_variable_name_; 
00327   int                                                joint_variable_index_;  
00328   double                                             joint_position_, joint_tolerance_above_, joint_tolerance_below_; 
00329 };
00330 
00342 class OrientationConstraint : public KinematicConstraint
00343 {
00344 public:
00345   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00346 
00347 public:
00353   OrientationConstraint(const robot_model::RobotModelConstPtr &model) :
00354     KinematicConstraint(model), link_model_(NULL)
00355   {
00356     type_ = ORIENTATION_CONSTRAINT;
00357   }
00358 
00372   bool configure(const moveit_msgs::OrientationConstraint &oc, const robot_state::Transforms &tf);
00373 
00390   virtual bool equal(const KinematicConstraint &other, double margin) const;
00391 
00392   virtual void clear();
00393   virtual ConstraintEvaluationResult decide(const robot_state::RobotState &state, bool verbose = false) const;
00394   virtual bool enabled() const;
00395   virtual void print(std::ostream &out = std::cout) const;
00396 
00403   const robot_model::LinkModel* getLinkModel() const
00404   {
00405     return link_model_;
00406   }
00407 
00414   const std::string& getReferenceFrame() const
00415   {
00416     return desired_rotation_frame_id_;
00417   }
00418 
00425   bool mobileReferenceFrame() const
00426   {
00427     return mobile_frame_;
00428   }
00429 
00435   const Eigen::Matrix3d& getDesiredRotationMatrix() const
00436   {
00437     return desired_rotation_matrix_;
00438   }
00439 
00446   double getXAxisTolerance() const
00447   {
00448     return absolute_x_axis_tolerance_;
00449   }
00450 
00457   double getYAxisTolerance() const
00458   {
00459     return absolute_y_axis_tolerance_;
00460   }
00461 
00468   double getZAxisTolerance() const
00469   {
00470     return absolute_z_axis_tolerance_;
00471   }
00472 
00475   void swapLinkModel(const robot_model::LinkModel *new_link, const Eigen::Matrix3d &update);
00476   
00477 protected:
00478 
00479   const robot_model::LinkModel *link_model_; 
00480   Eigen::Matrix3d               desired_rotation_matrix_; 
00481   Eigen::Matrix3d               desired_rotation_matrix_inv_; 
00482   std::string                   desired_rotation_frame_id_; 
00483   bool                          mobile_frame_; 
00484   double                        absolute_x_axis_tolerance_, absolute_y_axis_tolerance_, absolute_z_axis_tolerance_; 
00485 };
00486 
00487 
00501 class PositionConstraint : public KinematicConstraint
00502 {
00503 public:
00504   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00505 
00506 public:
00507 
00513   PositionConstraint(const robot_model::RobotModelConstPtr &model) :
00514     KinematicConstraint(model), link_model_(NULL)
00515   {
00516     type_ = POSITION_CONSTRAINT;
00517   }
00518 
00535   bool configure(const moveit_msgs::PositionConstraint &pc, const robot_state::Transforms &tf);
00536 
00560   virtual bool equal(const KinematicConstraint &other, double margin) const;
00561 
00562   virtual void clear();
00563   virtual ConstraintEvaluationResult decide(const robot_state::RobotState &state, bool verbose = false) const;
00564   virtual bool enabled() const;
00565   virtual void print(std::ostream &out = std::cout) const;
00566 
00573   const robot_model::LinkModel* getLinkModel() const
00574   {
00575     return link_model_;
00576   }
00577 
00584   const Eigen::Vector3d& getLinkOffset() const
00585   {
00586     return offset_;
00587   }
00588 
00596   bool hasLinkOffset() const
00597   {
00598     if(!enabled()) return false;
00599     return has_offset_;
00600   }
00601 
00602 
00609   const std::vector<bodies::BodyPtr>& getConstraintRegions() const
00610   {
00611     return constraint_region_;
00612   }
00613 
00620   const std::string& getReferenceFrame() const
00621   {
00622     return constraint_frame_id_;
00623   }
00624 
00632   bool mobileReferenceFrame() const
00633   {
00634     if (!enabled()) return false;
00635     return mobile_frame_;
00636   }
00637 
00640   void swapLinkModel(const robot_model::LinkModel *new_link, const Eigen::Affine3d &update);
00641   
00642 protected:
00643 
00644   Eigen::Vector3d                                   offset_; 
00645   bool                                              has_offset_; 
00646   std::vector<bodies::BodyPtr>                      constraint_region_; 
00647   EigenSTL::vector_Affine3d                         constraint_region_pose_; 
00648   bool                                              mobile_frame_; 
00649   std::string                                       constraint_frame_id_; 
00650   const robot_model::LinkModel *link_model_; 
00651 };
00652 
00749 class VisibilityConstraint : public KinematicConstraint
00750 {
00751 public:
00752   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00753 
00754 public:
00760   VisibilityConstraint(const robot_model::RobotModelConstPtr &model);
00761 
00774   bool configure(const moveit_msgs::VisibilityConstraint &vc, const robot_state::Transforms &tf);
00775 
00793   virtual bool equal(const KinematicConstraint &other, double margin) const;
00794   virtual void clear();
00795 
00803   shapes::Mesh* getVisibilityCone(const robot_state::RobotState &state) const;
00804 
00816   void getMarkers(const robot_state::RobotState &state, visualization_msgs::MarkerArray &markers) const;
00817 
00818   virtual bool enabled() const;
00819   virtual ConstraintEvaluationResult decide(const robot_state::RobotState &state, bool verbose = false) const;
00820   virtual void print(std::ostream &out = std::cout) const;
00821 
00822 protected:
00823 
00833   bool decideContact(const collision_detection::Contact &contact) const;
00834 
00835   collision_detection::CollisionRobotPtr collision_robot_; 
00836   bool                                   mobile_sensor_frame_; 
00837   bool                                   mobile_target_frame_; 
00838   std::string                            target_frame_id_; 
00839   std::string                            sensor_frame_id_; 
00840   Eigen::Affine3d                        sensor_pose_; 
00841   int                                    sensor_view_direction_; 
00842   Eigen::Affine3d                        target_pose_; 
00843   unsigned int                           cone_sides_; 
00844   EigenSTL::vector_Vector3d              points_; 
00845   double                                 target_radius_; 
00846   double                                 max_view_angle_; 
00847   double                                 max_range_angle_; 
00848 };
00849 
00858 class KinematicConstraintSet
00859 {
00860 public:
00861   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00862 
00863 public:
00864 
00870   KinematicConstraintSet(const robot_model::RobotModelConstPtr &model) :
00871     robot_model_(model)
00872   {
00873   }
00874 
00875   ~KinematicConstraintSet()
00876   {
00877     clear();
00878   }
00879 
00881   void clear();
00882 
00893   bool add(const moveit_msgs::Constraints &c, const robot_state::Transforms &tf);
00894 
00902   bool add(const std::vector<moveit_msgs::JointConstraint> &jc);
00903 
00911   bool add(const std::vector<moveit_msgs::PositionConstraint> &pc, const robot_state::Transforms &tf);
00912 
00920   bool add(const std::vector<moveit_msgs::OrientationConstraint> &oc, const robot_state::Transforms &tf);
00921 
00929   bool add(const std::vector<moveit_msgs::VisibilityConstraint> &vc, const robot_state::Transforms &tf);
00930 
00942   ConstraintEvaluationResult decide(const robot_state::RobotState &state, bool verbose = false) const;
00943 
00962   ConstraintEvaluationResult decide(const robot_state::RobotState &state, std::vector<ConstraintEvaluationResult> &results, bool verbose = false) const;
00963 
00979   bool equal(const KinematicConstraintSet &other, double margin) const;
00980 
00986   void print(std::ostream &out = std::cout) const;
00987 
00994   const std::vector<moveit_msgs::PositionConstraint>& getPositionConstraints() const
00995   {
00996     return position_constraints_;
00997   }
00998 
01005   const std::vector<moveit_msgs::OrientationConstraint>& getOrientationConstraints() const
01006   {
01007     return orientation_constraints_;
01008   }
01009 
01016   const std::vector<moveit_msgs::JointConstraint>& getJointConstraints() const
01017   {
01018     return joint_constraints_;
01019   }
01020 
01027   const std::vector<moveit_msgs::VisibilityConstraint>& getVisibilityConstraints() const
01028   {
01029     return visibility_constraints_;
01030   }
01031 
01038   const moveit_msgs::Constraints& getAllConstraints() const
01039   {
01040     return all_constraints_;
01041   }
01042 
01049   bool empty() const
01050   {
01051     return kinematic_constraints_.empty();
01052   }
01053 
01054 protected:
01055 
01056   robot_model::RobotModelConstPtr                 robot_model_; 
01057   std::vector<KinematicConstraintPtr>             kinematic_constraints_; 
01059   std::vector<moveit_msgs::JointConstraint>       joint_constraints_; 
01060   std::vector<moveit_msgs::PositionConstraint>    position_constraints_;
01061   std::vector<moveit_msgs::OrientationConstraint> orientation_constraints_;
01062   std::vector<moveit_msgs::VisibilityConstraint>  visibility_constraints_;
01063   moveit_msgs::Constraints                        all_constraints_; 
01065 };
01066 
01067 typedef boost::shared_ptr<KinematicConstraintSet> KinematicConstraintSetPtr; 
01068 typedef boost::shared_ptr<const KinematicConstraintSet> KinematicConstraintSetConstPtr; 
01070 }
01071 
01072 
01073 #endif


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Thu Aug 27 2015 13:58:52