As stated in micropython-rosserial documentation, any ROS message type to be used by a node must be created before they can be used in micropython-rosserial based scripts.
The message class files are generated by module ugenpy, one of the additional modules installed during the pip install of the micropython-rosserial.
But although the module is installed it doesn’t install the folder of with the message definition files, the *.msg files, for the std_messages.
So we need to copy the msg definition files to our MicroPython device.
Before we can do that we need:
- the .msg files for ROS std_msgs;
- the software to copy then to the file system of our MicroPython device;
Lets do it now.
Get the std_msgs .msgs files from github
github repository to the /std_msgs folder in our MicroPython device.
cd ~/ git clone https://github.com/FunPythonEC/uPy-genpy cd uPy-genpy/src
The rshell is the software to copy the files to (and from) the microPython file system.
It can also be used as serial terminal to access the microPython console (the REPL)
sudo pip3 install rshell
After installation we can run it with the following command
rshell connect serial /dev/ttyUSB0 115200
We get automatically connected to our micropython device.
We may also just run rshell and issue the connect insider the rshell.
The command help give the available commands.
help Documented commands (type help <topic>): ======================================== args cat connect date edit filesize help mkdir rm shell boards cd cp echo exit filetype ls repl rsync
The boards command give the avalilable / connected boards.
boards pyboard @ /dev/ttyUSB0 connected Epoch: 2000 Dirs: /boot.py /lib /main.py /project.pymakr /rospub.py /rossub.py /utils.py /pyboard/boot.py /pyboard/lib /pyboard/main.py /pyboard/project.pymakr /pyboard/rospub.py /pyboard/rossub.py /pyboard/utils.py
The repl command gives us access to the microphython console, the REPL.
repl Entering REPL. Use Control-X to exit. > MicroPython v1.15 on 2021-04-18; ESP32 module with ESP32 Type "help()" for more information. >>>
Our micropython device file system is available under the following path:
So we in order to copy our folder std_msgs from our computer to our micropython file system, we use the following command
cp -r std_msgs /pyboard
After some seconds all the files are copied and you could list the /std_msgs folder in the file system of our micropython device with:
ls /pyboard/std_msgs Bool.msg Duration.msg Float64MultiArray.msg Int32MultiArray.msg MultiArrayDimension.msg UInt16MultiArray.msg UInt8.msg Byte.msg Empty.msg Header.msg Int64.msg MultiArrayLayout.msg UInt32.msg UInt8MultiArray.msg ByteMultiArray.msg Float32.msg Int16.msg Int64MultiArray.msg String.msg UInt32MultiArray.msg Char.msg Float32MultiArray.msg Int16MultiArray.msg Int8.msg Time.msg UInt64.msg ColorRGBA.msg Float64.msg Int32.msg Int8MultiArray.msg UInt16.msg UInt64MultiArray.msg
I just copy all the messages, but, in order to spare space, we should only copy the required ones.
Now that we have the msg files in our micropython device, we may start to create de ROS message class files required for our test scripts.
Go to the REPL (micropython console) with the following command.
And enter the following lines on the REPL
from ugenpy.message import MessageGenerator msg=MessageGenerator('std_msgs/ColorRGBA.msg') msg.create_message() msg=MessageGenerator('std_msgs/String.msg') msg.create_message()
The first part import the required module
The second part, create the py class file for the file ColorRGBA.msg
The third part, create the py class file for the file String.msg
We get some info about the processed data types. For the first file is:
data type processed: float32 to be <f data type processed: float32 to be <f data type processed: float32 to be <f data type processed: float32 to be <f
For the second file, we get:
data type processed: string to be <I%ss
We may check if the files exist inside the REPL, with the following commands.
> import os >>> os.listdir('std_msgs') ['Bool.msg', 'Byte.msg', 'ByteMultiArray.msg', 'Char.msg', (...) 'UInt8MultiArray.msg', '_ColorRGBA.py', '_String.py', '__init__.py']