Understanding InteractiveMarkers
I have followed the interactive markers tutorial, and I successfully achieved want I wanted: to mix the quadrocopter and button markers. However, I do not understand how the code works. To define the marker, I have the following code:
def makeMarker():
marker = Marker()
marker.type = Marker.CYLINDER
marker.scale.x = 0.3
marker.scale.y = 0.3
marker.scale.z = 0.3
marker.color.g = 1.0
marker.color.a = 1.0
return marker
# create an interactive marker for our server
int_marker = InteractiveMarker()
int_marker.header.frame_id = "world"
int_marker.name = "goal_marker"
int_marker.description = "goal_marker"
int_marker.scale = 0.7
# create marker and a non-interactive control containing the marker
control = InteractiveMarkerControl()
control.always_visible = True
control.markers.append(makeMarker())
# add control to interactive marker
int_marker.controls.append(control)
# add control for position (as it has no marker, RViz decides which one to use).
control = InteractiveMarkerControl()
control.orientation.w = 1
control.orientation.x = 0
control.orientation.y = 1
control.orientation.z = 0
control.interaction_mode = InteractiveMarkerControl.MOVE_PLANE
int_marker.controls.append(copy.deepcopy(control))
# add control for the height (as it has no marker, RViz decides which one to use).
control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
int_marker.controls.append(copy.deepcopy(control))
# add control for pose publishing.
control.interaction_mode = InteractiveMarkerControl.BUTTON
control.markers.append(makeMarker())
int_marker.controls.append(control)
First, the interactive marker is created (int_marker
), and then a Control is associated to maker created by makeMarker
and this Control is inserted in int_marker
. Then, two more controls are created to give the plannar movement and height, and inserted to int_marker
. So far so good.
However, when adding the button functionality, I have to include the extra line control.markers.append(makeMarker())
, that is, to create a new visual marker and append it to the Control. Why do I need this? I will not work otherwise.
FINAL SOLUTION: Removing extra appends and thus other extra code:
# create an interactive marker for our server
int_marker = InteractiveMarker()
int_marker.header.frame_id = "world"
int_marker.name = "int_marker"
int_marker.description = "int_marker"
int_marker.scale = 0.7
# add control for position (as it has no marker, RViz decides which one to use).
control = InteractiveMarkerControl()
control.orientation.w = 1
control.orientation.x = 0
control.orientation.y = 1
control.orientation.z = 0
control.interaction_mode = InteractiveMarkerControl.MOVE_PLANE
int_marker.controls.append(copy.deepcopy(control))
# add control for the height (as it has no marker, RViz decides which one to use).
control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
int_marker.controls.append(copy.deepcopy(control))
# add control for pose publishing. A marker is required in this case, RViz does not
# assign one.
control.interaction_mode = InteractiveMarkerControl.BUTTON
control.markers.append(makeMarker()) # This is required, it will not work otherwise.
int_marker.controls.append(control)