-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add ROS2 message support #10538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add ROS2 message support #10538
Conversation
Adds ROS2 message type support to the rclcpy module. Creating a Publisher now requires a ROS message type - all future messages must adhere to that message type. A small group of test messages are available in the std_msgs submodule of rclcpy, including Int32 and Bool. Message type detection is done through a type registry, and the appropriate C level information passed to the Micro-ROS interface. Ideally, future messages and message packages will be supported with an automated class and registry generator. Due to MicroROS restrictions, custom user message types cannot be supported without rebuilding Circuitpython. API changes: Removes the test publisher function `publish_int32` and replaces it with the correct `publish` function, which accepts a message object. Adds the MsgType parameter to publisher creation. Adds the std_msgs module to the module root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi - some suggestions. I will make this a draft PR for now, since you are going to do more. Also awaiting doc for several new constructors, etc. Otherwise it looks quite clean.
You could use mp_arg_parse_all_kw_array()
even on the simple construtors, but maybe this is simpler and less code.
static mp_obj_t bool_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { | ||
mp_arg_check_num(n_args, n_kw, 0, 1, true); | ||
rclcpy_std_msgs_bool_obj_t *self = m_new_obj(rclcpy_std_msgs_bool_obj_t); | ||
self->base.type = &rclcpy_std_msgs_bool_type; | ||
|
||
if (n_args == 1) { | ||
self->data = mp_obj_is_true(args[0]); | ||
} else { | ||
self->data = false; | ||
} | ||
return MP_OBJ_FROM_PTR(self); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can (and should) use the new mp_obj_malloc()
or mp_obj_malloc_with_finaliser()
(if you need a finaliser) instead of the old m_new_obj()
and setting the base.type
explicitly. Take a look at some other make_new
s in existing modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, my bad. Was referencing old stuff from usermod for this bit.
// This file is part of the CircuitPython project: https://circuitpython.org | ||
// | ||
// SPDX-FileCopyrightText: Copyright (c) 2025 Lucian Copeland | ||
// | ||
// SPDX-License-Identifier: MIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were these going to be omitted or moved to shared-module/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured I would post the "default" structure first before trying any shenanigans. I'll investigate the microcontroller/ResetReason
example you mentioned to see if it's a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make sure the overall module and class structure looked acceptable, since I wasn't able to find other shared-bindings modules that attempt large class collections like this.
Adds ROS2 message type support to the rclcpy module. Creating a Publisher now requires a ROS message type - all future messages must adhere to that message type. A small group of simple test messages are available in the
std_msgs
submodule of rclcpy, including Int32 and Bool. Message type detection is done through a type registry, and the appropriate C level information passed to the Micro-ROS interface. Ideally, future messages and message packages will be supported with an automated class and registry generator. Due to MicroROS restrictions, custom user message types cannot be supported without rebuilding Circuitpython.Putting this up a little early to get eyes on my implementation of the registry and file arrangement while I work on updating the documentation and cleaning up formatting and translation checks. Tested for functionality with ROS2 Jazzy, and is working as expected.
Example:
API changes to
rclcpy
publish_int32
and replaces it with the correctpublish
function, which accepts a message object.