Ask Your Question

How to display a marker sequence in ros3djs when each are defined in the base_link frame?

asked 2021-04-20 03:22:21 -0500

Py gravatar image

updated 2021-04-20 04:45:58 -0500

I publish markers at the origin of the robot base_link frame regularly. In RViz, a marker is therefore plotted wherever the robot is located at the time it is created, building up a sequence of markers along the robots trajectory. I achieve this by setting frame_locked = False in the marker definition. Performance is really good with no lag observed and all of these markers persist on screen for visualisation (due to frame_locked = False) as shown in the screenshot below.

image description

I am trying to implement this same visualisation in a web browser using ros3djs with the following code but it does not appear to recognise the frame_locked = False marker option.

<!DOCTYPE html>
    <meta charset="utf-8" />

    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>

    <script type="text/javascript" type="text/javascript">
         * Setup all visualization elements when the page is loaded.
        function init() {
            // Connect to ROS.
            var ros = new ROSLIB.Ros({
                url : 'ws://localhost:9090'

            // Create the main viewer.
            var viewer = new ROS3D.Viewer({
                divID : 'markers',
                width : 800,
                height : 600,
                antialias : true

            // Setup a client to listen to TFs.
            var tfClient = new ROSLIB.TFClient({
                ros : ros,
                angularThres : 0.01,
                transThres : 0.01,
                rate : 10.0,
                fixedFrame : '/map'

            // Setup the marker client.
            var markerClient = new ROS3D.MarkerClient({
                ros : ros,
                tfClient : tfClient,
                topic : '/my_marker',
                rootObject : viewer.scene


<body onload="init()">
<h1>Simple Marker Example</h1>
<div id="markers"></div>

The problem with this code is that it displays each marker wherever the base_link is positioned in the map frame but does not leave the same sequence of markers for visualisation as my RViz example does.

Maybe this is expected because each marker has the same pose with respect to the base_link frame, which moves with the robot as it is operates. Does this suggest that RViz is somehow able to relate/transform these marker poses in the base_link frame to the map frame? If so, how might I properly set this up in the above code? Or maybe there is a simpler ros3djs setting I can use to make the markers persist on screen and respect the frame_locked = False option?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-04-20 08:58:15 -0500

miura gravatar image

updated 2021-04-20 11:03:09 -0500

If you change the id of the visualization_msgs/Marker, it might work. referring to the MakerClient code, it seems to erase markers with the same ns and id in the callback.


Perhaps your hypothesis is correct. The base_link is changing, so the marker is probably being recorded in the same place all the time. I have thought of a way to deal with this.


  1. change frame_id to map from base_link
  2. use tf2 to calculate the difference (geometry_msgs/TransformStamped) between map and base_link( ref: )
  3. Set the difference calculated above to Marker's pose. (Set the translation of TransformStamped to the position of the pose, and set the rotation of TransformStamped to the orientation of the pose.)
  4. Set frame_locked back to true
edit flag offensive delete link more


Each marker has a common namespace currently and I'm assigning an ID to each marker using the approach in the code snippet below. It looks like this works when I echo the marker topic. However, in RViz, I do get a warning saying Adding marker '/X' multiple times for each marker ID. Does all this suggest that I'm not assigning IDs correctly?

counter = marker_counter + 1 = marker_counter

Here's an example of one of my markers:

  seq: 1807
    secs: 643
    nsecs: 836000000
  frame_id: "/base_link"
ns: "markers"
id: 1807
type: 1
action: 0
    x: 0.0
    y: 0.0
    z: 0.0
    x: 0.0
    y: 0.0
    z: 0.0
    w: 0.0
  x: 0.1
  y: 0.6
  z: 0.1
  r: 0.7551710605621338
  g: 0.0844290629029274
  b: 0.10511341691017151
  a: 1.0
  secs: 0
  nsecs:         0
frame_locked ...
Py gravatar image Py  ( 2021-04-20 09:44:18 -0500 )edit

If the echo is working, I don't think it's a problem, although I am curious about the rviz message.

Why don't you overwrite ROS3D.MarkerClient.prototype.processMessage before the init? If you paste the code linked above and add console.log(message.ns +; or something similar, it should show up in your browser's console. You can also try removing the this.removeMarker(message.ns +; line to see if my guess is correct.

miura gravatar image miura  ( 2021-04-20 10:05:55 -0500 )edit

Good idea! Console log results in lots of lines of markers216 increasing in number but with same namespace. Removing the removeMarker line does not seem to have an effect - I've also done a test to confirm that this is never being called. Are there any other modifications you can suggest or something else I can explore?

Py gravatar image Py  ( 2021-04-20 10:37:13 -0500 )edit

That works! Thanks! However this approach seems to have a lot of lag in it. Markers are published and displayed well at first but after a while markers are slow to publish and therefore become spaced at greater and greater distances apart. Any tips of solving this?

Py gravatar image Py  ( 2021-04-20 13:01:13 -0500 )edit

I'm glad it worked out.

It's strange that it gets slower and slower. It is difficult to know what action to take. First, you may want to check the publish interval from the header stamp.

In any case, I think the content has changed since the first question, so you might want to update the question or create another one.

miura gravatar image miura  ( 2021-04-21 07:19:56 -0500 )edit

Thanks for the comment. I've marked this question as answered and posted a new one here.

Py gravatar image Py  ( 2021-04-21 07:54:16 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-04-20 03:22:21 -0500

Seen: 236 times

Last updated: Apr 20 '21