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

Apply transform to visualization marker

asked 2020-10-19 01:33:56 -0500

rluque gravatar image

updated 2020-10-19 01:39:13 -0500

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.action = Marker.ADD

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
R = radius

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"
marker.header.frame_id = "P"

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 flag offensive close merge delete

Comments

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

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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-10-19 05:04:52 -0500

Roberto Z. gravatar image

updated 2020-10-19 05:31:27 -0500

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:
Writing a tf2 broadcaster (Python)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2020-10-19 01:33:56 -0500

Seen: 894 times

Last updated: Oct 19 '20