Installing, Running, and Using RosBridge
Introduction
This section describes installing RosBridge, which is useful for communicating to devices which do not have ROS installed (like windows machines with custom drivers)
Installing, Running, and Using RosBridge
-
Install necessary prerequisites on the ROS machine ```bash #Install rosbridge on guest machine sudo apt install -y ros-melodic-rosbridge-suite
ensure you have the most recent version of pip
pip3 install --upgrade pip
Install roslibpy client for rosbridge on guest machine
pip3 install setuptools_rust service_identity roslibpy
launch rosbridge server
roslaunch rosbridge_server rosbridge_websocket.launch
open up your favorite python editor
spyder3 ```
-
start roscore on the guest:
bash roscore -
Run an existing talker in ROS. in a new terminal window: ```bash cd ~/catkin_ws source ./devel/setup.bash
In the last tutorial we made a publisher called "talker". Let's run it:
rosrun beginner_tutorials talker (C++)
rosrun beginner_tutorials talker.py # (Python) ```
Non-ROS machine setup
-
install roslibpy (required if you did not do this in the prior step)
bash pip install service_identity roslibpy -
create a file called listener.py, substituting the ip address of the ROS Master for
. Paste in the following: ```python
-- coding: utf-8 --
""" Created on Fri Mar 27 08:33:41 2020
@author: danaukes """
from future import print_function import roslibpy
client = roslibpy.Ros(host='
', port=9090) client.run() listener = roslibpy.Topic(client, '/chatter', 'std_msgs/String') listener.subscribe(lambda message: print('Heard talking: ' + message['data']))
try: while True: pass except KeyboardInterrupt: client.terminate() except Exception as e: print(e) client.terminate() ```
-
Run from the editor(f5) or, in a new terminal window, navigate to the location of 'listener.py' and type:
bash python3 listener.py -
Now, create a file called talker.py, substituting the ip address of the machine for
if on the host machine, or 'localhost' if in the guest machine. Paste in the following: ```python
-- coding: utf-8 --
""" Created on Fri Mar 27 08:36:13 2020
@author: danaukes """
import time
import roslibpy
client = roslibpy.Ros(host='
', port=9090) client.run() talker = roslibpy.Topic(client, '/dancustom', 'std_msgs/String')
while client.is_connected: talker.publish(roslibpy.Message({'data': 'Hello World!'})) print('Sending message...') time.sleep(1)
talker.unadvertise()
client.terminate() ```
-
on the guest machine, start a new terminal window, and type
bash rostopic echo /dancustom