|
1 | 1 | # uPy-rosserial |
2 | | -`rosserial` a method used by ROS in order to establish communication via serial , mostly this is used with microcontrollers, which in this case are the ones responsible in some ROS applications for actuators and sensors usage. |
| 2 | +`rosserial` is a method used by ROS in order to establish communication via serial, basically a middleware, mostly used with microcontrollers, which in this case are the ones responsible in some ROS applications for actuators and sensors usage. |
3 | 3 |
|
4 | | -Since there is no rosserial package for uPy as there is for Arduino, this repo has been created where every needed script to establish rosserial with uPy will be found. |
| 4 | +This library targets the communication between ROS and uPy with rosserial as middleware. |
5 | 5 |
|
6 | 6 | ## Features |
7 | 7 | - [x] Advertising Topics |
8 | 8 | - [x] Publishing |
9 | 9 | - [x] Subscribing |
10 | 10 | - [ ] Services |
11 | 11 |
|
12 | | -**To Do: Subscribing testing and implementation.** |
| 12 | +**To Do: Implement services usage.** |
13 | 13 |
|
14 | 14 | ## Installation |
15 | 15 | Before using this library you must have ROS installed, as well as rosserial which would be with the following command: |
16 | | -`sudo apt install ros-<version>-rosserial` |
17 | 16 |
|
| 17 | +`sudo apt install ros-<version>-rosserial` |
18 | 18 |
|
19 | 19 | In theory every board with the kind of generic `UART` class for ESP32 is capable of using this library, but it must be known exactly which `UART ID` is being used, this means for example, for ESP32 defined pins correspond to TX0 and RX0 for UART0, and so on. In the examples below, UART2 is used. |
20 | 20 |
|
21 | | -In order to use ros node communication, have in mind a python class for each message must be available. this means a dependency of this library is [uPy Genpy](https://github.com/FunPythonEC/uPy-genpy) and [uPy rosserial_msgs](https://github.com/FunPythonEC/uPy-rosserial_msgs), `ugenpy` used to create Python classes for messages from `*.msg` files while `rosserial_msgs` has the `TopicInfo` class for topic negotiation. Follow the installation from `ugenpy` before proceeding. |
22 | 21 |
|
23 | | -Once `ugenpy` and `rosserial_msgs` are inside, the package `uros` from this repository must be copied to the flash memory. I strongly recommend using [rshell](https://github.com/dhylands/rshell). |
| 22 | +### Copying source files |
| 23 | +In order to use ros node communication, have in mind a python class for each message must be available. this means a dependency of this library is [uPy Genpy](https://github.com/FunPythonEC/uPy-genpy) and [uPy rosserial_msgs](https://github.com/FunPythonEC/uPy-rosserial_msgs), `ugenpy` used to create Python classes for messages from `*.msg` files while `rosserial_msgs` has the `TopicInfo` class for topic negotiation. The folders from `src` from this current repo and the other two must be copied |
| 24 | + |
| 25 | +I strongly recommend using [rshell](https://github.com/dhylands/rshell). |
24 | 26 |
|
| 27 | +### Using upip |
25 | 28 | Now available with upip, could be installed with: |
26 | 29 | ``` python |
27 | 30 | import upip |
28 | 31 | upip.install('micropython-rosserial') |
29 | 32 | ``` |
| 33 | +If `micropython-rosserial` is installed, because of requirementes, `ugenpy` and `TopicInfo` will too. |
30 | 34 | >Note: must be connected to WiFi to use upip like this. |
31 | 35 |
|
32 | 36 | **Have in mind before publishing or subscribing to a topic, the message class must be generated with `ugenpy`** |
@@ -94,4 +98,26 @@ node = uros.NodeHandle(2, 115200) |
94 | 98 | node.subscribe('chatter', String, cb) |
95 | 99 | while True: |
96 | 100 | node.publish('greet', packet) |
97 | | -``` |
| 101 | +``` |
| 102 | + |
| 103 | +## Classes |
| 104 | +### `uros.NodeHandle` |
| 105 | +#### Constructor |
| 106 | +##### `uros.NodeHandle(serial_id, baudrate)` |
| 107 | +Initiates the class which handles the node, advertised topics, publishes and subscribe. |
| 108 | +* `serial_id`: corresponds to the UART ID, in case of ESP32, it has 3 UARTS, in the examples UART2 is used. |
| 109 | +* `baudrate`: is the baudrate in which the board will communicate. |
| 110 | + |
| 111 | +#### Methods |
| 112 | +##### `uros.NodeHandle.publish(topic_name, msg, buffer_size=1024)` |
| 113 | +Publishes data to a defined topic, with a defined message class. |
| 114 | +* `topic_name`: the topic where the message will be put or published. |
| 115 | +* `msg`: the msg class initiated with its slots values defined. |
| 116 | +* `buffer_size`: the amount of bytes that will be published as a maximum from this particular topic, 1024 is by default. |
| 117 | + |
| 118 | +##### `uros.NodeHandle.subscribe(topic_name, msgobj, cb, buffer_size=1024)` |
| 119 | +Subscribe to a defined topic. |
| 120 | +* `topic_name`: same as publish. |
| 121 | +* `msgobj`: is the object class, but not instantiated, just the class passed. |
| 122 | +* `cb`: must be defined, it is a callback function, with a single argument that corresponds to the inconming message class. |
| 123 | +* `buffer_size`: same as publish. |
0 commit comments