Skip to content

Commit c93c42a

Browse files
committed
feat: Add ROS 2 Lyrical support
- Add lyrical development and MCU repositories to Sources - Add lyrical package ignore list - Add source compatibility patches for ROS 2 Lyrical (ament_cmake macro, rcutils threading, rosidl_buffer no-exceptions, rcl_timer_init2, rclc_lifecycle clock parameter) - Add portenta_h7_m7_lyrical test environment to ci/platformio.ini and .github/workflows/ci.yml - Update README.md with lyrical distribution Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
1 parent cfee17f commit c93c42a

6 files changed

Lines changed: 219 additions & 5 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
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, esp32dev_ethernet, portenta_h7_m7_humble, portenta_h7_m7_jazzy, portenta_h7_m7_kilted, portenta_h7_m7_rolling, teensy41_custom, pico, pico2]
19+
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, esp32dev_ethernet, portenta_h7_m7_humble, portenta_h7_m7_jazzy, portenta_h7_m7_kilted, portenta_h7_m7_lyrical, portenta_h7_m7_rolling, teensy41_custom, pico, pico2]
2020

2121
steps:
2222
- uses: actions/checkout@v5

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ The target ROS 2 distribution can be configured with the `board_microros_distro
102102
- `humble`
103103
- `jazzy`
104104
- `kilted` *(default value)*
105+
- `lyrical`
105106
- `rolling`
106107

107108
### Transport configuration

‎ci/platformio.ini‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ board_microros_distro = kilted
2828
lib_deps =
2929
../
3030

31+
; Lyrical test
32+
[env:portenta_h7_m7_lyrical]
33+
platform = ststm32
34+
board = portenta_h7_m7
35+
framework = arduino
36+
board_microros_transport = serial
37+
board_microros_distro = lyrical
38+
lib_deps =
39+
../
40+
3141
; Rolling test
3242
[env:portenta_h7_m7_rolling]
3343
platform = ststm32
@@ -206,3 +216,4 @@ framework = arduino
206216
board_microros_transport = custom
207217
lib_deps =
208218
../
219+

‎ci/src/main.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void setup() {
126126
&timer,
127127
&support,
128128
RCL_MS_TO_NS(100),
129-
timer_callback));
129+
(rcl_timer_callback_t) timer_callback));
130130

131131
// create executor
132132
RCCHECK(rclc_executor_init(&executor, &support.context, 1, &allocator));

‎microros_utils/library_builder.py‎

Lines changed: 172 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ def download_dev_environment(self):
9696

9797
def build_dev_environment(self):
9898
print("Building micro-ROS dev dependencies")
99+
self.patch_dev_sources()
99100

100-
# Fix build: Ignore rmw_test_fixture_implementation in rolling
101+
# Fix build: Ignore rmw_test_fixture_implementation in rolling, kilted, lyrical
101102
touch_command = ''
102-
if self.distro in ('rolling', 'kilted'):
103-
touch_command = 'touch src/ament_cmake_ros/rmw_test_fixture_implementation/COLCON_IGNORE && '
103+
if self.distro in ('rolling', 'kilted', 'lyrical'):
104+
touch_command = 'touch src/ament_cmake_ros/rmw_test_fixture_implementation/COLCON_IGNORE src/ament_cmake_ros/rmw_test_fixture/COLCON_IGNORE && '
104105

105106
command = "cd {} && {} . {} && colcon build --cmake-args -DBUILD_TESTING=OFF -DPython3_EXECUTABLE=`which python`".format(self.dev_folder, touch_command, self.python_env)
106107
result = run_cmd(command, env=self.env)
@@ -173,6 +174,7 @@ def get_repositories_from_yaml(self, yaml_file):
173174

174175
def build_mcu_environment(self, meta_file, toolchain_file, user_meta = ""):
175176
print("Building micro-ROS library")
177+
self.patch_mcu_sources()
176178

177179
common_meta_path = self.library_folder + '/metas/common.meta'
178180
colcon_command = '. {} && colcon build --merge-install --packages-ignore-regex=.*_cpp --metas {} {} {} --cmake-args -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=OFF -DTHIRDPARTY=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE={} -DPython3_EXECUTABLE=`which python`'.format(self.python_env, common_meta_path, meta_file, user_meta, toolchain_file)
@@ -213,6 +215,18 @@ def package_mcu_library(self):
213215
# Copy includes
214216
shutil.copytree(self.build_folder + "/mcu/install/include", self.includes)
215217

218+
timer_h = os.path.join(self.includes, "rclc", "timer.h")
219+
if os.path.exists(timer_h):
220+
with open(timer_h, "r") as f_t:
221+
ct = f_t.read()
222+
if "rclc_timer_init_default2" not in ct:
223+
ct = ct.replace(
224+
"#if __cplusplus\n}\n#endif",
225+
"static inline rcl_ret_t rclc_timer_init_default2(rcl_timer_t * timer, rclc_support_t * support, const uint64_t timeout_ns, const rcl_timer_callback_t callback, bool autostart) { (void)autostart; return rclc_timer_init_default(timer, support, timeout_ns, callback); }\n\n#if __cplusplus\n}\n#endif"
226+
)
227+
with open(timer_h, "w") as f_t:
228+
f_t.write(ct)
229+
216230
# Fix include paths
217231
include_folders = os.listdir(self.includes)
218232

@@ -235,3 +249,158 @@ def resolve_binutils_path(self):
235249
sys.exit(1)
236250

237251
return ""
252+
253+
def patch_dev_sources(self):
254+
all_cmake = os.path.join(self.dev_src_folder, "ament_cmake", "ament_cmake_core", "cmake", "core", "all.cmake")
255+
if os.path.exists(all_cmake):
256+
with open(all_cmake, "r") as f:
257+
ac = f.read()
258+
if "macro(ament_target_dependencies" not in ac:
259+
macro_def = """
260+
261+
# Compatibility ament_target_dependencies macro for micro-ROS
262+
macro(ament_target_dependencies target)
263+
cmake_parse_arguments(_ARG "SYSTEM;INTERFACE;PUBLIC;PRIVATE" "" "" ${ARGN})
264+
set(_dependencies ${_ARG_UNPARSED_ARGUMENTS})
265+
foreach(_dep ${_dependencies})
266+
find_package(${_dep} QUIET)
267+
if(TARGET ${_dep})
268+
if(_ARG_INTERFACE)
269+
target_link_libraries(${target} INTERFACE ${_dep})
270+
elseif(_ARG_PUBLIC)
271+
target_link_libraries(${target} PUBLIC ${_dep})
272+
else()
273+
target_link_libraries(${target} PRIVATE ${_dep})
274+
endif()
275+
elseif(TARGET ${_dep}::${_dep})
276+
if(_ARG_INTERFACE)
277+
target_link_libraries(${target} INTERFACE ${_dep}::${_dep})
278+
elseif(_ARG_PUBLIC)
279+
target_link_libraries(${target} PUBLIC ${_dep}::${_dep})
280+
else()
281+
target_link_libraries(${target} PRIVATE ${_dep}::${_dep})
282+
endif()
283+
endif()
284+
if(${_dep}_INCLUDE_DIRS)
285+
if(_ARG_INTERFACE)
286+
target_include_directories(${target} INTERFACE ${${_dep}_INCLUDE_DIRS})
287+
elseif(_ARG_PUBLIC)
288+
target_include_directories(${target} PUBLIC ${${_dep}_INCLUDE_DIRS})
289+
else()
290+
target_include_directories(${target} PRIVATE ${${_dep}_INCLUDE_DIRS})
291+
endif()
292+
endif()
293+
if(${_dep}_LIBRARIES)
294+
if(_ARG_INTERFACE)
295+
target_link_libraries(${target} INTERFACE ${${_dep}_LIBRARIES})
296+
elseif(_ARG_PUBLIC)
297+
target_link_libraries(${target} PUBLIC ${${_dep}_LIBRARIES})
298+
else()
299+
target_link_libraries(${target} PRIVATE ${${_dep}_LIBRARIES})
300+
endif()
301+
endif()
302+
endforeach()
303+
endmacro()
304+
"""
305+
with open(all_cmake, "a") as f:
306+
f.write(macro_def)
307+
308+
def patch_mcu_sources(self):
309+
# 1. Patch rcutils base64.c for no thread support
310+
base64_c = os.path.join(self.mcu_src_folder, "rcutils", "src", "base64.c")
311+
if os.path.exists(base64_c):
312+
with open(base64_c, "r") as f:
313+
bc = f.read()
314+
if "RCUTILS_NO_THREAD_SUPPORT" not in bc:
315+
target1 = "#ifdef _WIN32\nstatic INIT_ONCE base64_map_initialization_once = INIT_ONCE_STATIC_INIT;"
316+
rep1 = "#if defined(RCUTILS_NO_THREAD_SUPPORT)\nstatic bool base64_map_initialized = false;\n#elif defined(_WIN32)\nstatic INIT_ONCE base64_map_initialization_once = INIT_ONCE_STATIC_INIT;"
317+
target2 = "#else\n pthread_once(&base64_map_initialization_once, initialize_base64_map);\n#endif"
318+
rep2 = "#elif defined(RCUTILS_NO_THREAD_SUPPORT)\n if (!base64_map_initialized) { initialize_base64_map(); base64_map_initialized = true; }\n#else\n pthread_once(&base64_map_initialization_once, initialize_base64_map);\n#endif"
319+
bc = bc.replace(target1, rep1).replace(target2, rep2)
320+
with open(base64_c, "w") as f:
321+
f.write(bc)
322+
323+
# 2. Patch rosidl_buffer buffer.hpp for -fno-exceptions
324+
buffer_hpp = os.path.join(self.mcu_src_folder, "rosidl", "rosidl_buffer", "include", "rosidl_buffer", "buffer.hpp")
325+
if os.path.exists(buffer_hpp):
326+
with open(buffer_hpp, "r") as f:
327+
bh = f.read()
328+
if "__EXCEPTIONS" not in bh:
329+
orig_throw1 = ' throw std::invalid_argument("Buffer implementation must not be null");'
330+
patch_throw1 = '#if __EXCEPTIONS || defined(__cpp_exceptions)\n throw std::invalid_argument("Buffer implementation must not be null");\n#endif'
331+
bh = bh.replace(orig_throw1, patch_throw1)
332+
333+
orig_fn = """ void throw_if_not_cpu_backend() const
334+
{
335+
if (!cpu_impl_) {
336+
throw std::runtime_error(
337+
"Operation requires CPU backend. Current backend: " +
338+
impl_->get_backend_type() +
339+
". Use to_vector() for explicit conversion to CPU.");
340+
}
341+
}"""
342+
patch_fn = """ void throw_if_not_cpu_backend() const
343+
{
344+
#if __EXCEPTIONS || defined(__cpp_exceptions)
345+
if (!cpu_impl_) {
346+
throw std::runtime_error(
347+
"Operation requires CPU backend. Current backend: " +
348+
impl_->get_backend_type() +
349+
". Use to_vector() for explicit conversion to CPU.");
350+
}
351+
#endif
352+
}"""
353+
bh = bh.replace(orig_fn, patch_fn)
354+
with open(buffer_hpp, "w") as f:
355+
f.write(bh)
356+
357+
# 3. Patch rclc timer.c for rcl_timer_init2
358+
timer_c = os.path.join(self.mcu_src_folder, "rclc", "rclc", "src", "rclc", "timer.c")
359+
if os.path.exists(timer_c):
360+
with open(timer_c, "r") as f:
361+
tc = f.read()
362+
if "rcl_timer_init2" not in tc:
363+
target_timer = """ rcl_ret_t rc = rcl_timer_init(
364+
timer,
365+
&support->clock,
366+
&support->context,
367+
timeout_ns,
368+
callback,
369+
(*support->allocator));"""
370+
rep_timer = """ rcl_ret_t rc = rcl_timer_init2(
371+
timer,
372+
&support->clock,
373+
&support->context,
374+
timeout_ns,
375+
callback,
376+
(*support->allocator),
377+
true);"""
378+
tc = tc.replace(target_timer, rep_timer)
379+
with open(timer_c, "w") as f:
380+
f.write(tc)
381+
382+
# 4. Patch rclc_lifecycle for rcl_lifecycle_state_machine_init clock parameter
383+
lc_c = os.path.join(self.mcu_src_folder, "rclc", "rclc_lifecycle", "src", "rclc_lifecycle", "rclc_lifecycle.c")
384+
if os.path.exists(lc_c):
385+
with open(lc_c, "r") as f:
386+
lcc = f.read()
387+
if "lifecycle_clock" not in lcc:
388+
target_lc = """ rcl_ret_t rcl_ret = rcl_lifecycle_state_machine_init(
389+
state_machine,
390+
node,
391+
ROSIDL_GET_MSG_TYPE_SUPPORT(lifecycle_msgs, msg, TransitionEvent),"""
392+
rep_lc = """ static rcl_clock_t lifecycle_clock;
393+
static bool lifecycle_clock_initialized = false;
394+
if (!lifecycle_clock_initialized) {
395+
rcl_ros_clock_init(&lifecycle_clock, allocator);
396+
lifecycle_clock_initialized = true;
397+
}
398+
399+
rcl_ret_t rcl_ret = rcl_lifecycle_state_machine_init(
400+
state_machine,
401+
node,
402+
&lifecycle_clock,
403+
ROSIDL_GET_MSG_TYPE_SUPPORT(lifecycle_msgs, msg, TransitionEvent),"""
404+
lcc = "#include <rcl/time.h>\n" + lcc.replace(target_lc, rep_lc)
405+
with open(lc_c, "w") as f:
406+
f.write(lcc)

‎microros_utils/repositories.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ class Sources:
107107
Repository("ament_cmake_ros", "https://github.com/ros2/ament_cmake_ros", "kilted"),
108108
Repository("ament_index", "https://github.com/ament/ament_index", "kilted")
109109
],
110+
'lyrical': [
111+
Repository("ament_cmake", "https://github.com/ament/ament_cmake", "lyrical"),
112+
Repository("ament_lint", "https://github.com/ament/ament_lint", "lyrical"),
113+
Repository("ament_package", "https://github.com/ament/ament_package", "lyrical"),
114+
Repository("googletest", "https://github.com/ament/googletest", "lyrical"),
115+
Repository("ament_cmake_ros", "https://github.com/ros2/ament_cmake_ros", "lyrical"),
116+
Repository("ament_index", "https://github.com/ament/ament_index", "lyrical")
117+
],
110118
'rolling': [
111119
Repository("ament_cmake", "https://github.com/ament/ament_cmake", "rolling"),
112120
Repository("ament_lint", "https://github.com/ament/ament_lint", "rolling"),
@@ -212,6 +220,30 @@ class Sources:
212220
Repository("rcl_logging", "https://github.com/ros2/rcl_logging", "kilted"),
213221
Repository("ros2_tracing", "https://github.com/ros2/ros2_tracing", "kilted"),
214222
],
223+
'lyrical': [
224+
Repository("micro-CDR", "https://github.com/eProsima/micro-CDR", "lyrical", "ros2"),
225+
Repository("Micro-XRCE-DDS-Client", "https://github.com/eProsima/Micro-XRCE-DDS-Client", "lyrical", "ros2"),
226+
Repository("rcl", "https://github.com/micro-ROS/rcl", "lyrical"),
227+
Repository("rclc", "https://github.com/ros2/rclc", "lyrical", "master"),
228+
Repository("micro_ros_utilities", "https://github.com/micro-ROS/micro_ros_utilities", "lyrical", "rolling"),
229+
Repository("rcutils", "https://github.com/micro-ROS/rcutils", "lyrical"),
230+
Repository("micro_ros_msgs", "https://github.com/micro-ROS/micro_ros_msgs", "lyrical", "rolling"),
231+
Repository("rmw-microxrcedds", "https://github.com/micro-ROS/rmw-microxrcedds", "lyrical", "rolling"),
232+
Repository("rosidl_typesupport", "https://github.com/micro-ROS/rosidl_typesupport", "lyrical"),
233+
Repository("rosidl_typesupport_microxrcedds", "https://github.com/micro-ROS/rosidl_typesupport_microxrcedds", "lyrical", "rolling"),
234+
Repository("rosidl", "https://github.com/ros2/rosidl", "lyrical"),
235+
Repository("rosidl_dynamic_typesupport", "https://github.com/ros2/rosidl_dynamic_typesupport", "lyrical"),
236+
Repository("rosidl_core", "https://github.com/ros2/rosidl_core", "lyrical"),
237+
Repository("rmw", "https://github.com/ros2/rmw", "lyrical"),
238+
Repository("rcl_interfaces", "https://github.com/ros2/rcl_interfaces", "lyrical"),
239+
Repository("rosidl_defaults", "https://github.com/ros2/rosidl_defaults", "lyrical"),
240+
Repository("unique_identifier_msgs", "https://github.com/ros2/unique_identifier_msgs", "lyrical"),
241+
Repository("common_interfaces", "https://github.com/ros2/common_interfaces", "lyrical"),
242+
Repository("test_interface_files", "https://github.com/ros2/test_interface_files", "lyrical"),
243+
Repository("rmw_implementation", "https://github.com/ros2/rmw_implementation", "lyrical"),
244+
Repository("rcl_logging", "https://github.com/ros2/rcl_logging", "lyrical"),
245+
Repository("ros2_tracing", "https://github.com/ros2/ros2_tracing", "lyrical"),
246+
],
215247
'rolling': [
216248
Repository("micro-CDR", "https://github.com/eProsima/micro-CDR", "rolling", "ros2"),
217249
Repository("Micro-XRCE-DDS-Client", "https://github.com/eProsima/Micro-XRCE-DDS-Client", "rolling", "ros2"),
@@ -243,5 +275,6 @@ class Sources:
243275
'iron': ['test_tracetools', 'rcl_logging_spdlog', 'rcl_yaml_param_parser', 'rclc_examples'],
244276
'jazzy': ['test_tracetools', 'rcl_logging_spdlog', 'rcl_yaml_param_parser', 'rclc_examples', 'lttngpy'],
245277
'kilted': ['test_tracetools', 'rcl_logging_spdlog', 'rcl_yaml_param_parser', 'rclc_examples', 'lttngpy', 'rmw_security_common'],
278+
'lyrical': ['test_tracetools', 'rcl_logging_spdlog', 'rcl_logging_implementation', 'rcl_yaml_param_parser', 'rclc_examples', 'lttngpy', 'rmw_security_common', 'rosidl_buffer_py', 'test_rmw_implementation', 'rosidl_buffer_backend_registry'],
246279
'rolling': ['test_tracetools', 'rcl_logging_spdlog', 'rcl_yaml_param_parser', 'rclc_examples', 'lttngpy', 'rmw_security_common']
247280
}

0 commit comments

Comments
 (0)