On ros3djs, how can I stop markers dispearing?

asked 2021-03-24 10:58:55 -0600

Py gravatar image

updated 2021-03-24 10:59:41 -0600

I publish markers onto a web GUI using the code below. I'd like all markers to remain on the viewer but it seems that my code only displays the latest marker rather than the latest marker as well as all markers that have been published before it. Note that the markers are defined with the default lifetime parameter of 0 meaning that they should exist forever (this works well when viewing on RViz) even though they disappear when viewing the on a web browser using the code below.

Any ideas how to make the markers persist?

new Vue({
    el: '#vueApp',

    data: {
        ros: null,
        connected: false,
        pubInterval: null
    },

    methods: {

        init: function () {

            // ROSBridge Connection Object
            this.ros = new ROSLIB.Ros({
                url: 'ws://' + window.location.hostname + ':9090'
            })

            // ROSBridge Connection Object Callbacks
            this.ros.on('connection', () => {
                this.connected = true
                console.log('Connection to ROSBridge established')
                this.pubInterval = setInterval(this.publish, 100)
            })
            this.ros.on('error', (error) => {
                console.log('Something went wrong when trying to connect')
                console.log(error)
            })
            this.ros.on('close', () => {
                this.connected = false
                console.log('Connection to ROSBridge was closed')
                clearInterval(this.pubInterval)
            })

            // Visualisation
            let viewer = new ROS3D.Viewer({
                divID : 'map',
                width : 600,
                height : 400,
                antialias : true,
            });

            // TF Client
            let tfClient = new ROSLIB.TFClient({
                ros : this.ros,
                angularThres : 0.01,
                transThres : 0.01,
                rate : 10.0,
                fixedFrame : '/map'
            });

            // Marker Data Acquisition
            let markerClient = new ROS3D.MarkerClient({
                ros : this.ros,
                tfClient : tfClient,
                topic : '/visualization_marker',
                rootObject : viewer.scene
            });

        }
    }
})
edit retag flag offensive close merge delete

Comments

1

I think the problem is that marker client is exclusive to only one marker.. If you want several markers you should do more than one markerclient or a MarkerArrayClient.

I do no0t know why, but i think a good good idea for your case should be to create a topic which send info when a new marker is created (backend) and then, put a subscriber in your js code. Inside a subscriver, generate a new marker client.

Dunno, worked on that few years ago so I am not quite sure which should be the optimal way to work on it.

Solrac3589 gravatar image Solrac3589  ( 2021-03-26 07:02:18 -0600 )edit

I've not got this to work but are you suggesting a function like this:

getMarker: function (){
    let visualization_marker_topic = new ROSLIB.Topic({
        ros: this.ros,
        name: '/visualization_marker',
        messageType: 'visualization_msgs/Marker'
    })
    visualization_marker_topic.subscribe((message) => {
        let markerClient = new ROS3D.MarkerClient({
            ros : this.ros,
            tfClient : tfClient,
            topic : '/visualization_marker',
            rootObject : viewer.scene
        });
    })
}
Py gravatar image Py  ( 2021-03-29 05:41:39 -0600 )edit

Anyone got any more ideas on this? I've posted this question to provide more info and try to get to the bottom of this.

Py gravatar image Py  ( 2021-04-20 03:44:53 -0600 )edit

I just made some adjustments and got the above code snippet to work so that whenever a new marker message is received a new marker client is created to visualise it. This produces the same results and does not solve the initial problem, i.e. needing to visualise the sequence of markers. Also, it seems that using the MarkerArrayClient also does not work given that all markers are the same pose in relation to the base_link frame. See here for more info.

Py gravatar image Py  ( 2021-04-20 04:19:02 -0600 )edit