Skip to content

A demonstration of basic ROSBridge and ROStful functionality.

Notifications You must be signed in to change notification settings

playertr/rosbridge_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rosbridge_demo

A demonstration of basic rosbridge and rostful functionality in a ROS system.

As shown in the diagram, rosbridge exposes a JSON interface to a ROS service, while rostful presents a REST interface via an HTTP interface.

Sample node

The ROS package ros_pose_gen contains a server (written in Python) which provides a set of sample ROS topics and services, which can then be accessed either through rosbridge or rostful.

/gen_random_poses generates a requested number of 6DOF poses

Access via rosbridge

Rosbridge converts ROS messages to a JSON format, and expose those results on a websocket, with a schema like

{ 
  "op": "call_service", 
  "service": "/gen_random_pose", 
  "args": [2]
}

that is well-documented. Because it is documented, actively maintained, and automically configured, it is a potentially scalable choice for ROS JSON API needs.

diagram

The directory cpp_client contains a C++ client which interacts with the rosbridge interface in "raw JSON."

The directory roslibpy_client uses roslibpy, which must be installed. Note: that roslibpy does not require ROS to be installed (that's the magic of rosbridge), you should be able to install it on any computer using pip.

Access vis rostful

Rostful publishes a REST interface over HTTP. In the container, it publishes on port 8080.

Any web browser can be used to read a published topic via GET by opening the address: http://localhost:8080/chatter

Rostful example

ROS services are called with a PUT, which require a little more work. From the command line:

% curl -X POST http://localhost:8080/add_two_ints -H 'Content-Type: application/json' -d '{"a": 1, "b": 2}'

{"sum": 3, "_format": "ros"}

POST is also used to publish to ROS topics.

Rostful publishes some meta-information at URLs http://localhost:8080/_rosdef


Installation and Usage

Docker (Recommended)

This demo can be run in Docker containers, which greatly simplifies installation. Docker is supported on Windows, Mac, and many flavors of Linux including Windows Subsystem for Linux. I uploaded images on Docker Hub that you can download with the following commands.

  1. Install Docker Engine by following the official instructions.

  2. Download and run the rosbridge_demo_ros container. This container:

    • provides a ROS service that generates a list of random poses
    • starts a rosbridge server on port 9090
    • starts a rostful server on port 8080
    docker run -it -p 8080:8080 -p 9090:9090 playertr/rosbridge_demo_ros roslaunch ros_pose_gen pose_server.launch
    

    or

    make run-ros-image
    
  3. Download and run the rosbridge_demo_cpp container. This container:

    • connects to the rosbridge websocket
    • requests two (from argument) random poses and prints the response
    docker run -it --net=host playertr/rosbridge_demo_client build/client 2
    
  4. Install roslibpy and run the python client directly (on any computer):

    pip install roslibpy
    roslibpy_client/roslibpy_client.py
    
  5. Access the rostful interface as described above.

Source

If you aren't using Docker, then you can still install all the dependencies locally in an Ubuntu machine. Here's a sketch of how to do that. For more detail, refer to the Docker installation scripts in docker/Dockerfile_ros and docker/Dockerfile_cpp and to the referenced instructions.

  1. Install ROS (Melodic, which requires Ubuntu 18.04, has been tested) by following the official instructions.
  2. Install the ros_pose_gen package in a catkin workspace. This package provides a ROS service that generates a list of random poses.
  3. Install rosbridge by following the official instructions.
  4. Install Microsoft's C++ REST SDK by following the official instructions in its Github README.
  5. Install C++ build tools:
    sudo apt-get update
    sudo apt-get install build-essential cmake
    
  6. Build the C++ client executable. This executable, which is installed to cpp_client/build/main, connects to a rosbridge server at 0.0.0.0:9090 and issues a service call to the ROS service.
    mkdir -p cpp_client/build
    cd cpp_client/build
    cmake ..
    make
    
  7. Run the demo:
    • Terminal one:
      source devel/setup.bash
      roslaunch ros_pose_gen pose_server.launch
      
    • Terminal two:
      ./cpp_client/build/client
      

Applicable Documentation

Service/Message definitions http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv

ROS Service Tutorial http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28python%29

How to create a ROS package http://wiki.ros.org/ROS/Tutorials/CreatingPackage

rosbridge docs http://wiki.ros.org/rosbridge_suite

variable-length ROS messages http://wiki.ros.org/msg

ROS pose message http://docs.ros.org/en/noetic/api/geometry_msgs/html/msg/Pose.html

ROS msg capitalization conventions http://wiki.ros.org/ROS/Patterns/Conventions

Running rosbridge tutorial http://wiki.ros.org/rosbridge_suite/Tutorials/RunningRosbridge

rosbridge Protocol Specification https://github.com/RobotWebTools/rosbridge_suite/blob/ros1/ROSBRIDGE_PROTOCOL.md

Microsoft C++ REST SDK https://stackoverflow.com/questions/34423092/websocket-library https://github.com/Microsoft/cpprestsdk


(Re-)Building the docker images

Rules for rebuilding the Dockerfile are in the Makefile as the root of this repo. The docker images can be rebuilt by running:

make images

The individual image can be built by:

make build-ros-image
make build-client-image

About

A demonstration of basic ROSBridge and ROStful functionality.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published