Using the roslibpy library to connect Ubuntu ROS with python on windows

created at 06-07-2022 views: 12

environment

  • Win10+python, call it WinPC
  • The virtual machine Ubuntu16.04 + ROS kinetic calls it RosPC

implemention

First, install rosbridge suite on RosPC:

sudo apt-get install -y ros-kinetic-rosbridge-server
sudo apt-get install -y ros-kinetic-tf2-web-republisher

Before you connect, make sure the service is up:

roslaunch rosbridge_server rosbridge_websocket.launch
rosrun tf2_web_republisher tf2_web_republisher

Install roslibpy on your WinPC:

pip install roslibpy

Simple connection:

We start by importing roslibpy as follows:

import roslibpy

We initialize the connection (the port defaults to 9090):

ros = roslibpy.Ros(host='localhost', port=9090)
ros.run()

The preceding line starts the connection but does not block, i.e. the connection is established in the background, but the function returns control to the program immediately.

Let's take a look at the status:

print(ros.is_connected)

# rusult:

True
created at:06-07-2022
edited at: 06-09-2022: