35
35
36
36
from interactive_markers .interactive_marker_server import *
37
37
from interactive_markers .menu_handler import *
38
+ from geometry_msgs .msg import Point
38
39
from tf .broadcaster import TransformBroadcaster
39
40
40
41
from random import random
41
42
from math import sin
42
43
43
44
server = None
44
- marker_pos = 0
45
45
menu_handler = MenuHandler ()
46
46
br = None
47
47
counter = 0
@@ -131,98 +131,108 @@ def saveMarker( int_marker ):
131
131
#####################################################################
132
132
# Marker Creation
133
133
134
- def make6DofMarker ( fixed ):
135
- global marker_pos
134
+ def make6DofMarker ( fixed , interaction_mode , position , show_6dof = False ):
136
135
int_marker = InteractiveMarker ()
137
136
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
140
138
int_marker .scale = 1
141
139
142
140
int_marker .name = "simple_6dof"
143
141
int_marker .description = "Simple 6-DOF Control"
144
142
145
143
# insert a box
146
144
makeBoxControl (int_marker )
145
+ int_marker .controls [0 ].interaction_mode = interaction_mode
147
146
148
147
if fixed :
149
148
int_marker .name += "_fixed"
150
149
int_marker .description += "\n (fixed orientation)"
151
150
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 )
162
173
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 )
173
184
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 )
184
195
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 )
195
206
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 )
206
217
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 )
217
228
218
229
server .insert (int_marker , processFeedback )
230
+ menu_handler .apply ( server , int_marker .name )
219
231
220
- def makeRandomDofMarker ():
221
- global marker_pos
232
+ def makeRandomDofMarker ( position ):
222
233
int_marker = InteractiveMarker ()
223
234
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
226
236
int_marker .scale = 1
227
237
228
238
int_marker .name = "6dof_random_axes"
@@ -240,16 +250,14 @@ def makeRandomDofMarker():
240
250
control .interaction_mode = InteractiveMarkerControl .ROTATE_AXIS
241
251
int_marker .controls .append (copy .deepcopy (control ))
242
252
control .interaction_mode = InteractiveMarkerControl .MOVE_AXIS
243
- int_marker .controls .append (control )
253
+ int_marker .controls .append (copy . deepcopy ( control ) )
244
254
245
255
server .insert (int_marker , processFeedback )
246
256
247
- def makeViewFacingMarker ():
248
- global marker_pos
257
+ def makeViewFacingMarker (position ):
249
258
int_marker = InteractiveMarker ()
250
259
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
253
261
int_marker .scale = 1
254
262
255
263
int_marker .name = "view_facing"
@@ -276,12 +284,10 @@ def makeViewFacingMarker():
276
284
277
285
server .insert (int_marker , processFeedback )
278
286
279
- def makeQuadrocopterMarker ():
280
- global marker_pos
287
+ def makeQuadrocopterMarker (position ):
281
288
int_marker = InteractiveMarker ()
282
289
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
285
291
int_marker .scale = 1
286
292
287
293
int_marker .name = "quadrocopter"
@@ -301,12 +307,10 @@ def makeQuadrocopterMarker():
301
307
302
308
server .insert (int_marker , processFeedback )
303
309
304
- def makeChessPieceMarker ():
305
- global marker_pos
310
+ def makeChessPieceMarker (position ):
306
311
int_marker = InteractiveMarker ()
307
312
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
310
314
int_marker .scale = 1
311
315
312
316
int_marker .name = "chess_piece"
@@ -331,12 +335,10 @@ def makeChessPieceMarker():
331
335
# set different callback for POSE_UPDATE feedback
332
336
server .setCallback (int_marker .name , alignMarker , InteractiveMarkerFeedback .POSE_UPDATE )
333
337
334
- def makePanTiltMarker ():
335
- global marker_pos
338
+ def makePanTiltMarker (position ):
336
339
int_marker = InteractiveMarker ()
337
340
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
340
342
int_marker .scale = 1
341
343
342
344
int_marker .name = "pan_tilt"
@@ -364,12 +366,10 @@ def makePanTiltMarker():
364
366
365
367
server .insert (int_marker , processFeedback )
366
368
367
- def makeMenuMarker ():
368
- global marker_pos
369
+ def makeMenuMarker (position ):
369
370
int_marker = InteractiveMarker ()
370
371
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
373
373
int_marker .scale = 1
374
374
375
375
int_marker .name = "context_menu"
@@ -391,12 +391,10 @@ def makeMenuMarker():
391
391
server .insert (int_marker , processFeedback )
392
392
menu_handler .apply ( server , int_marker .name )
393
393
394
- def makeMovingMarker ():
395
- global marker_pos
394
+ def makeMovingMarker (position ):
396
395
int_marker = InteractiveMarker ()
397
396
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
400
398
int_marker .scale = 1
401
399
402
400
int_marker .name = "moving"
@@ -432,16 +430,33 @@ def makeMovingMarker():
432
430
sub_menu_handle = menu_handler .insert ( "Submenu" )
433
431
menu_handler .insert ( "First Entry" , parent = sub_menu_handle , callback = processFeedback )
434
432
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
+
445
460
446
461
server .applyChanges ()
447
462
0 commit comments