current_state_monitor.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 the 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_PLANNING_SCENE_MONITOR_CURRENT_STATE_MONITOR_
00038 #define MOVEIT_PLANNING_SCENE_MONITOR_CURRENT_STATE_MONITOR_
00039 
00040 #include <ros/ros.h>
00041 #include <tf/tf.h>
00042 #include <moveit/robot_state/robot_state.h>
00043 #include <sensor_msgs/JointState.h>
00044 #include <boost/function.hpp>
00045 #include <boost/shared_ptr.hpp>
00046 #include <boost/thread/mutex.hpp>
00047 
00048 namespace planning_scene_monitor
00049 {
00050 
00051 typedef boost::function<void(const sensor_msgs::JointStateConstPtr &joint_state)> JointStateUpdateCallback;
00052 
00055 class CurrentStateMonitor
00056 {
00057 public:
00058 
00063   CurrentStateMonitor(const robot_model::RobotModelConstPtr &kmodel, const boost::shared_ptr<tf::Transformer> &tf);
00064 
00065   ~CurrentStateMonitor();
00066 
00070   void startStateMonitor(const std::string &joint_states_topic = "joint_states");
00071 
00074   void stopStateMonitor();
00075 
00077   bool isActive() const;
00078 
00080   const robot_model::RobotModelConstPtr& getRobotModel() const
00081   {
00082     return kmodel_;
00083   }
00084 
00086   std::string getMonitoredTopic() const;
00087 
00091   bool haveCompleteState() const;
00092 
00097   bool haveCompleteState(const ros::Duration &age) const;
00098 
00103   bool haveCompleteState(std::vector<std::string> &missing_joints) const;
00104 
00110   bool haveCompleteState(const ros::Duration &age, std::vector<std::string> &missing_states) const;
00111 
00114   robot_state::RobotStatePtr getCurrentState() const;
00115 
00117   ros::Time getCurrentStateTime() const;
00118 
00121   std::pair<robot_state::RobotStatePtr, ros::Time> getCurrentStateAndTime() const;
00122 
00125   std::map<std::string, double> getCurrentStateValues() const;
00126 
00128   bool waitForCurrentState(double wait_time) const;
00129 
00131   bool waitForCurrentState(const std::string &group, double wait_time) const;
00132 
00134   const ros::Time& getMonitorStartTime() const
00135   {
00136     return monitor_start_time_;
00137   }
00138 
00140   void addUpdateCallback(const JointStateUpdateCallback &fn);
00141 
00143   void clearUpdateCallbacks();
00144 
00149   void setBoundsError(double error)
00150   {
00151     error_ = (error > 0) ? error : -error;
00152   }
00153 
00158   double getBoundsError() const
00159   {
00160     return error_;
00161   }
00162 
00163 private:
00164 
00165   void jointStateCallback(const sensor_msgs::JointStateConstPtr &joint_state);
00166   bool isPassiveDOF(const std::string &dof) const;
00167 
00168   ros::NodeHandle                              nh_;
00169   boost::shared_ptr<tf::Transformer>           tf_;
00170   robot_model::RobotModelConstPtr              kmodel_;
00171   robot_state::RobotState                      kstate_;
00172   robot_state::JointState                     *root_;
00173   std::map<std::string, ros::Time>             joint_time_;
00174   bool                                         state_monitor_started_;
00175   ros::Time                                    monitor_start_time_;
00176   double                                       error_;
00177   ros::Subscriber                              joint_state_subscriber_;
00178   ros::Time                                    current_state_time_;
00179 
00180   mutable boost::mutex                         state_update_lock_;
00181   std::vector< JointStateUpdateCallback >      update_callbacks_;
00182 };
00183 
00184 typedef boost::shared_ptr<CurrentStateMonitor> CurrentStateMonitorPtr;
00185 typedef boost::shared_ptr<const CurrentStateMonitor> CurrentStateMonitorConstPtr;
00186 }
00187 
00188 #endif


planning
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Mon Oct 6 2014 02:31:39