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


jsk_interactive_marker
Author(s): furuta
autogenerated on Sun Sep 13 2015 22:29:27