ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange

# Apply transform to visualization marker

I create a visualization marker with circle shape in this way:

from geometry_msgs.msg import Point, Quaternion
from visualization_msgs.msg import Marker

marker = Marker()
marker.type = Marker.LINE_STRIP

marker.pose.orientation = Quaternion(0,0,0,1)

marker.scale.x = 0.01

marker.color.g = 1.0
marker.color.a = 1.0

centre_x = x
centre_y = y

delta_th = 0.01
for th in numpy.arange(0.0, 2*math.pi+delta_th, delta_th):
x = centre_x + R * math.sin(th)
y = centre_y + R * math.cos(th)

point = Point()
point.x = x
point.y = y
marker.points.append(point)

marker.ns = "circle"


I would like to apply a transform operation like translation, rotation or scalation to this marker.

Is there an already developed way to do it? Or I would have to recalculate the marker.points with new parameters in the circle equation?

edit retag close merge delete

I thought about applying translation/rotation matrix to each point of marker.points array but I don't know how I could proceed with scale operation

( 2020-10-19 03:34:43 -0500 )edit

Sort by ยป oldest newest most voted

I assume your circle shape marker is working.
This solution creates a new coordinate frame called "marker1" and then assigns that coordinate frame to your custom marker. This will translate and rotate the center of the circle shape that you have defined.

In order to create a new coordinate frame use tf2.
A quick solution is to add a static transform publisher to your launch file. Set the translation/rotation arguments and frame names as required.

<launch>
<node pkg="tf2_ros" type="static_transform_publisher" name="marker_tf_broadcaster" args="5 0 0 0 0 0 1 map marker1" />
</launch>


In your python script assign the coordinate frame to the marker.
Set marker.header.frame_id = "marker1" or whatever frame name you've set via the static_transform_publisher above.

With respect to scale, it really depends on what you want to scale: if it is the line width, then just modify the marker.scale attribute in your existing script for scaling. If scaling means modifying the radius of your marker circle or the circle radius and the line width then you will have to write this part yourself.

If the tf2 translation/rotation approach works for you, you can also include a (dynamic) tf2 transform broadcaster directly into your script: