interactive_robot.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 *
00003 * Software License Agreement (BSD License)
00004 *
00005 *  Copyright (c) 2013, Willow Garage, Inc.
00006 *  All rights reserved.
00007 *
00008 *  Redistribution and use in source and binary forms, with or without
00009 *  modification, are permitted provided that the following conditions
00010 *  are met:
00011 *
00012 *   * Redistributions of source code must retain the above copyright
00013 *     notice, this list of conditions and the following disclaimer.
00014 *   * Redistributions in binary form must reproduce the above
00015 *     copyright notice, this list of conditions and the following
00016 *     disclaimer in the documentation and/or other materials provided
00017 *     with the distribution.
00018 *   * Neither the name of Willow Garage, Inc. nor the names of its
00019 *     contributors may be used to endorse or promote products derived
00020 *     from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 *  POSSIBILITY OF SUCH DAMAGE.
00034 *
00035 * Author: Acorn Pooley
00036 *********************************************************************/
00037 
00038 // This code goes with the interactivity tutorial
00039 //    http://moveit.ros.org/wiki/index.php/Groovy/InteractiveRobot/InteractivityTutorial
00040 
00041 #ifndef PR2_MOVEIT_TUTORIALS_INTERACTIVITY_SRC_INTERACTIVE_ROBOT_H_
00042 #define PR2_MOVEIT_TUTORIALS_INTERACTIVITY_SRC_INTERACTIVE_ROBOT_H_
00043 
00044 #include <ros/ros.h>
00045 #include <moveit/robot_model_loader/robot_model_loader.h>
00046 #include <moveit/robot_model/robot_model.h>
00047 #include <moveit/robot_state/robot_state.h>
00048 #include <moveit/robot_state/joint_state_group.h>
00049 #include <moveit_msgs/DisplayRobotState.h>
00050 #include "imarker.h"
00051 
00052 
00056 class InteractiveRobot {
00057 public:
00058   InteractiveRobot(
00059         const std::string& robot_description = "robot_description",
00060         const std::string& robot_topic = "interactive_robot_state",
00061         const std::string& marker_topic = "interactive_robot_markers",
00062         const std::string& imarker_topic = "interactive_robot_imarkers");
00063   ~InteractiveRobot();
00064 
00066   void setGroup(const std::string& name);
00067   const std::string& getGroupName() const;
00068 
00070   bool setGroupPose(const Eigen::Affine3d& pose);
00071 
00073   void setWorldObjectPose(const Eigen::Affine3d& pose);
00074 
00076   void setUserCallback(boost::function<void (InteractiveRobot& robot)> callback)
00077   {
00078     user_callback_ = callback;
00079   }
00080 
00082   robot_model::RobotModelPtr& robotModel() { return robot_model_; }
00084   robot_state::RobotStatePtr& robotState() { return robot_state_; }
00085 
00087   void getWorldGeometry(Eigen::Affine3d& pose, double& size);
00088 
00090   class RobotLoadException : std::exception
00091   { };
00092 
00095   void *user_data_;
00096 
00097 private:
00098   /* Indicate that the world or the robot has changed and
00099    * the new state needs to be updated and published to rviz */
00100   void scheduleUpdate();
00101 
00102 
00103   /* set the callback timer to fire if needed.
00104    * Return true if callback should happen immediately. */
00105   bool setCallbackTimer(bool new_update_request);
00106 
00107   /* update the world and robot state and publish to rviz */
00108   void updateCallback(const ros::TimerEvent& e);
00109 
00110   /* functions to calculate new state and publish to rviz */
00111   void updateAll();
00112   void publishRobotState();
00113   void publishWorldState();
00114 
00115   /* callback called when marker moves.  Moves right hand to new marker pose. */
00116   static void movedRobotMarkerCallback(
00117       InteractiveRobot *robot,
00118       const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00119 
00120   /* callback called when marker moves.  Moves world object to new pose. */
00121   static void movedWorldMarkerCallback(
00122       InteractiveRobot *robot,
00123       const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00124 
00125 
00126   /* marker publishers */
00127   ros::NodeHandle nh_;
00128   ros::Publisher robot_state_publisher_;
00129   ros::Publisher world_state_publisher_;
00130   interactive_markers::InteractiveMarkerServer interactive_marker_server_;
00131   IMarker *imarker_robot_;
00132   IMarker *imarker_world_;
00133 
00134   /* robot info */
00135   robot_model_loader::RobotModelLoader rm_loader_;
00136   robot_model::RobotModelPtr robot_model_;
00137   robot_state::RobotStatePtr robot_state_;
00138 
00139   /* info about joint group we are manipulating */
00140   robot_state::JointStateGroup* group_;
00141   Eigen::Affine3d desired_group_end_link_pose_;
00142 
00143   /* world info */
00144   Eigen::Affine3d desired_world_object_pose_;
00145   static const double WORLD_BOX_SIZE_;
00146   static const Eigen::Affine3d DEFAULT_WORLD_OBJECT_POSE_;
00147 
00148   /* user callback function */
00149   boost::function<void (InteractiveRobot& robot)> user_callback_;
00150 
00151   /* timer info for rate limiting */
00152   ros::Timer publish_timer_;
00153   ros::Time init_time_;
00154   ros::Time last_callback_time_;
00155   ros::Duration average_callback_duration_;
00156   static const ros::Duration min_delay_;
00157   int schedule_request_count_;
00158 };
00159 
00160 #endif // PR2_MOVEIT_TUTORIALS_INTERACTIVITY_SRC_INTERACTIVE_ROBOT_H_


pr2_moveit_tutorials
Author(s): Sachin Chitta
autogenerated on Mon Oct 6 2014 11:15:31