robot_interaction.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 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, Adam Leeper */
00036 
00037 #ifndef MOVEIT_ROBOT_INTERACTION_ROBOT_INTERACTION_
00038 #define MOVEIT_ROBOT_INTERACTION_ROBOT_INTERACTION_
00039 
00040 #include <visualization_msgs/InteractiveMarkerFeedback.h>
00041 #include <visualization_msgs/InteractiveMarker.h>
00042 #include <geometry_msgs/PoseArray.h>
00043 #include <interactive_markers/menu_handler.h>
00044 #include <moveit/robot_state/robot_state.h>
00045 #include <moveit/robot_interaction/interaction.h>
00046 #include <boost/function.hpp>
00047 #include <boost/thread.hpp>
00048 
00049 // This is needed for legacy code that includes robot_interaction.h but not
00050 // interaction_handler.h
00051 #include <moveit/robot_interaction/interaction_handler.h>
00052 
00053 namespace interactive_markers
00054 {
00055 class InteractiveMarkerServer;
00056 }
00057 
00058 namespace robot_interaction
00059 {
00060 
00061 class InteractionHandler;
00062 typedef boost::shared_ptr<InteractionHandler> InteractionHandlerPtr;
00063 
00064 class KinematicOptionsMap;
00065 typedef boost::shared_ptr<KinematicOptionsMap> KinematicOptionsMapPtr;
00066 
00067 
00068 // Manage interactive markers for controlling a robot state.
00069 //
00070 // The RobotInteraction class manages one or more InteractionHandler objects
00071 // each of which maintains a set of interactive markers for manipulating one
00072 // group of one RobotState.
00073 //
00074 // The group being manipulated is common to all InteractionHandler objects
00075 // contained in a RobotInteraction instance.
00076 class RobotInteraction
00077 {
00078 public:
00079   // DEPRECATED TYPES.  For backwards compatibility.  Avoid using these.
00080   typedef ::robot_interaction::InteractionHandler InteractionHandler;
00081   typedef ::robot_interaction::InteractionHandlerPtr InteractionHandlerPtr;
00082   typedef ::robot_interaction::EndEffectorInteraction EndEffector;
00083   typedef ::robot_interaction::JointInteraction Joint;
00084   typedef ::robot_interaction::GenericInteraction Generic;
00085 public:
00086 
00088   static const std::string INTERACTIVE_MARKER_TOPIC;
00089 
00090 
00091   RobotInteraction(const robot_model::RobotModelConstPtr &kmodel,
00092                    const std::string &ns = "");
00093   virtual ~RobotInteraction();
00094 
00095   const std::string& getServerTopic(void) const
00096   {
00097     return topic_;
00098   }
00099 
00111   void addActiveComponent(
00112         const InteractiveMarkerConstructorFn &construct,
00113         const ProcessFeedbackFn &process,
00114         const InteractiveMarkerUpdateFn &update = InteractiveMarkerUpdateFn(),
00115         const std::string &name = "");
00116 
00125   void decideActiveComponents(const std::string &group);
00126   void decideActiveComponents(const std::string &group,
00127                               InteractionStyle::InteractionStyle style);
00128 
00131   void clear();
00132 
00138   void addInteractiveMarkers(
00139         const ::robot_interaction::InteractionHandlerPtr &handler,
00140         const double marker_scale = 0.0);
00141 
00142   // Update pose of all interactive markers to match the handler's RobotState.
00143   // Call this when the handler's RobotState changes.
00144   void updateInteractiveMarkers(
00145         const ::robot_interaction::InteractionHandlerPtr &handler);
00146 
00147   // True if markers are being shown for this handler.
00148   bool showingMarkers(
00149         const ::robot_interaction::InteractionHandlerPtr &handler);
00150 
00151   // Display all markers that have been added.
00152   // This is needed after calls to addInteractiveMarkers() to publish the
00153   // resulting markers so they get displayed.  This call is not needed after
00154   // calling updateInteractiveMarkers() which publishes the results itself.
00155   void publishInteractiveMarkers();
00156 
00157   // Clear all interactive markers.
00158   // This removes all interactive markers but does not affect which
00159   // interactions are active.  After this a call to publishInteractiveMarkers()
00160   // is needed to actually remove the markers from the display.
00161   void clearInteractiveMarkers();
00162 
00163   const robot_model::RobotModelConstPtr& getRobotModel() const { return robot_model_; }
00164 
00165   // Get the kinematic options map.
00166   // Use this to set kinematic options (defaults or per-group).
00167   KinematicOptionsMapPtr getKinematicOptionsMap() { return kinematic_options_map_; }
00168   
00169   // enable/disable subscription of the topics to move interactive marker
00170   void toggleMoveInteractiveMarkerTopic(bool enable);
00171 private:
00172   // called by decideActiveComponents(); add markers for end effectors
00173   void decideActiveEndEffectors(const std::string &group);
00174   void decideActiveEndEffectors(const std::string &group,
00175                                 InteractionStyle::InteractionStyle style);
00176 
00177   // called by decideActiveComponents(); add markers for planar and floating
00178   // joints
00179   void decideActiveJoints(const std::string &group);
00180 
00181   void moveInteractiveMarker(const std::string name,
00182                              const geometry_msgs::PoseStampedConstPtr& msg);
00183   // register the name of the topic and marker name to move
00184   // interactive marker from other ROS nodes
00185   void registerMoveInteractiveMarkerTopic(
00186     const std::string marker_name, const std::string& name);
00187   // return the diameter of the sphere that certainly can enclose the AABB of
00188   // the links in this group
00189   double computeGroupMarkerSize(const std::string &group);
00190   void computeMarkerPose(
00191         const ::robot_interaction::InteractionHandlerPtr &handler,
00192         const EndEffectorInteraction &eef,
00193         const robot_state::RobotState &robot_state,
00194         geometry_msgs::Pose &pose,
00195         geometry_msgs::Pose &control_to_eef_tf) const;
00196 
00197   void addEndEffectorMarkers(
00198         const ::robot_interaction::InteractionHandlerPtr &handler,
00199         const EndEffectorInteraction& eef,
00200         visualization_msgs::InteractiveMarker& im,
00201         bool position = true,
00202         bool orientation = true);
00203   void addEndEffectorMarkers(
00204         const ::robot_interaction::InteractionHandlerPtr &handler,
00205         const EndEffectorInteraction& eef,
00206         const geometry_msgs::Pose& offset,
00207         visualization_msgs::InteractiveMarker& im,
00208         bool position = true,
00209         bool orientation = true);
00210   void processInteractiveMarkerFeedback(
00211         const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback);
00212   void subscribeMoveInteractiveMarker(const std::string marker_name, const std::string& name);
00213   void processingThread();
00214   void clearInteractiveMarkersUnsafe();
00215 
00216   boost::scoped_ptr<boost::thread> processing_thread_;
00217   bool run_processing_thread_;
00218 
00219   boost::condition_variable new_feedback_condition_;
00220   std::map<std::string, visualization_msgs::InteractiveMarkerFeedbackConstPtr> feedback_map_;
00221 
00222   robot_model::RobotModelConstPtr robot_model_;
00223 
00224   std::vector<EndEffectorInteraction> active_eef_;
00225   std::vector<JointInteraction> active_vj_;
00226   std::vector<GenericInteraction> active_generic_;
00227 
00228   std::map<std::string, ::robot_interaction::InteractionHandlerPtr> handlers_;
00229   std::map<std::string, std::size_t> shown_markers_;
00230 
00231   // This mutex is locked every time markers are read or updated;
00232   // This includes the active_* arrays and shown_markers_
00233   // Please note that this mutex *MUST NOT* be locked while operations
00234   // on the interative marker server are called because the server
00235   // also locks internally and we could othewrise end up with a problem
00236   // of Thread 1: Lock A,         Lock B, Unlock B, Unloack A
00237   //    Thread 2:         Lock B, Lock A
00238   // => deadlock
00239   boost::mutex marker_access_lock_;
00240 
00241   interactive_markers::InteractiveMarkerServer *int_marker_server_;
00242   // ros subscribers to move the interactive markers by other ros nodes
00243   std::vector<ros::Subscriber> int_marker_move_subscribers_;
00244   // the array of the names of the topics which need to be subscribed
00245   // to move the interactive markers by other ROS nodes
00246   std::vector<std::string> int_marker_move_topics_;
00247   // the array of the marker names in the same order to int_marker_move_topics_
00248   std::vector<std::string> int_marker_names_;
00249   
00250   std::string topic_;
00251 
00252   // options for doing IK
00253   // Locking is done internally
00254   KinematicOptionsMapPtr kinematic_options_map_;
00255 
00256 public:
00257   // DEPRECATED.  This is included for backwards compatibility.
00258   // These classes/enums used to be subclasses of RobotInteraction.  This
00259   // allows client code to continue to work as if they are.
00260 
00263   enum EndEffectorInteractionStyle
00264   {
00265     EEF_POSITION_ARROWS = InteractionStyle::POSITION_ARROWS,
00266     EEF_ORIENTATION_CIRCLES = InteractionStyle::ORIENTATION_CIRCLES,
00267     EEF_POSITION_SPHERE = InteractionStyle::POSITION_SPHERE,
00268     EEF_ORIENTATION_SPHERE = InteractionStyle::ORIENTATION_SPHERE,
00269     EEF_POSITION_EEF = InteractionStyle::POSITION_EEF,
00270     EEF_ORIENTATION_EEF = InteractionStyle::ORIENTATION_EEF,
00271     EEF_FIXED = InteractionStyle::FIXED,
00272     EEF_POSITION = InteractionStyle::POSITION,
00273     EEF_ORIENTATION = InteractionStyle::ORIENTATION,
00274     EEF_6DOF = InteractionStyle::SIX_DOF,
00275     EEF_6DOF_SPHERE = InteractionStyle::SIX_DOF_SPHERE,
00276     EEF_POSITION_NOSPHERE = InteractionStyle::POSITION_NOSPHERE,
00277     EEF_ORIENTATION_NOSPHERE = InteractionStyle::ORIENTATION_NOSPHERE,
00278     EEF_6DOF_NOSPHERE = InteractionStyle::SIX_DOF_NOSPHERE
00279   };
00280   // DEPRECATED.  Use InteractionStyle::InteractionStyle version.
00281   void decideActiveComponents(const std::string &group,
00282                               EndEffectorInteractionStyle style);
00283   // DEPRECATED.  Use InteractionStyle::InteractionStyle version.
00284   void decideActiveEndEffectors(const std::string &group,
00285                                 EndEffectorInteractionStyle style);
00286   // DEPRECATED
00287   const std::vector<EndEffectorInteraction>& getActiveEndEffectors() const
00288   {
00289     return active_eef_;
00290   }
00291   // DEPRECATED
00292   const std::vector<JointInteraction>& getActiveJoints() const
00293   {
00294     return active_vj_;
00295   }
00296   // DEPRECATED
00297   static bool updateState(
00298             robot_state::RobotState &state,
00299             const EndEffectorInteraction &eef,
00300             const geometry_msgs::Pose &pose,
00301             unsigned int attempts,
00302             double ik_timeout,
00303             const robot_state::GroupStateValidityCallbackFn &validity_callback =
00304                                 robot_state::GroupStateValidityCallbackFn(),
00305             const kinematics::KinematicsQueryOptions &kinematics_query_options =
00306                                 kinematics::KinematicsQueryOptions());
00307 };
00308 
00309 typedef boost::shared_ptr<RobotInteraction> RobotInteractionPtr;
00310 typedef boost::shared_ptr<const RobotInteraction> RobotInteractionConstPtr;
00311 
00312 
00313 }
00314 
00315 #endif


robot_interaction
Author(s): Ioan Sucan
autogenerated on Wed Aug 26 2015 12:44:19