Rosanswers logo

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="http://static.robotwebtools.org/threejs/current/three.min.js"></script>
    <script type="text/javascript" src="http://static.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
    <script type="text/javascript" src="http://static.robotwebtools.org/roslibjs/current/roslib.min.js"></script>
    <script type="text/javascript" src="http://static.robotwebtools.org/ros3djs/current/ros3d.min.js"></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?

Originally posted by Py on ROS Answers with karma: 501 on 2021-04-20

Post score: 0


1 Answer 1


Rosanswers logo

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: http://wiki.ros.org/tf2/Tutorials/Writing%20a%20tf2%20listener%20%28C%2B%2B%29 )
  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

Originally posted by miura with karma: 1908 on 2021-04-20

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by Py on 2021-04-20:
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.id = 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: False
points: []
colors: []
text: ''
mesh_resource: ''
mesh_use_embedded_materials: False

Comment by miura on 2021-04-20:
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 + message.id); or something similar, it should show up in your browser's console. You can also try removing the this.removeMarker(message.ns + message.id); line to see if my guess is correct.

Comment by Py on 2021-04-20:
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?

Comment by Py on 2021-04-20:
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?

Comment by miura on 2021-04-21:
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.

Comment by Py on 2021-04-21:
Thanks for the comment. I've marked this question as answered and posted a new one here.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.