The new ROS2TFClient + React application #742
Replies: 1 comment 7 replies
-
Just to help narrow down the issue and make sure we're seeing a roslibjs issue as opposed to a React lifecycle issue, I have a couple recommendations: Instead of doing const exampleSubscriber = useMemo(() => new ROSLIB.Topic({
ros: ros,
name: topic,
messageType: type,
}), [ros, topic, type]); You can apply a similar model to defining your ROS2TFClient. I suspect you are actually causing extremely high-rate re-renders on your React component and things are getting confused. As a general React tip, you should never call a state setter within a high-rate callback - so if you need to have references to the "most recent message" like you have here, I would recommend using |
Beta Was this translation helpful? Give feedback.
-
Hello!
So, following up on the recent PR #731 of adding a TF client for ROS 2 on roslibjs. I decided to try and use it in a React application that my team is working on for using Three.js (react-three-fiber) for visualizing ROS 2 data, but I've run into a issue. I will describe what's happening and provide some code snippets and we can follow up a discussion on the matter as proposed by @EzraBrooks on #731.
So, I changed the Roslibjs version on
package.json
togithub:RobotWebTools/roslibjs#develop
and installed it. Then, realized that actions are still not implemented on the main release of rosbridge for Ros Humble, so I cloned and compiled the most recent version of therosbridge_suite
(branchros2
), launched the newrosbridge_websocket
and thetf2_web_republisher
fork from @pac48 .I'm now able to get TFs arriving, but something wrong is happening with the rosbridge as I stop being able to unsubscribe from other topic subscribers and can't dispose ROS2TFClient when the component unmounts and eventually
WebSocketClosedError: Tried to write to a closed websocket
errors start raining on the rosbridge websocket if I try to reconnect.Maybe I'm doing something wrong, but this was my approach (sample code, some logic is not there like changing topics, etc):
So I launch everything:
ros2 run tf2_web_republisher tf2_web_republisher_node
ros2 launch rosbridge_server rosbridge_websocket_launch.xml
The rosbag:
ros2 bag play example_rosbag
And launch my app and connect to the rosbridge_websocket and both msg and tf start arriving:
But, I can no longer unsubscribe correctly from topic subscribers (exampleSubscriber in this case).
Before, on disconnect and component unmount, the rosbridge disconnects cleanly:
Now, with an active subscription on TF client, I try to disconnect/unmount and this happens:
The subscriber topic does not unsubscribe and on the next connection it creates new subscribers and duplicates it. I think the TFClient may actually unsubscribe (I've printed and checked the object and the frame_id is removed) but there is no feedback on the rosbridge). This only happens if I call a ROS2TFClient.subscribe(), if I don't subscribe a TF, everything is ok.
Am I doing something wrong or is the rosbridge not stable with actions yet, or something? Can someone reproduce this?
If you can make it work, please give me some insights on your approach!
Thank you :)
Beta Was this translation helpful? Give feedback.
All reactions