WebBridge is a bridge between ROS and the Web.
- exposes ROS topics, services, and parameters over WebSockets using JSON messages.
- A browser or any web app can connect via roslib.js (JavaScript client).
- There are other client implementation except js like python roslibpy
<!DOCTYPE html><html><head><metacharset="utf-8"/><scriptsrc="https://cdn.jsdelivr.net/npm/roslib@1/build/roslib.min.js"></script><title>ROS Bridge Demo</title><script>// Connecting to ROS// -----------------varros=newROSLIB.Ros();ros.connect('ws://localhost:9090');ros.on('connection',function(){console.log('Connected to websocket server.');});ros.on('error',function(error){console.log('Error connecting to websocket server: ',error);});ros.on('close',function(){console.log('Connection to websocket server closed.');});// ----------------- </script>
<!DOCTYPE html><html><head><metacharset="utf-8"/><scriptsrc="https://cdn.jsdelivr.net/npm/roslib@1/build/roslib.min.js"></script><title>ROS Bridge Demo</title><script>// Connecting to ROS// -----------------varros=newROSLIB.Ros();ros.connect('ws://localhost:9090');ros.on('connection',function(){console.log('Connected to websocket server.');});ros.on('error',function(error){console.log('Error connecting to websocket server: ',error);});ros.on('close',function(){console.log('Connection to websocket server closed.');});// ----------------- </script><script>// Reading the parameter 'param1'varparam1=newROSLIB.Param({ros:ros,name:'/minimal:param1'});</script><body><labelfor="param1Value">param1 value:</label><spanid="param1Value">Loading...</span><buttononclick="refreshParam1()">Refresh</button><buttononclick="updateParam1()">Update</button><script>functiondisplayParam1(value){document.getElementById('param1Value').textContent=value;}// Initial fetch and displayparam1.get(function(value){displayParam1(value);});// Refresh button handlerfunctionrefreshParam1(){param1.get(function(value){displayParam1(value);});}functionupdateParam1(){constnewValue=prompt("Enter new value for param1:");if(newValue!==null){param1.set(newValue);refreshParam1();}}</script></body>
Subscriber
Implement subscriber to ros topic
The demo topic publish int counter
The js subscribe using bridge
#!/usr/bin/env python3importrclpyfromrclpy.nodeimportNodefromstd_srvs.srvimportTriggerfromrclpy.qosimportqos_profile_services_defaultTOPIC="trigger_srv"classMyNode(Node):def__init__(self):node_name="minimal_srv"super().__init__(node_name)self.srv=self.create_service(Trigger,TOPIC,self.handler,qos_profile=qos_profile_services_default)self.get_logger().info("Hello ROS2")defhandler(self,request:Trigger.Request,response:Trigger.Response):self.get_logger().info("Trigger service called")response.success=Trueresponse.message="success"print(response)returnresponsedefmain(args=None):rclpy.init(args=args)node=MyNode()rclpy.spin(node)node.destroy_node()rclpy.shutdown()if__name__=='__main__':main()