simple_marker.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 
31 // %Tag(fullSource)%
32 #include <ros/ros.h>
33 
35 
37  const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
38 {
39  ROS_INFO_STREAM( feedback->marker_name << " is now at "
40  << feedback->pose.position.x << ", " << feedback->pose.position.y
41  << ", " << feedback->pose.position.z );
42 }
43 
44 int main(int argc, char** argv)
45 {
46  ros::init(argc, argv, "simple_marker");
47 
48  // create an interactive marker server on the topic namespace simple_marker
50 
51  // create an interactive marker for our server
52  visualization_msgs::InteractiveMarker int_marker;
53  int_marker.header.frame_id = "base_link";
54  int_marker.header.stamp=ros::Time::now();
55  int_marker.name = "my_marker";
56  int_marker.description = "Simple 1-DOF Control";
57 
58  // create a grey box marker
59  visualization_msgs::Marker box_marker;
60  box_marker.type = visualization_msgs::Marker::CUBE;
61  box_marker.scale.x = 0.45;
62  box_marker.scale.y = 0.45;
63  box_marker.scale.z = 0.45;
64  box_marker.color.r = 0.5;
65  box_marker.color.g = 0.5;
66  box_marker.color.b = 0.5;
67  box_marker.color.a = 1.0;
68 
69  // create a non-interactive control which contains the box
70  visualization_msgs::InteractiveMarkerControl box_control;
71  box_control.always_visible = true;
72  box_control.markers.push_back( box_marker );
73 
74  // add the control to the interactive marker
75  int_marker.controls.push_back( box_control );
76 
77  // create a control which will move the box
78  // this control does not contain any markers,
79  // which will cause RViz to insert two arrows
80  visualization_msgs::InteractiveMarkerControl rotate_control;
81  rotate_control.name = "move_x";
82  rotate_control.interaction_mode =
83  visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
84 
85  // add the control to the interactive marker
86  int_marker.controls.push_back(rotate_control);
87 
88  // add the interactive marker to our collection &
89  // tell the server to call processFeedback() when feedback arrives for it
90  server.insert(int_marker, &processFeedback);
91 
92  // 'commit' changes and send to all clients
93  server.applyChanges();
94 
95  // start the ROS main loop
96  ros::spin();
97 }
98 // %Tag(fullSource)%
void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
int main(int argc, char **argv)
INTERACTIVE_MARKERS_PUBLIC void insert(const visualization_msgs::InteractiveMarker &int_marker)
#define ROS_INFO_STREAM(args)
INTERACTIVE_MARKERS_PUBLIC void applyChanges()
static Time now()


interactive_marker_tutorials
Author(s): David Gossow
autogenerated on Sat May 16 2020 03:49:16