interactive_marker_interface.h
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 
00003 #include <tf/tf.h>
00004 //#include <tf/transform_listener.h>
00005 #include <tf/transform_broadcaster.h>
00006 
00007 #include <interactive_markers/interactive_marker_server.h>
00008 
00009 #include <interactive_markers/menu_handler.h>
00010 #include <jsk_interactive_marker/SetPose.h>
00011 #include <jsk_interactive_marker/MarkerSetPose.h>
00012 
00013 #include <math.h>
00014 #include <jsk_interactive_marker/MarkerMenu.h>
00015 #include <jsk_interactive_marker/MarkerPose.h>
00016 
00017 #include <std_msgs/Int8.h>
00018 #include "urdf_parser/urdf_parser.h"
00019 #if ROS_VERSION_MINIMUM(1,12,0) // kinetic
00020 #include <urdf_world/types.h>
00021 #else
00022 namespace urdf {
00023 typedef boost::shared_ptr<ModelInterface> ModelInterfaceSharedPtr;
00024 }
00025 #endif
00026 
00027 class InteractiveMarkerInterface {
00028  private:
00029   struct MeshProperty{
00030     std::string link_name;
00031     std::string mesh_file;
00032     geometry_msgs::Point position;
00033     geometry_msgs::Quaternion orientation;
00034 
00035   };
00036 
00037   struct UrdfProperty{
00038     urdf::ModelInterfaceSharedPtr model;
00039     std::string root_link_name;
00040     geometry_msgs::Pose pose;
00041     double scale;
00042     std_msgs::ColorRGBA color;
00043     bool use_original_color;
00044   };
00045 
00046  public:
00047   visualization_msgs::InteractiveMarker make6DofControlMarker( std::string name, geometry_msgs::PoseStamped &stamped, float scale, bool fixed_position, bool fixed_rotation);
00048 
00049   void proc_feedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00050   void proc_feedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, int type );
00051   void pub_marker_tf ( std_msgs::Header header, geometry_msgs::Pose pose);
00052   void pub_marker_pose ( std_msgs::Header header, geometry_msgs::Pose pose, std::string name, int type );
00053 
00054   void pub_marker_menu(std::string marker,int menu, int type);
00055   void pub_marker_menu(std::string marker,int menu);
00056   
00057   void pub_marker_menuCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, int menu );
00058 
00059   void pub_marker_menuCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, int menu, int type);
00060 
00061   void IMSizeLargeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00062 
00063   void IMSizeMiddleCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00064 
00065   void IMSizeSmallCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00066 
00067   void changeMoveModeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00068 
00069   void changeMoveModeCb1( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00070 
00071   void changeMoveModeCb2( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00072 
00073   void changeForceModeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00074 
00075   void changeForceModeCb1( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00076 
00077   void changeForceModeCb2( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00078 
00079   
00080   void targetPointMenuCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00081 
00082   void lookAutomaticallyMenuCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00083 
00084   void ConstraintCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00085 
00086   void modeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00087 
00088   void changeMoveArm( std::string m_name, int menu );
00089   
00090   void setOriginCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, bool origin_hand);
00091 
00092   void ikmodeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00093   void toggleIKModeCb( const std_msgs::EmptyConstPtr &msg);
00094   void useTorsoCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00095 
00096   void usingIKCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00097 
00098   void marker_menu_cb( const jsk_interactive_marker::MarkerMenuConstPtr &msg);
00099 
00100   void updateHeadGoal( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
00101   void updateBase( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
00102   void updateFinger( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, std::string hand);
00103 
00104   visualization_msgs::InteractiveMarker makeBaseMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed);
00105 
00106 
00107 
00108   void changeMarkerForceMode( std::string mk_name , int im_mode);
00109   
00110   void toggleStartIKCb( const std_msgs::EmptyConstPtr &msg);
00111 
00112   void initControlMarkers(void);
00113 
00114   void initBodyMarkers(void);
00115 
00116   void initHandler(void);
00117 
00118   void changeMarkerMoveMode( std::string mk_name , int im_mode);
00119 
00120   void changeMarkerMoveMode( std::string mk_name , int im_mode, float mk_size);
00121 
00122   void changeMarkerMoveMode( std::string mk_name , int im_mode, float mk_size, geometry_msgs::PoseStamped dist_pose);
00123 
00124   void changeMarkerOperationModelMode( std::string mk_name );
00125 
00126   //void addHandMarker(visualization_msgs::InteractiveMarkerControl &imc,std::vector < MeshProperty > mesh_vec, double mk_size);
00127   void addHandMarker(visualization_msgs::InteractiveMarker &im,std::vector < UrdfProperty > urdf_vec);
00128   void addSphereMarker(visualization_msgs::InteractiveMarker &im, double scale, std_msgs::ColorRGBA color);
00129   void makeCenterSphere(visualization_msgs::InteractiveMarker &mk, double mk_size);
00130 
00131   InteractiveMarkerInterface ();
00132 
00133   bool markers_set_cb ( jsk_interactive_marker::MarkerSetPose::Request &req,
00134                         jsk_interactive_marker::MarkerSetPose::Response &res );
00135 
00136   bool markers_del_cb ( jsk_interactive_marker::MarkerSetPose::Request &req,
00137                         jsk_interactive_marker::MarkerSetPose::Response &res );
00138 
00139   void move_marker_cb ( const geometry_msgs::PoseStampedConstPtr &msg);
00140 
00141   bool set_cb ( jsk_interactive_marker::MarkerSetPose::Request &req,
00142                 jsk_interactive_marker::MarkerSetPose::Response &res );
00143 
00144   bool reset_cb ( jsk_interactive_marker::SetPose::Request &req,
00145                   jsk_interactive_marker::SetPose::Response &res );
00146 
00147   void loadMeshFromYaml(XmlRpc::XmlRpcValue val, std::string name, std::vector<MeshProperty>& mesh);
00148   void loadUrdfFromYaml(XmlRpc::XmlRpcValue val, std::string name, std::vector<UrdfProperty>& mesh);
00149   void loadMeshes(XmlRpc::XmlRpcValue val);
00150 
00151   void makeIMVisible(visualization_msgs::InteractiveMarker &im);
00152 
00153  private:
00154 
00155   ros::NodeHandle nh_;
00156   ros::NodeHandle pnh_;
00157   std::shared_ptr<interactive_markers::InteractiveMarkerServer> server_;
00158   ros::Publisher pub_;
00159   ros::Publisher pub_update_;
00160   ros::Publisher pub_move_;
00161   ros::ServiceServer serv_reset_;
00162   ros::ServiceServer serv_set_;
00163   ros::ServiceServer serv_markers_set_;
00164   ros::ServiceServer serv_markers_del_;
00165   ros::Subscriber sub_marker_pose_;
00166   ros::Subscriber sub_marker_menu_;
00167   ros::Subscriber sub_toggle_start_ik_;
00168   ros::Subscriber sub_toggle_ik_mode_;
00169   //tf::TransformListener tfl_;
00170   tf::TransformBroadcaster tfb_;
00171   ros::ServiceClient dynamic_tf_publisher_client_;
00172 
00173   interactive_markers::MenuHandler menu_handler;
00174   interactive_markers::MenuHandler menu_handler1;
00175   interactive_markers::MenuHandler menu_handler2;
00176   interactive_markers::MenuHandler menu_handler_force;
00177   interactive_markers::MenuHandler menu_handler_force1;
00178   interactive_markers::MenuHandler menu_handler_force2;
00179   interactive_markers::MenuHandler::EntryHandle sub_menu_handle;
00180   interactive_markers::MenuHandler::EntryHandle sub_menu_handle2;
00181   interactive_markers::MenuHandler::EntryHandle sub_menu_handle_ik;
00182 
00183   interactive_markers::MenuHandler menu_head_;
00184   interactive_markers::MenuHandler::EntryHandle head_target_handle_;
00185   interactive_markers::MenuHandler::EntryHandle head_auto_look_handle_;
00186 
00187   interactive_markers::MenuHandler menu_head_target_;
00188 
00189   interactive_markers::MenuHandler menu_base_;
00190   interactive_markers::MenuHandler menu_finger_r_;
00191   interactive_markers::MenuHandler menu_finger_l_;
00192 
00193   // parameters
00194   std::string marker_name;
00195   std::string server_name;
00196   std::string base_frame;
00197   std::string move_base_frame;
00198   std::string target_frame;
00199   bool fix_marker;
00200   interactive_markers::MenuHandler::EntryHandle h_mode_last;
00201   interactive_markers::MenuHandler::EntryHandle h_mode_last2;
00202   interactive_markers::MenuHandler::EntryHandle h_mode_last3;
00203 
00204   interactive_markers::MenuHandler::EntryHandle rotation_t_menu_;
00205   interactive_markers::MenuHandler::EntryHandle rotation_nil_menu_;
00206 
00207   interactive_markers::MenuHandler::EntryHandle use_torso_menu_;
00208   interactive_markers::MenuHandler::EntryHandle use_torso_t_menu_;
00209   interactive_markers::MenuHandler::EntryHandle use_torso_nil_menu_;
00210   interactive_markers::MenuHandler::EntryHandle use_fullbody_menu_;
00211 
00212 
00213   interactive_markers::MenuHandler::EntryHandle start_ik_menu_;
00214   interactive_markers::MenuHandler::EntryHandle stop_ik_menu_;
00215 
00216   int h_mode_rightarm;
00217   int h_mode_constrained;
00218   int h_mode_ikmode;
00219   int use_arm;
00220 
00221   
00222 
00223   std::list<visualization_msgs::InteractiveMarker> imlist;
00224   //interactive_markers::MenuHandler menu_handler;
00225 
00226   struct GripperState{
00227   GripperState() : on_(false), view_facing_(false), edit_control_(false), torso_frame_(false) {}
00228 
00229     bool on_;
00230     bool view_facing_;
00231     bool edit_control_;
00232     bool torso_frame_;
00233   };
00234 
00235   struct ControlState{
00236   ControlState() : posture_r_(false), posture_l_(false), torso_on_(false), head_on_(false),
00237       projector_on_(false), init_head_goal_(false), base_on_(true),  r_finger_on_(false), l_finger_on_(false), move_arm_(RARM), move_origin_state_(HAND_ORIGIN) {}
00238 
00239     void print()
00240     {
00241       ROS_DEBUG_NAMED("control_state", "gripper: on[%d|%d][%d], edit[%d|%d][%d], torso[%d|%d]",
00242                       l_gripper_.on_, r_gripper_.on_, dual_grippers_.on_, l_gripper_.edit_control_, r_gripper_.edit_control_, dual_grippers_.edit_control_, l_gripper_.torso_frame_, r_gripper_.torso_frame_);
00243       ROS_DEBUG_NAMED("control_state", "posture[%d|%d] torso[%d] base[%d] head[%d] projector[%d]",
00244                       posture_l_, posture_r_, torso_on_, base_on_, head_on_, projector_on_ );
00245     }
00246 
00247     enum MoveArmState { RARM, LARM, ARMS};
00248     enum MoveOriginState { HAND_ORIGIN, DESIGNATED_ORIGIN};
00249 
00250     MoveArmState move_arm_;
00251     MoveOriginState move_origin_state_;
00252     
00253     geometry_msgs::PoseStamped marker_pose_;
00254 
00255     bool posture_r_;
00256     bool posture_l_;
00257     bool torso_on_;
00258     bool head_on_;
00259     bool projector_on_;
00260     bool look_auto_on_;
00261     bool init_head_goal_;
00262     bool base_on_;
00263     bool planar_only_;
00264     bool r_finger_on_;
00265     bool l_finger_on_;
00266     GripperState dual_grippers_;
00267     GripperState r_gripper_;
00268     GripperState l_gripper_;
00269   };
00270 
00271   bool use_finger_marker_;
00272   bool use_body_marker_;
00273   bool use_center_sphere_;
00274 
00275 
00276   ControlState control_state_;
00277 
00278   geometry_msgs::PoseStamped head_goal_pose_;
00279 
00280   std::string hand_type_;
00281 
00282   std::string head_link_frame_;
00283   std::string head_mesh_;
00284   std::vector< MeshProperty > rhand_mesh_, lhand_mesh_;
00285   std::vector< UrdfProperty > rhand_urdf_, lhand_urdf_;
00286 
00287 };
00288 


jsk_interactive_marker
Author(s): furuta
autogenerated on Wed May 1 2019 02:40:31