The following command must be executed in the computer with the rosmaster.
rosrun rosserial_arduino serial_node.py _port:=/dev/ttyUSB0 _baud:=115200
The baud must match the baud in the uros.NodeHandle statement in the micropython-rosserial script.
micropython-rosserial publisher sample code
import uros from std_msgs import ColorRGBA #message object ColorRGBA from time import sleep node=uros.NodeHandle(2,115200) #node initialized, for tx2/rx2 and 115200 baudrate msg=ColorRGBA() #msg object init msg.r=1 #values to variables assigned msg.g=3 msg.b=4 msg.a=1 while True: node.publish('Colorsh',msg) #publish data to node Colorsh sleep(1)
micropython-rosserial subscriber sample code
import uros from std_msgs import String def cb(msg): print(msg.data) node = uros.NodeHandle(2, 115200) node.subscribe('chatter', String, cb)
micropython-rosserial subscriber and publisher sample code
import uros from std_msgs import String def cb(msg): print(msg.data) packet=String() packet.data='hola fpy' node = uros.NodeHandle(2, 115200) node.subscribe('chatter', String, cb) while True: node.publish('greet', packet)
Node constructor
uros.NodeHandle(SERIAL_ID = 2, BAUDRATE = 115200, **KWARGS)
Remark: there are 3 serial ports in esp32
**KWARGS are arguments for a custom serial port connection.
More info about micropython-rosserial
https://pypi.org/project/micropython-rosserial/
end