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

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>
<html>
<head>
    <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
            });

        }
    </script>
</head>

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

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
1

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.

https://github.com/RobotWebTools/ros3...

Update

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.

Idea

  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/Wri... )
  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

Comments

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:

header: 
  seq: 1807
  stamp: 
    secs: 643
    nsecs: 836000000
  frame_id: "/base_link"
ns: "markers"
id: 1807
type: 1
action: 0
pose: 
  position: 
    x: 0.0
    y: 0.0
    z: 0.0
  orientation: 
    x: 0.0
    y: 0.0
    z: 0.0
    w: 0.0
scale: 
  x: 0.1
  y: 0.6
  z: 0.1
color: 
  r: 0.7551710605621338
  g: 0.0844290629029274
  b: 0.10511341691017151
  a: 1.0
lifetime: 
  secs: 0
  nsecs:         0
frame_locked ...
(more)
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 + 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.

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

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
1

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
1

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

Question Tools

1 follower

Stats

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

Seen: 477 times

Last updated: Apr 20 '21