Skip to content

Commit fee637e

Browse files
author
David Gossow
committed
Merge pull request #7 from aleeper/move_rotate_3d
new layout and 3D controls in basic_controls
2 parents 6f5b74c + 0ecc25f commit fee637e

File tree

2 files changed

+210
-163
lines changed

2 files changed

+210
-163
lines changed

interactive_marker_tutorials/python/basic_controls.py

Lines changed: 119 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535

3636
from interactive_markers.interactive_marker_server import *
3737
from interactive_markers.menu_handler import *
38+
from geometry_msgs.msg import Point
3839
from tf.broadcaster import TransformBroadcaster
3940

4041
from random import random
4142
from math import sin
4243

4344
server = None
44-
marker_pos = 0
4545
menu_handler = MenuHandler()
4646
br = None
4747
counter = 0
@@ -131,98 +131,108 @@ def saveMarker( int_marker ):
131131
#####################################################################
132132
# Marker Creation
133133

134-
def make6DofMarker( fixed ):
135-
global marker_pos
134+
def make6DofMarker( fixed, interaction_mode, position, show_6dof = False):
136135
int_marker = InteractiveMarker()
137136
int_marker.header.frame_id = "/base_link"
138-
int_marker.pose.position.y = -3.0 * marker_pos
139-
marker_pos += 1
137+
int_marker.pose.position = position
140138
int_marker.scale = 1
141139

142140
int_marker.name = "simple_6dof"
143141
int_marker.description = "Simple 6-DOF Control"
144142

145143
# insert a box
146144
makeBoxControl(int_marker)
145+
int_marker.controls[0].interaction_mode = interaction_mode
147146

148147
if fixed:
149148
int_marker.name += "_fixed"
150149
int_marker.description += "\n(fixed orientation)"
151150

152-
control = InteractiveMarkerControl()
153-
control.orientation.w = 1
154-
control.orientation.x = 1
155-
control.orientation.y = 0
156-
control.orientation.z = 0
157-
control.name = "rotate_x"
158-
control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
159-
if fixed:
160-
control.orientation_mode = InteractiveMarkerControl.FIXED
161-
int_marker.controls.append(control)
151+
if interaction_mode != InteractiveMarkerControl.NONE:
152+
control_modes_dict = {
153+
InteractiveMarkerControl.MOVE_3D : "MOVE_3D",
154+
InteractiveMarkerControl.ROTATE_3D : "ROTATE_3D",
155+
InteractiveMarkerControl.MOVE_ROTATE_3D : "MOVE_ROTATE_3D" }
156+
int_marker.name += "_" + control_modes_dict[interaction_mode]
157+
int_marker.description = "3D Control"
158+
if show_6dof:
159+
int_marker.description += " + 6-DOF controls"
160+
int_marker.description += "\n" + control_modes_dict[interaction_mode]
161+
162+
if show_6dof:
163+
control = InteractiveMarkerControl()
164+
control.orientation.w = 1
165+
control.orientation.x = 1
166+
control.orientation.y = 0
167+
control.orientation.z = 0
168+
control.name = "rotate_x"
169+
control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
170+
if fixed:
171+
control.orientation_mode = InteractiveMarkerControl.FIXED
172+
int_marker.controls.append(control)
162173

163-
control = InteractiveMarkerControl()
164-
control.orientation.w = 1
165-
control.orientation.x = 1
166-
control.orientation.y = 0
167-
control.orientation.z = 0
168-
control.name = "move_x"
169-
control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
170-
if fixed:
171-
control.orientation_mode = InteractiveMarkerControl.FIXED
172-
int_marker.controls.append(control)
174+
control = InteractiveMarkerControl()
175+
control.orientation.w = 1
176+
control.orientation.x = 1
177+
control.orientation.y = 0
178+
control.orientation.z = 0
179+
control.name = "move_x"
180+
control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
181+
if fixed:
182+
control.orientation_mode = InteractiveMarkerControl.FIXED
183+
int_marker.controls.append(control)
173184

174-
control = InteractiveMarkerControl()
175-
control.orientation.w = 1
176-
control.orientation.x = 0
177-
control.orientation.y = 1
178-
control.orientation.z = 0
179-
control.name = "rotate_z"
180-
control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
181-
if fixed:
182-
control.orientation_mode = InteractiveMarkerControl.FIXED
183-
int_marker.controls.append(control)
185+
control = InteractiveMarkerControl()
186+
control.orientation.w = 1
187+
control.orientation.x = 0
188+
control.orientation.y = 1
189+
control.orientation.z = 0
190+
control.name = "rotate_z"
191+
control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
192+
if fixed:
193+
control.orientation_mode = InteractiveMarkerControl.FIXED
194+
int_marker.controls.append(control)
184195

185-
control = InteractiveMarkerControl()
186-
control.orientation.w = 1
187-
control.orientation.x = 0
188-
control.orientation.y = 1
189-
control.orientation.z = 0
190-
control.name = "move_z"
191-
control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
192-
if fixed:
193-
control.orientation_mode = InteractiveMarkerControl.FIXED
194-
int_marker.controls.append(control)
196+
control = InteractiveMarkerControl()
197+
control.orientation.w = 1
198+
control.orientation.x = 0
199+
control.orientation.y = 1
200+
control.orientation.z = 0
201+
control.name = "move_z"
202+
control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
203+
if fixed:
204+
control.orientation_mode = InteractiveMarkerControl.FIXED
205+
int_marker.controls.append(control)
195206

196-
control = InteractiveMarkerControl()
197-
control.orientation.w = 1
198-
control.orientation.x = 0
199-
control.orientation.y = 0
200-
control.orientation.z = 1
201-
control.name = "rotate_y"
202-
control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
203-
if fixed:
204-
control.orientation_mode = InteractiveMarkerControl.FIXED
205-
int_marker.controls.append(control)
207+
control = InteractiveMarkerControl()
208+
control.orientation.w = 1
209+
control.orientation.x = 0
210+
control.orientation.y = 0
211+
control.orientation.z = 1
212+
control.name = "rotate_y"
213+
control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
214+
if fixed:
215+
control.orientation_mode = InteractiveMarkerControl.FIXED
216+
int_marker.controls.append(control)
206217

207-
control = InteractiveMarkerControl()
208-
control.orientation.w = 1
209-
control.orientation.x = 0
210-
control.orientation.y = 0
211-
control.orientation.z = 1
212-
control.name = "move_y"
213-
control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
214-
if fixed:
215-
control.orientation_mode = InteractiveMarkerControl.FIXED
216-
int_marker.controls.append(control)
218+
control = InteractiveMarkerControl()
219+
control.orientation.w = 1
220+
control.orientation.x = 0
221+
control.orientation.y = 0
222+
control.orientation.z = 1
223+
control.name = "move_y"
224+
control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
225+
if fixed:
226+
control.orientation_mode = InteractiveMarkerControl.FIXED
227+
int_marker.controls.append(control)
217228

218229
server.insert(int_marker, processFeedback)
230+
menu_handler.apply( server, int_marker.name )
219231

220-
def makeRandomDofMarker():
221-
global marker_pos
232+
def makeRandomDofMarker( position ):
222233
int_marker = InteractiveMarker()
223234
int_marker.header.frame_id = "/base_link"
224-
int_marker.pose.position.y = -3.0 * marker_pos
225-
marker_pos += 1
235+
int_marker.pose.position = position
226236
int_marker.scale = 1
227237

228238
int_marker.name = "6dof_random_axes"
@@ -240,16 +250,14 @@ def makeRandomDofMarker():
240250
control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
241251
int_marker.controls.append(copy.deepcopy(control))
242252
control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
243-
int_marker.controls.append(control)
253+
int_marker.controls.append(copy.deepcopy(control))
244254

245255
server.insert(int_marker, processFeedback)
246256

247-
def makeViewFacingMarker():
248-
global marker_pos
257+
def makeViewFacingMarker(position):
249258
int_marker = InteractiveMarker()
250259
int_marker.header.frame_id = "/base_link"
251-
int_marker.pose.position.y = -3.0 * marker_pos
252-
marker_pos += 1
260+
int_marker.pose.position = position
253261
int_marker.scale = 1
254262

255263
int_marker.name = "view_facing"
@@ -276,12 +284,10 @@ def makeViewFacingMarker():
276284

277285
server.insert(int_marker, processFeedback)
278286

279-
def makeQuadrocopterMarker():
280-
global marker_pos
287+
def makeQuadrocopterMarker(position):
281288
int_marker = InteractiveMarker()
282289
int_marker.header.frame_id = "/base_link"
283-
int_marker.pose.position.y = -3.0 * marker_pos
284-
marker_pos += 1
290+
int_marker.pose.position = position
285291
int_marker.scale = 1
286292

287293
int_marker.name = "quadrocopter"
@@ -301,12 +307,10 @@ def makeQuadrocopterMarker():
301307

302308
server.insert(int_marker, processFeedback)
303309

304-
def makeChessPieceMarker():
305-
global marker_pos
310+
def makeChessPieceMarker(position):
306311
int_marker = InteractiveMarker()
307312
int_marker.header.frame_id = "/base_link"
308-
int_marker.pose.position.y = -3.0 * marker_pos
309-
marker_pos += 1
313+
int_marker.pose.position = position
310314
int_marker.scale = 1
311315

312316
int_marker.name = "chess_piece"
@@ -331,12 +335,10 @@ def makeChessPieceMarker():
331335
# set different callback for POSE_UPDATE feedback
332336
server.setCallback(int_marker.name, alignMarker, InteractiveMarkerFeedback.POSE_UPDATE )
333337

334-
def makePanTiltMarker():
335-
global marker_pos
338+
def makePanTiltMarker(position):
336339
int_marker = InteractiveMarker()
337340
int_marker.header.frame_id = "/base_link"
338-
int_marker.pose.position.y = -3.0 * marker_pos
339-
marker_pos += 1
341+
int_marker.pose.position = position
340342
int_marker.scale = 1
341343

342344
int_marker.name = "pan_tilt"
@@ -364,12 +366,10 @@ def makePanTiltMarker():
364366

365367
server.insert(int_marker, processFeedback)
366368

367-
def makeMenuMarker():
368-
global marker_pos
369+
def makeMenuMarker(position):
369370
int_marker = InteractiveMarker()
370371
int_marker.header.frame_id = "/base_link"
371-
int_marker.pose.position.y = -3.0 * marker_pos
372-
marker_pos += 1
372+
int_marker.pose.position = position
373373
int_marker.scale = 1
374374

375375
int_marker.name = "context_menu"
@@ -391,12 +391,10 @@ def makeMenuMarker():
391391
server.insert(int_marker, processFeedback)
392392
menu_handler.apply( server, int_marker.name )
393393

394-
def makeMovingMarker():
395-
global marker_pos
394+
def makeMovingMarker(position):
396395
int_marker = InteractiveMarker()
397396
int_marker.header.frame_id = "/moving_frame"
398-
int_marker.pose.position.y = -3.0 * marker_pos
399-
marker_pos += 1
397+
int_marker.pose.position = position
400398
int_marker.scale = 1
401399

402400
int_marker.name = "moving"
@@ -432,16 +430,33 @@ def makeMovingMarker():
432430
sub_menu_handle = menu_handler.insert( "Submenu" )
433431
menu_handler.insert( "First Entry", parent=sub_menu_handle, callback=processFeedback )
434432
menu_handler.insert( "Second Entry", parent=sub_menu_handle, callback=processFeedback )
435-
436-
make6DofMarker( False )
437-
make6DofMarker( True )
438-
makeRandomDofMarker( )
439-
makeViewFacingMarker( )
440-
makeQuadrocopterMarker( )
441-
makeChessPieceMarker( )
442-
makePanTiltMarker( )
443-
makeMenuMarker( )
444-
makeMovingMarker( )
433+
434+
435+
position = Point(-3, 3, 0)
436+
make6DofMarker( False, InteractiveMarkerControl.NONE, position, True)
437+
position = Point( 0, 3, 0)
438+
make6DofMarker( True, InteractiveMarkerControl.NONE, position, True)
439+
position = Point( 3, 3, 0)
440+
makeRandomDofMarker( position )
441+
position = Point(-3, 0, 0)
442+
make6DofMarker( False, InteractiveMarkerControl.ROTATE_3D, position, False)
443+
position = Point( 0, 0, 0)
444+
make6DofMarker( False, InteractiveMarkerControl.MOVE_ROTATE_3D, position, True )
445+
position = Point( 3, 0, 0)
446+
make6DofMarker( False, InteractiveMarkerControl.MOVE_3D, position, False)
447+
position = Point(-3, -3, 0)
448+
makeViewFacingMarker( position )
449+
position = Point( 0, -3, 0)
450+
makeQuadrocopterMarker( position )
451+
position = Point( 3, -3, 0)
452+
makeChessPieceMarker( position )
453+
position = Point(-3, -6, 0)
454+
makePanTiltMarker( position )
455+
position = Point( 0, -6, 0)
456+
makeMovingMarker( position )
457+
position = Point( 3, -6, 0)
458+
makeMenuMarker( position )
459+
445460

446461
server.applyChanges()
447462

0 commit comments

Comments
 (0)