00001 /* 00002 * Copyright (c) 2011, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 00031 // %Tag(fullSource)% 00032 #include <ros/ros.h> 00033 00034 #include <interactive_markers/interactive_marker_server.h> 00035 00036 void processFeedback( 00037 const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ) 00038 { 00039 ROS_INFO_STREAM( feedback->marker_name << " is now at " 00040 << feedback->pose.position.x << ", " << feedback->pose.position.y 00041 << ", " << feedback->pose.position.z ); 00042 } 00043 00044 int main(int argc, char** argv) 00045 { 00046 ros::init(argc, argv, "simple_marker"); 00047 00048 // create an interactive marker server on the topic namespace simple_marker 00049 interactive_markers::InteractiveMarkerServer server("simple_marker"); 00050 00051 // create an interactive marker for our server 00052 visualization_msgs::InteractiveMarker int_marker; 00053 int_marker.header.frame_id = "/base_link"; 00054 int_marker.name = "my_marker"; 00055 int_marker.description = "Simple 1-DOF Control"; 00056 00057 // create a grey box marker 00058 visualization_msgs::Marker box_marker; 00059 box_marker.type = visualization_msgs::Marker::CUBE; 00060 box_marker.scale.x = 0.45; 00061 box_marker.scale.y = 0.45; 00062 box_marker.scale.z = 0.45; 00063 box_marker.color.r = 0.5; 00064 box_marker.color.g = 0.5; 00065 box_marker.color.b = 0.5; 00066 box_marker.color.a = 1.0; 00067 00068 // create a non-interactive control which contains the box 00069 visualization_msgs::InteractiveMarkerControl box_control; 00070 box_control.always_visible = true; 00071 box_control.markers.push_back( box_marker ); 00072 00073 // add the control to the interactive marker 00074 int_marker.controls.push_back( box_control ); 00075 00076 // create a control which will move the box 00077 // this control does not contain any markers, 00078 // which will cause RViz to insert two arrows 00079 visualization_msgs::InteractiveMarkerControl rotate_control; 00080 rotate_control.name = "move_x"; 00081 rotate_control.interaction_mode = 00082 visualization_msgs::InteractiveMarkerControl::MOVE_AXIS; 00083 00084 // add the control to the interactive marker 00085 int_marker.controls.push_back(rotate_control); 00086 00087 // add the interactive marker to our collection & 00088 // tell the server to call processFeedback() when feedback arrives for it 00089 server.insert(int_marker, &processFeedback); 00090 00091 // 'commit' changes and send to all clients 00092 server.applyChanges(); 00093 00094 // start the ROS main loop 00095 ros::spin(); 00096 } 00097 // %Tag(fullSource)%