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


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