simple_marker.cpp
Go to the documentation of this file.
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.header.stamp=ros::Time::now();
00055   int_marker.name = "my_marker";
00056   int_marker.description = "Simple 1-DOF Control";
00057 
00058   // create a grey box marker
00059   visualization_msgs::Marker box_marker;
00060   box_marker.type = visualization_msgs::Marker::CUBE;
00061   box_marker.scale.x = 0.45;
00062   box_marker.scale.y = 0.45;
00063   box_marker.scale.z = 0.45;
00064   box_marker.color.r = 0.5;
00065   box_marker.color.g = 0.5;
00066   box_marker.color.b = 0.5;
00067   box_marker.color.a = 1.0;
00068 
00069   // create a non-interactive control which contains the box
00070   visualization_msgs::InteractiveMarkerControl box_control;
00071   box_control.always_visible = true;
00072   box_control.markers.push_back( box_marker );
00073 
00074   // add the control to the interactive marker
00075   int_marker.controls.push_back( box_control );
00076 
00077   // create a control which will move the box
00078   // this control does not contain any markers,
00079   // which will cause RViz to insert two arrows
00080   visualization_msgs::InteractiveMarkerControl rotate_control;
00081   rotate_control.name = "move_x";
00082   rotate_control.interaction_mode =
00083       visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00084 
00085   // add the control to the interactive marker
00086   int_marker.controls.push_back(rotate_control);
00087 
00088   // add the interactive marker to our collection &
00089   // tell the server to call processFeedback() when feedback arrives for it
00090   server.insert(int_marker, &processFeedback);
00091 
00092   // 'commit' changes and send to all clients
00093   server.applyChanges();
00094 
00095   // start the ROS main loop
00096   ros::spin();
00097 }
00098 // %Tag(fullSource)%


interactive_marker_tutorials
Author(s): David Gossow
autogenerated on Thu Jun 6 2019 17:45:02