In this tutorial we will learn how to use the uROS library for micropython: https://github.com/mgtm98/uRos
ROS is an Operating System for Robots in which the different “nodes” communicate with a central server through TCP messages in JSON format.
This library allows us to implement a ROS node in our SBC. It will connect to a server and will be able to send (publish) or receive (subscribe to) messages.
The code to post a message is as follows:
In this code we first connect to the LAN network and then to the ROS server; we define the format of our message and finally we publish.
On the PC we execute a code in python that acts as a ROS server. For simplicity, this code is just a socket server that prints the data to the console.
As a result, the data received on the server is displayed:
If we examine the data we see two parts:
1. The definition of our uRosTopic message. This is only sent once for each new type of message.
2. And the published data. This is sent every time we publish a new value.
Now you are ready to connect your SBC to any ROS device via ethernet, define a custom message and send it with only few lines of python code.