Go to the documentation of this file.00001 #include <ros/ros.h>
00002
00003 #include <interactive_markers/interactive_marker_server.h>
00004 #include <interactive_markers/menu_handler.h>
00005
00006 #include <tf/transform_broadcaster.h>
00007 #include <tf/tf.h>
00008
00009 #include <dynamic_tf_publisher/SetDynamicTF.h>
00010 using namespace visualization_msgs;
00011
00012 class UrdfControlMarker {
00013 public:
00014 UrdfControlMarker();
00015 void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00016 void makeControlMarker( bool fixed );
00017 void set_pose_cb( const geometry_msgs::PoseStampedConstPtr &msg );
00018 void markerUpdate ( std_msgs::Header header, geometry_msgs::Pose pose);
00019
00020 private:
00021 bool use_dynamic_tf_, move_2d_;
00022 ros::ServiceClient dynamic_tf_publisher_client_;
00023 ros::Subscriber sub_set_pose_;
00024 boost::shared_ptr<interactive_markers::InteractiveMarkerServer> server_;
00025 ros::NodeHandle nh_, pnh_;
00026 ros::Publisher pub_pose_;
00027 std::string frame_id_, marker_frame_id_;
00028 };
00029
00030 UrdfControlMarker::UrdfControlMarker() : nh_(), pnh_("~"){
00031 server_.reset( new interactive_markers::InteractiveMarkerServer("urdf_control_marker","",false) );
00032
00033 pnh_.param("move_2d", move_2d_, false);
00034 pnh_.getParam("use_dynamic_tf", use_dynamic_tf_);
00035 pnh_.param<std::string>("frame_id", frame_id_, "/map");
00036 pnh_.param<std::string>("marker_frame_id", marker_frame_id_, "/urdf_control_marker");
00037 if (use_dynamic_tf_) {
00038 ros::service::waitForService("set_dynamic_tf", -1);
00039 dynamic_tf_publisher_client_ = nh_.serviceClient<dynamic_tf_publisher::SetDynamicTF>("set_dynamic_tf", true);
00040 }
00041 pub_pose_ = pnh_.advertise<geometry_msgs::PoseStamped>("pose", 1);
00042 sub_set_pose_ = pnh_.subscribe<geometry_msgs::PoseStamped> ("set_pose", 1, boost::bind( &UrdfControlMarker::set_pose_cb, this, _1));
00043
00044
00045 makeControlMarker( false );
00046 server_->applyChanges();
00047 ros::spin();
00048 server_.reset();
00049 }
00050
00051 void UrdfControlMarker::set_pose_cb ( const geometry_msgs::PoseStampedConstPtr &msg){
00052 server_->setPose("urdf_control_marker", msg->pose, msg->header);
00053 server_->applyChanges();
00054 markerUpdate( msg->header, msg->pose);
00055 }
00056
00057
00058 void UrdfControlMarker::processFeedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
00059 {
00060 markerUpdate( feedback->header, feedback->pose);
00061 }
00062
00063 void UrdfControlMarker::markerUpdate ( std_msgs::Header header, geometry_msgs::Pose pose){
00064 dynamic_tf_publisher::SetDynamicTF SetTf;
00065 SetTf.request.freq = 20;
00066 SetTf.request.cur_tf.header = header;
00067 SetTf.request.cur_tf.child_frame_id = marker_frame_id_;
00068 geometry_msgs::Transform transform;
00069 transform.translation.x = pose.position.x;
00070 transform.translation.y = pose.position.y;
00071 transform.translation.z = pose.position.z;
00072 transform.rotation = pose.orientation;
00073
00074 SetTf.request.cur_tf.transform = transform;
00075 if (use_dynamic_tf_){
00076 dynamic_tf_publisher_client_.call(SetTf);
00077 }
00078
00079 geometry_msgs::PoseStamped ps;
00080 ps.header = header;
00081 ps.pose = pose;
00082 pub_pose_.publish(ps);
00083
00084 server_->applyChanges();
00085 }
00086
00087
00088
00089
00090 void UrdfControlMarker::makeControlMarker( bool fixed )
00091 {
00092 InteractiveMarker int_marker;
00093 int_marker.header.frame_id = frame_id_;
00094 int_marker.scale = 1;
00095
00096 int_marker.name = "urdf_control_marker";
00097
00098 InteractiveMarkerControl control;
00099
00100 if ( fixed )
00101 {
00102 int_marker.name += "_fixed";
00103 control.orientation_mode = InteractiveMarkerControl::FIXED;
00104 }
00105 control.always_visible = true;
00106
00107 control.orientation.w = 1;
00108 control.orientation.x = 1;
00109 control.orientation.y = 0;
00110 control.orientation.z = 0;
00111 control.name = "rotate_x";
00112 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
00113 if(!move_2d_){
00114 int_marker.controls.push_back(control);
00115 }
00116 control.name = "move_x";
00117 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
00118 int_marker.controls.push_back(control);
00119
00120 control.orientation.w = 1;
00121 control.orientation.x = 0;
00122 control.orientation.y = 1;
00123 control.orientation.z = 0;
00124 control.name = "rotate_z";
00125 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
00126 int_marker.controls.push_back(control);
00127 control.name = "move_z";
00128 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
00129 if(!move_2d_){
00130 int_marker.controls.push_back(control);
00131 }
00132
00133 control.orientation.w = 1;
00134 control.orientation.x = 0;
00135 control.orientation.y = 0;
00136 control.orientation.z = 1;
00137 control.name = "rotate_y";
00138 control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
00139 if(!move_2d_){
00140 int_marker.controls.push_back(control);
00141 }
00142 control.name = "move_y";
00143 control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
00144 int_marker.controls.push_back(control);
00145
00146 server_->insert(int_marker);
00147 server_->setCallback(int_marker.name, boost::bind( &UrdfControlMarker::processFeedback, this, _1));
00148 }
00149
00150 int main(int argc, char** argv)
00151 {
00152 ros::init(argc, argv, "basic_controls");
00153 UrdfControlMarker ucm;
00154 }