Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <interactive_markers/interactive_marker_server.h>
00003 #include <interactive_markers/tools.h>
00004 #include <interactive_markers/menu_handler.h>
00005
00006 #include <geometry_msgs/PoseStamped.h>
00007
00008 class Marker6DOF {
00009 public:
00010 Marker6DOF() {
00011 ros::NodeHandle nh, pnh("~");
00012 pnh.param("frame_id", frame_id_, std::string("/map"));
00013 pose_pub_ = pnh.advertise<geometry_msgs::PoseStamped>("pose", 1);
00014 pose_stamped_sub_ = pnh.subscribe("move_marker", 1, &Marker6DOF::moveMarkerCB, this);
00015
00016
00017 server_.reset( new interactive_markers::InteractiveMarkerServer(ros::this_node::getName()));
00018 initializeInteractiveMarker();
00019 }
00020 virtual ~Marker6DOF() {};
00021
00022 protected:
00023 void moveMarkerCB(const geometry_msgs::PoseStamped::ConstPtr& msg) {
00024 pose_pub_.publish(msg);
00025 server_->setPose("marker", msg->pose, msg->header);
00026 server_->applyChanges();
00027 }
00028
00029 void initializeInteractiveMarker() {
00030 visualization_msgs::InteractiveMarker int_marker;
00031 int_marker.header.frame_id = frame_id_;
00032 int_marker.name = "marker";
00033 int_marker.pose.orientation.w = 1.0;
00034
00035 visualization_msgs::Marker sphere_marker;
00036 sphere_marker.type = visualization_msgs::Marker::SPHERE;
00037 sphere_marker.scale.x = 0.1;
00038 sphere_marker.scale.y = 0.1;
00039 sphere_marker.scale.z = 0.1;
00040 sphere_marker.color.r = 0.0;
00041 sphere_marker.color.g = 1.0;
00042 sphere_marker.color.b = 0.0;
00043 sphere_marker.color.a = 1.0;
00044 sphere_marker.pose.orientation.w = 1.0;
00045
00046 visualization_msgs::InteractiveMarkerControl sphere_marker_control;
00047 sphere_marker_control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00048 sphere_marker_control.always_visible = true;
00049 sphere_marker_control.markers.push_back(sphere_marker);
00050 int_marker.controls.push_back(sphere_marker_control);
00051
00052 visualization_msgs::InteractiveMarkerControl control;
00053
00054 control.orientation.w = 1;
00055 control.orientation.x = 1;
00056 control.orientation.y = 0;
00057 control.orientation.z = 0;
00058 control.name = "rotate_x";
00059 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00060 int_marker.controls.push_back(control);
00061 control.name = "move_x";
00062 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00063 int_marker.controls.push_back(control);
00064
00065 control.orientation.w = 1;
00066 control.orientation.x = 0;
00067 control.orientation.y = 1;
00068 control.orientation.z = 0;
00069 control.name = "rotate_z";
00070 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00071 int_marker.controls.push_back(control);
00072 control.name = "move_z";
00073 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00074 int_marker.controls.push_back(control);
00075
00076 control.orientation.w = 1;
00077 control.orientation.x = 0;
00078 control.orientation.y = 0;
00079 control.orientation.z = 1;
00080 control.name = "rotate_y";
00081 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00082 int_marker.controls.push_back(control);
00083 control.name = "move_y";
00084 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00085 int_marker.controls.push_back(control);
00086
00087 server_->insert(int_marker,
00088 boost::bind(&Marker6DOF::processFeedbackCB, this, _1));
00089 server_->applyChanges();
00090 }
00091
00092 void processFeedbackCB(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback) {
00093 geometry_msgs::PoseStamped pose;
00094 pose.header = feedback->header;
00095 pose.pose = feedback->pose;
00096 pose_pub_.publish(pose);
00097 }
00098
00099 boost::shared_ptr<interactive_markers::InteractiveMarkerServer> server_;
00100 ros::Subscriber pose_stamped_sub_;
00101 ros::Publisher pose_pub_;
00102 std::string frame_id_;
00103 };
00104
00105
00106 int main(int argc, char** argv) {
00107 ros::init(argc, argv, "marker_6dof");
00108 Marker6DOF marker;
00109 ros::spin();
00110 return 0;
00111 }