RobotWebTools / roslibjs

The Standard ROS JavaScript Library
https://robotwebtools.github.io/roslibjs
Other
678 stars 378 forks source link

Question about TfClient #558

Closed roddc closed 1 year ago

roddc commented 2 years ago

Description I am using a TfClient to subscribe to tf2_web_republisher to get the transform feedback. However, the subscribe callback never called if I subscribe to the TF outside the topic.subscribe callback. If I subscribe to the TF inside a topic.subscribe, I can get the feedback. Does it mean I have to subscribe to the TF inside the topic subscribe callback?

Steps To Reproduce

    const ros = new Ros({
        url: "ws://localhost:9090",
    });

   const reset = new ROSLIB.Topic({
        ros,
        name: "/reset_time",
        messageType: "std_msgs/String",
    });
    const msg = new ROSLIB.Message({ data: "" });
   // clear old TF data
    reset.publish(msg);

   const tfClient = new ROSLIB.TFClient({
          ros,
          fixedFrame: "base_link",
          angularThres: 0.01,
          transThres: 0.01,
           rate: 10.0,
   });

  const topic = new Topic({
        ros: ros,
        name: "/map",
        messageType: "nav_msgs/OccupancyGrid",
        queue_length: 1,
    });

    // This doesn't work
   tfClient.subscribe('grid_map',(tf)=>{
           console.log(tf);
   })

  topic.subscribe((message) => {
      // This works
      tfClient.subscribe('grid_map',(tf)=>{
           console.log(tf);
   })
})

Expected Behavior

Actual Behavior

MatthijsBurgh commented 2 years ago

Please provide code samples

roddc commented 2 years ago

Please provide code samples

I have provided the code sample to reproduce, I was using a ros bag to test the code. I also notice that sometimes the tf subscribe callback never called after I refreshed the page, but the client did receive the tf2_web_republisher/feedback from Websocket. Is it because the goal_ids were not the same after I refresh the page?