Skip to content

Commit 9330dfa

Browse files
pablogs9Acuadros95
andauthored
Allow custom transports (#21)
* Allow custom transports Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Indentatation Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Docs Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Update macros Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Add custom transport check * Revert changes * Modify README with extend targets * Modify custom contributions Co-authored-by: acuadros95 <acuadros1995@gmail.com>
1 parent 451f425 commit 9330dfa

6 files changed

Lines changed: 56 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
platform: [teensy41, teensy40, teensy36, teensy35, teensy31, due, zero, olimex_e407, esp32dev, nanorp2040connect, portenta_h7_m7, teensy41_eth, nanorp2040connect_wifi, portenta_h7_m7_wifi, esp32dev_wifi, portenta_h7_m7_foxy, portenta_h7_m7_rolling]
17+
platform: [teensy41, teensy40, teensy36, teensy35, teensy31, due, zero, olimex_e407, esp32dev, nanorp2040connect, portenta_h7_m7, teensy41_eth, nanorp2040connect_wifi, portenta_h7_m7_wifi, esp32dev_wifi, portenta_h7_m7_foxy, portenta_h7_m7_rolling, teensy41_custom]
1818

1919
steps:
2020
- uses: actions/checkout@v3

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ PlatformIO will handle the full build process, including dependencies, compilati
1616
- [Transport configuration](#transport-configuration)
1717
- [Extra packages](#extra-packages)
1818
- [Other configuration](#other-configuration)
19-
- [Custom targets](#custom-targets)
20-
- [Custom transport](#custom-transport)
19+
- [Extend library targets](#extend-library-targets)
20+
- [Transport implementation](#transport-implementation)
2121
- [Time source](#time-source)
2222
- [Using the micro-ROS Agent](#using-the-micro-ros-agent)
2323
- [Examples](#examples)
@@ -119,6 +119,26 @@ The transport can be configured with the `board_microros_transport = <transport>
119119
set_microros_native_ethernet_transports(local_mac, local_ip, agent_ip, agent_port);
120120
```
121121

122+
- `custom`
123+
124+
The user will need to write transport functions in app code and provide it to the micro-ROS library using [`rmw_uros_set_custom_transport()` API](https://micro.ros.org/docs/tutorials/advanced/create_custom_transports/)
125+
126+
```c
127+
bool platformio_transport_open(struct uxrCustomTransport * transport) {...};
128+
bool platformio_transport_close(struct uxrCustomTransport * transport) {...};
129+
size_t platformio_transport_write(struct uxrCustomTransport* transport, const uint8_t * buf, size_t len, uint8_t * err) {...};
130+
size_t platformio_transport_read(struct uxrCustomTransport* transport, uint8_t* buf, size_t len, int timeout, uint8_t* err) {...};
131+
132+
rmw_uros_set_custom_transport(
133+
MICROROS_TRANSPORTS_FRAMING_MODE, // Set the MICROROS_TRANSPORTS_FRAMING_MODE or MICROROS_TRANSPORTS_PACKET_MODE mode accordingly
134+
NULL,
135+
platformio_transport_open,
136+
platformio_transport_close,
137+
platformio_transport_write,
138+
platformio_transport_read
139+
);
140+
```
141+
122142
### Extra packages
123143
Colcon packages can be added to the build process using this two methods:
124144
- Package directories copied on the `<Project_directory>/extra_packages` folder.
@@ -136,12 +156,12 @@ This allows the user to customize the library memory resources or activate optio
136156

137157
*Note: the [common.meta](./metas/common.meta) file makes general adjustments to the library and shall not be modified by the user.*
138158

139-
## Custom targets
159+
## Extend library targets
140160
This library can be easily adapted to different boards, transports or RTOS, to achieve this the user shall provide:
141161

142-
### Custom transport
162+
### Transport implementation
143163

144-
Custom transport shall follow the signatures shown on [micro_ros_platformio.h](./platform_code/arduino/micro_ros_platformio.h), the [provided sources](./platform_code) can be used as reference along [this documentation](https://micro-xrce-dds.docs.eprosima.com/en/latest/transport.html#custom-transport). Custom transport source code shall be added on the `./platform_code/<framework>/<board_microros_transport>` path. Example:
164+
New transport implementations shall follow the signatures shown on [micro_ros_platformio.h](./platform_code/arduino/micro_ros_platformio.h), the [provided sources](./platform_code) can be used as reference along [this documentation](https://micro-xrce-dds.docs.eprosima.com/en/latest/transport.html#custom-transport). Contributed transport source code shall be added on the `./platform_code/<framework>/<board_microros_transport>` path. Example:
145165

146166
- `platform.ini`:
147167
```ini
@@ -152,6 +172,8 @@ Custom transport shall follow the signatures shown on [micro_ros_platformio.h](.
152172
- Also, a `MICRO_ROS_TRANSPORT_<FRAMEWORK>_<TRANSPORT>` definition will be available:
153173
https://github.com/micro-ROS/micro_ros_platformio/blob/de7a61c7e86fdd0186ed8b7d8ec320994e8ebcbf/ci/src/main.cpp#L3
154174

175+
*Note: `board_microros_transport = custom` should not be used, as it is used to add custom transports on user app code*
176+
155177
### Time source
156178
micro-ROS needs a time source to handle executor spins and synchronize reliable communication. To achieve this, a `clock_gettime` [POSIX compliant](https://linux.die.net/man/3/clock_gettime) implementation is required, with a minimum resolution of 1 millisecond.
157179

ci/platformio.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,13 @@ board_microros_transport = wifi_nina
145145
lib_deps =
146146
arduino-libraries/WiFiNINA@^1.8.13
147147
../
148+
149+
; Custom transports
150+
151+
[env:teensy41_custom]
152+
platform = teensy
153+
board = teensy41
154+
framework = arduino
155+
board_microros_transport = custom
156+
lib_deps =
157+
../

ci/src/main.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414

1515
#include <std_msgs/msg/int32.h>
1616

17+
// Test custom transports
18+
#if defined(MICRO_ROS_TRANSPORT_ARDUINO_CUSTOM)
19+
bool platformio_transport_open(struct uxrCustomTransport * transport) {return false;};
20+
bool platformio_transport_close(struct uxrCustomTransport * transport) {return false;};
21+
size_t platformio_transport_write(struct uxrCustomTransport* transport, const uint8_t * buf, size_t len, uint8_t * err) {return 0;};
22+
size_t platformio_transport_read(struct uxrCustomTransport* transport, uint8_t* buf, size_t len, int timeout, uint8_t* err) {return 0;};
23+
#endif
24+
1725
// Test extra packages
1826
#include <control_msgs/msg/joint_controller_state.h>
1927
#include <my_custom_message/msg/my_custom_message.h>
@@ -70,6 +78,15 @@ void setup() {
7078
char psk[]= "WIFI_PSK";
7179

7280
set_microros_wifi_transports(ssid, psk, agent_ip, agent_port);
81+
#elif defined(MICRO_ROS_TRANSPORT_ARDUINO_CUSTOM)
82+
rmw_uros_set_custom_transport(
83+
MICROROS_TRANSPORTS_FRAMING_MODE,
84+
NULL,
85+
platformio_transport_open,
86+
platformio_transport_close,
87+
platformio_transport_write,
88+
platformio_transport_read
89+
);
7390
#else
7491
#error "No transport defined"
7592
#endif

extra_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def build_microros(*args, **kwargs):
136136
global_env.Append(CPPPATH=[main_path + "/platform_code/{}".format(framework)])
137137

138138
# Add clock implementation
139-
env['SRC_FILTER'] += ' +<platform_code/{}/clock_gettime.cpp>'.format(framework, )
139+
env['SRC_FILTER'] += ' +<platform_code/{}/clock_gettime.cpp>'.format(framework)
140140

141141
# Add transport sources according to the framework and the transport
142142
env['SRC_FILTER'] += ' +<platform_code/{}/{}/micro_ros_transport.cpp>'.format(framework, microros_transport)

platform_code/arduino/custom/micro_ros_transport.h

Whitespace-only changes.

0 commit comments

Comments
 (0)