robot_state.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, 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, Inc. 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, E. Gil Jones */
00036 
00037 #ifndef MOVEIT_ROBOT_STATE_ROBOT_STATE_
00038 #define MOVEIT_ROBOT_STATE_ROBOT_STATE_
00039 
00040 #include <moveit/robot_model/robot_model.h>
00041 #include <moveit/robot_state/joint_state_group.h>
00042 #include <moveit/robot_state/attached_body.h>
00043 #include <std_msgs/ColorRGBA.h>
00044 #include <visualization_msgs/MarkerArray.h>
00045 
00047 namespace robot_state
00048 {
00049 
00050 typedef boost::function<void(AttachedBody *body, bool attached)> AttachedBodyCallback;
00051 
00054 class RobotState
00055 {
00056   friend class LinkState;
00057   friend class JointState;
00058 public:
00059 
00061   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00063 
00065   RobotState(const robot_model::RobotModelConstPtr &kinematic_model);
00066 
00068   RobotState(const RobotState& state);
00069 
00070   ~RobotState();
00071 
00075   bool setStateValues(const std::vector<double>& joint_state_values);
00076 
00078   void setStateValues(const std::map<std::string, double>& joint_state_map);
00079 
00082   void setStateValues(const std::map<std::string, double>& joint_state_map, std::vector<std::string>& missing);
00083 
00085   void setStateValues(const sensor_msgs::JointState& msg);
00086 
00089   void setStateValues(const std::vector<std::string>& joint_names,
00090                       const std::vector<double>& joint_values);
00091 
00094   void getStateValues(std::vector<double>& joint_state_values) const;
00095 
00097   void getStateValues(std::map<std::string, double>& joint_state_values) const;
00098 
00100   void getStateValues(sensor_msgs::JointState& msg) const;
00101 
00103   void updateLinkTransforms();
00104 
00106   bool updateStateWithLinkAt(const std::string& link_name, const Eigen::Affine3d& transform, bool backward = false);
00107 
00109   const robot_model::RobotModelConstPtr& getRobotModel() const
00110   {
00111     return kinematic_model_;
00112   }
00113 
00115   unsigned int getVariableCount() const
00116   {
00117     return kinematic_model_->getVariableCount();
00118   }
00119 
00121   void setToDefaultValues();
00122 
00124   void setToRandomValues();
00125 
00127   bool satisfiesBounds(const std::vector<std::string>& joints) const;
00128 
00130   bool satisfiesBounds(const std::string& joint) const;
00131 
00133   bool satisfiesBounds() const;
00134 
00136   void enforceBounds();
00137 
00139   const JointStateGroup* getJointStateGroup(const std::string &name) const;
00140 
00142   JointStateGroup* getJointStateGroup(const std::string &name);
00143 
00145   bool hasJointStateGroup(const std::string &name) const;
00146 
00148   bool hasJointState(const std::string &joint) const;
00149 
00151   bool hasLinkState(const std::string &link) const;
00152 
00154   JointState* getJointState(const std::string &joint) const;
00155 
00156   JointState* getJointState(const robot_model::JointModel *jmodel) const
00157   {
00158     // \todo make this more efficient (store index of JointState in the model)
00159     return getJointState(jmodel->getName());
00160   }
00161 
00163   LinkState* getLinkState(const std::string &link) const;
00164 
00166   const std::vector<JointState*>& getJointStateVector() const
00167   {
00168     return joint_state_vector_;
00169   }
00170 
00172   const std::vector<LinkState*>& getLinkStateVector() const
00173   {
00174     return link_state_vector_;
00175   }
00176 
00178   const std::map<std::string, JointStateGroup*>& getJointStateGroupMap() const
00179   {
00180     return joint_state_group_map_;
00181   }
00182 
00184   void getJointStateGroupNames(std::vector<std::string>& names) const;
00185 
00187   void attachBody(AttachedBody *attached_body);
00188 
00197   void attachBody(const std::string &id,
00198                   const std::vector<shapes::ShapeConstPtr> &shapes,
00199                   const EigenSTL::vector_Affine3d &attach_trans,
00200                   const std::set<std::string> &touch_links,
00201                   const std::string &link_name,
00202                   const sensor_msgs::JointState &detach_posture = sensor_msgs::JointState());
00203   void attachBody(const std::string &id,
00204                   const std::vector<shapes::ShapeConstPtr> &shapes,
00205                   const EigenSTL::vector_Affine3d &attach_trans,
00206                   const std::vector<std::string> &touch_links,
00207                   const std::string &link_name,
00208                   const sensor_msgs::JointState &detach_posture = sensor_msgs::JointState());
00209 
00211   void getAttachedBodies(std::vector<const AttachedBody*> &attached_bodies) const;
00212 
00214   bool clearAttachedBody(const std::string &id);
00215 
00217   void clearAttachedBodies(const std::string &link_name);
00218 
00220   void clearAttachedBodies();
00221 
00223   const AttachedBody* getAttachedBody(const std::string &name) const;
00224 
00226   bool hasAttachedBody(const std::string &id) const;
00227 
00230   const Eigen::Affine3d& getFrameTransform(const std::string &id) const;
00231 
00233   void computeAABB(std::vector<double> &aabb) const;
00234 
00236   bool knowsFrameTransform(const std::string &id) const;
00237 
00239   void printStateInfo(std::ostream &out = std::cout) const;
00240 
00242   std::string getStateTreeString(const std::string& prefix = "") const;
00243 
00245   void printTransforms(std::ostream &out = std::cout) const;
00246 
00248   const Eigen::Affine3d& getRootTransform() const;
00249 
00251   void setRootTransform(const Eigen::Affine3d &transform);
00252 
00254   random_numbers::RandomNumberGenerator& getRandomNumberGenerator();
00255 
00263   void getRobotMarkers(visualization_msgs::MarkerArray& arr,
00264                        const std::vector<std::string> &link_names,
00265                        const std_msgs::ColorRGBA& color,
00266                        const std::string& ns,
00267                        const ros::Duration& dur,
00268                        bool include_attached = false) const;
00269 
00274   void getRobotMarkers(visualization_msgs::MarkerArray& arr,
00275                        const std::vector<std::string> &link_names,
00276                        bool include_attached = false) const;
00277 
00279   void interpolate(const RobotState &to, const double t, RobotState &dest) const;
00280 
00282   double infinityNormDistance(const robot_state::RobotState *other) const;
00283 
00285   double distance(const RobotState &state) const;
00286 
00288   RobotState& operator=(const RobotState &other);
00289 
00290   void setAttachedBodyUpdateCallback(const AttachedBodyCallback &callback);
00291 
00292 private:
00293 
00294   void buildState();
00295   void copyFrom(const RobotState &ks);
00296   void printTransform(const std::string &st, const Eigen::Affine3d &t, std::ostream &out = std::cout) const;
00297   void getStateTreeJointString(std::stringstream& ss, const robot_state::JointState* js, const std::string& prefix, bool last) const;
00298   static void getPoseString(std::stringstream& ss, const Eigen::Affine3d& mtx, const std::string& pfx = "");
00299 
00300 
00301   robot_model::RobotModelConstPtr kinematic_model_;
00302 
00303   std::vector<JointState*>                joint_state_vector_;
00304   std::map<std::string, JointState*>      joint_state_map_;
00305 
00307   std::vector<LinkState*>                 link_state_vector_;
00308 
00310   std::map<std::string, LinkState*>       link_state_map_;
00311 
00313   Eigen::Affine3d                         root_transform_;
00314 
00316   std::map<std::string, JointStateGroup*> joint_state_group_map_;
00317 
00319   std::map<std::string, AttachedBody*>    attached_body_map_;
00320 
00325   boost::scoped_ptr<random_numbers::RandomNumberGenerator> rng_;
00326 
00329   AttachedBodyCallback attached_body_update_callback_;
00330 };
00331 
00332 typedef boost::shared_ptr<RobotState> RobotStatePtr;
00333 typedef boost::shared_ptr<const RobotState> RobotStateConstPtr;
00334 
00335 }
00336 
00337 #endif


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Mon Oct 6 2014 02:24:47