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)
# Start the rosbridge websocket server:
ros2 run rosbridge_server rosbridge_websocket
# Publish a simple string message to a topic:
ros2 topic pub /test std_msgs/String "data: 'hello from ROS2'"
# Start the rosbridge websocket server:
roslaunch rosbridge_server rosbridge_websocket.launch
# Publish a simple string message to a topic:
rostopic pub /test std_msgs/String "data: 'hello from ROS1'"