A C++11 library to interface ROS via rosbridge
This library can be used to talk to ROS and ROS2 via rosbridge. It enables you to communicate with ROS even if you don't have the full ROS Stack on your machine available (for example, when you are using Windows). The network communication of this library uses WebSocket protocol for compatibility with ROS2 rosbridge.
Please note that this library is in an early development stage and features are added as needed. Even though the library supports JSON and BSON, it's strongly recommended to use BSON.
Before you can compile the library, you need to install websocketpp, jsoncpp, libbson, and Boost.
sudo apt update
sudo apt install -y libwebsocketpp-dev libjsoncpp-dev libbson-dev libboost-all-dev
If you want to run rosbridge on the same machine:
# For ROS1 and ROS2
sudo apt install -y ros-${ROS_DISTRO}-rosbridge-suite
Now you can clone this repo. Please use --recursive if you want to use the unit tests. After cloning the repo, change into that directory and execute:
mkdir build
cd build
cmake .. # or 'cmake .. -Dtest=on' if you build the unit tests
make
The library provides two transport options:
Checkout src/client/websocket_client.cpp for an example implementation using WebSocket connections.
For ROS2 (Recommended):
ros2 run rosbridge_server rosbridge_websocket
# or
ros2 launch rosbridge_server rosbridge_websocket_launch.xml
For ROS1:
roslaunch rosbridge_server rosbridge_websocket.launch bson_only_mode:=True
Checkout src/client/tcp_client.cpp for an example implementation using TCP connections.
For ROS1:
roslaunch rosbridge_server rosbridge_tcp.launch bson_only_mode:=True
The CMakeLists.txt builds both clients:
websocket_client- WebSocket client (default)tcp_client- TCP client (for ROS1 compatibility)
Please ensure that the you executed cmake with '-Dtest=on' before you continue. When the library and the unit tests are compiled, execute the following commands on a machine running ROS to setup a minimal testing environment:
ros2 run rosbridge_server rosbridge_websocket
ros2 topic pub /test std_msgs/String "data: 'a5424890996794277159554918'"
ros2 run examples_rclcpp_minimal_service add_two_ints_server
roslaunch rosbridge_server rosbridge_websocket.launch # plus bson_only_mode:=True if you want to use BSON
rostopic pub /test std_msgs/String a5424890996794277159554918
rosrun rospy_tutorials add_two_ints_server