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