00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
00050
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
00069
00070
00071
00072
00073
00074
00075
00076 class RobotInteraction
00077 {
00078 public:
00079
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
00143
00144 void updateInteractiveMarkers(
00145 const ::robot_interaction::InteractionHandlerPtr &handler);
00146
00147
00148 bool showingMarkers(
00149 const ::robot_interaction::InteractionHandlerPtr &handler);
00150
00151
00152
00153
00154
00155 void publishInteractiveMarkers();
00156
00157
00158
00159
00160
00161 void clearInteractiveMarkers();
00162
00163 const robot_model::RobotModelConstPtr& getRobotModel() const { return robot_model_; }
00164
00165
00166
00167 KinematicOptionsMapPtr getKinematicOptionsMap() { return kinematic_options_map_; }
00168
00169
00170 void toggleMoveInteractiveMarkerTopic(bool enable);
00171 private:
00172
00173 void decideActiveEndEffectors(const std::string &group);
00174 void decideActiveEndEffectors(const std::string &group,
00175 InteractionStyle::InteractionStyle style);
00176
00177
00178
00179 void decideActiveJoints(const std::string &group);
00180
00181 void moveInteractiveMarker(const std::string name,
00182 const geometry_msgs::PoseStampedConstPtr& msg);
00183
00184
00185 void registerMoveInteractiveMarkerTopic(
00186 const std::string marker_name, const std::string& name);
00187
00188
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
00232
00233
00234
00235
00236
00237
00238
00239 boost::mutex marker_access_lock_;
00240
00241 interactive_markers::InteractiveMarkerServer *int_marker_server_;
00242
00243 std::vector<ros::Subscriber> int_marker_move_subscribers_;
00244
00245
00246 std::vector<std::string> int_marker_move_topics_;
00247
00248 std::vector<std::string> int_marker_names_;
00249
00250 std::string topic_;
00251
00252
00253
00254 KinematicOptionsMapPtr kinematic_options_map_;
00255
00256 public:
00257
00258
00259
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
00281 void decideActiveComponents(const std::string &group,
00282 EndEffectorInteractionStyle style);
00283
00284 void decideActiveEndEffectors(const std::string &group,
00285 EndEffectorInteractionStyle style);
00286
00287 const std::vector<EndEffectorInteraction>& getActiveEndEffectors() const
00288 {
00289 return active_eef_;
00290 }
00291
00292 const std::vector<JointInteraction>& getActiveJoints() const
00293 {
00294 return active_vj_;
00295 }
00296
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