2022-02-21 14:22:44 +08:00
# roslibdart
2022-02-21 17:58:22 +08:00
The is a fork of the original roslib by Eternali Conrad Heidebrecht (@Eternali), Artur Rymarz (@artrmz), TimWhiting Tim Whiting (@TimWhiting). roslibdart is a library for communicating to a ROS node over websockets with rosbridge. It is heavily influenced by roslibjs and follows the same structure. This fork is an effort to update the library and make it compatible to null safety, dart2 and ros2.
2022-02-21 14:22:44 +08:00
## List of feature implementation statuses (essentially a list of features required to reach roslibjs's level)
- [X] Core:
- [x] ROS connection object
- [x] Topic object (subscribe, unsubscribe, publish, advertise, unadvertise)
- [x] Service object (call, advertise, unadvertise)
- [x] Request object (provides typing and naming to any potential ROS request)
- [x] Param object (get, set, delete)
2022-02-21 17:58:22 +08:00
2022-02-21 14:22:44 +08:00
## Usage
### Install rosbridge
You can either
```
# install using apt-get
sudo apt-get install ros-foxy-rosbridge-server
# or you can clone from github
cd ros_ws/src
git clone https://github.com/RobotWebTools/rosbridge_suite
cd ..
colcon build
```
### Run ros bridge
```
2022-02-21 17:58:22 +08:00
cd ros_ws
2022-02-21 14:22:44 +08:00
source install/local_setup.bash
ros2 launch rosbridge_server rosbridge_websocket_launch.xml
```
2022-02-22 20:23:58 +08:00
## Testing publisher
2022-02-22 22:04:37 +08:00
### Demostration: running ros publisher and roslibdart subscriber
2022-02-21 14:22:44 +08:00
```
# Assume ros_ws is your workspace
cp -r rospackage/* ~/ros_ws/src/
cd ~/ros_ws
colcon build
source install/local_setup.bash
ros2 run tutorial publisher
```
2022-02-22 22:04:37 +08:00
2022-02-21 14:22:44 +08:00
```
cd example/subscriber
flutter run -d linux
```
2022-02-22 22:04:37 +08:00
### Example code of using roslibdart to subscribe
2022-02-22 21:54:27 +08:00
```
ros = Ros(url: 'ws://127.0.0.1:9090');
chatter = Topic(ros: ros, name: '/topic', type: "std_msgs/String", reconnectOnClose: true, queueLength: 10, queueSize: 10);
ros.connect();
await chatter.subscribe(subscribeHandler);
Future< void > subscribeHandler(Map< String , dynamic > msg) async {
msgReceived = json.encode(msg);
setState(() {});
}
```
2022-02-22 20:23:58 +08:00
## Testing subscriber
2022-02-22 22:04:37 +08:00
### Demostration: running ros subscriber and roslibdart publisher
2022-02-22 20:23:58 +08:00
```
ros2 run tutorial subscriber
```
2022-02-22 22:04:37 +08:00
2022-02-22 20:23:58 +08:00
```
cd example/publisher
flutter run -d linux
```
2022-02-22 22:04:37 +08:00
### Example code of using roslibdart to Publish
2022-02-22 21:54:27 +08:00
```
ros = Ros(url: 'ws://127.0.0.1:9090');
chatter = Topic(ros: ros, name: '/topic', type: "std_msgs/String", reconnectOnClose: true, queueLength: 10, queueSize: 10);
ros.connect();
Map< String , dynamic > json = {"data": msgToPublished.toString()};
await chatter.publish(json);
```
2022-02-22 20:23:58 +08:00
## Testing call
2022-02-22 22:04:37 +08:00
### Demostration: running roslibdart caller and ros service
2022-02-22 20:23:58 +08:00
```
ros2 run tutorial service
```
2022-02-22 22:04:37 +08:00
2022-02-22 20:23:58 +08:00
```
2022-02-22 22:04:37 +08:00
cd example/caller
2022-02-22 20:23:58 +08:00
flutter run -d linux
```
2022-02-22 22:04:37 +08:00
### Example code of using roslibdart to call a service
2022-02-22 21:54:27 +08:00
```
ros = Ros(url: 'ws://127.0.0.1:9090');
service = Service(name: 'add_two_ints', ros: ros, type: "tutorial_interfaces/AddTwoInts");
ros.connect();
Map< String , dynamic > json = {"a": 1, "b": 2};
Map< String , dynamic > result = await service.call(json);
msgToPublished = result['sum'];
```
2022-02-22 22:04:37 +08:00
2022-02-22 20:23:58 +08:00
## Testing providing service
2022-02-22 22:04:37 +08:00
### Demostration: running roslibdart service and ros caller
2022-02-22 21:54:27 +08:00
```
cd example/service
flutter run -d linux
```
2022-02-22 20:23:58 +08:00
```
2022-02-22 22:04:37 +08:00
ros2 run tutorial caller 2 3
2022-02-22 20:23:58 +08:00
```
2022-02-22 22:04:37 +08:00
### Example code of using roslibdart to provide service
2022-02-22 21:54:27 +08:00
```
ros = Ros(url: 'ws://127.0.0.1:9090');
service = Service(name: 'add_two_ints', ros: ros, type: "tutorial_interfaces/AddTwoInts");
ros.connect();
await service.advertise(serviceHandler);
Future< Map < String , dynamic > >? serviceHandler(Map< String , dynamic > args) async {
Map< String , dynamic > response = {};
response['sum'] = args['a'] + args['b'];
return response;
}
```
2022-02-21 17:58:22 +08:00
## Links
- [ROSBridge Protocol v2.0 ](https://github.com/biobotus/rosbridge_suite/blob/master/ROSBRIDGE_PROTOCOL.md ).
- [Original roslib library from Conrad Heidebrecht ](https://github.com/Eternali/roslib )
2022-02-22 20:23:58 +08:00
- [RosBridge server implementation ](https://github.com/RobotWebTools/rosbridge_suite )
2022-02-22 21:54:27 +08:00
- [roslibjs example ](https://github.com/RobotWebTools/roslibjs/blob/develop/examples/simple.html )