Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
hierophect wants to merge1 commit intoadafruit:main
base:main
Choose a base branch
Loading
fromhierophect:rclcpy-msg

Conversation

@hierophect
Copy link
Collaborator

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 thestd_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:

importos,wifi,timeimportrclcpyprint("connecting...")wifi.radio.connect(ssid=os.getenv('CIRCUITPY_WIFI_SSID'),password=os.getenv('CIRCUITPY_WIFI_PASSWORD'))print("my IP addr:",wifi.radio.ipv4_address)print(rclcpy.std_msgs.Int32)rclcpy.init(os.getenv('AGENT_IP'),os.getenv('AGENT_PORT'))mynode=rclcpy.Node("foo")print(mynode.get_name())mypub=mynode.create_publisher(rclcpy.std_msgs.Bool,"bar")print(mypub.get_topic_name())mymsg=rclcpy.std_msgs.Bool()mymsg.data=Truemypub.publish(mymsg)

API changes torclcpy

  • Removes the test publisher functionpublish_int32 and replaces it with the correctpublish function, which accepts a message object.
  • Adds the MsgType parameter to publisher creation.
  • Adds the std_msgs module to the module root.

Adds ROS2 message type support to the rclcpy module. Creating a Publisher nowrequires a ROS message type - all future messages must adhere to that messagetype. A small group of test messages are available in the std_msgs submodule ofrclcpy, including Int32 and Bool. Message type detection is done through a typeregistry, and the appropriate C level information passed to the Micro-ROSinterface. Ideally, future messages and message packages will be supported withan automated class and registry generator. Due to MicroROS restrictions, customuser message types cannot be supported without rebuilding Circuitpython.API changes:Removes the test publisher function `publish_int32` and replaces it with thecorrect `publish` function, which accepts a message object. Adds the MsgTypeparameter to publisher creation. Adds the std_msgs module to the module root.
@hierophecthierophect added the rclcpyMicro-ROS client module labelAug 1, 2025
Copy link
Collaborator

@dhalbertdhalbert left a 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.

Youcould usemp_arg_parse_all_kw_array() even on the simple construtors, but maybe this is simpler and less code.

Comment on lines +21 to +33
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);
}

Copy link
Collaborator

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 newmp_obj_malloc() ormp_obj_malloc_with_finaliser() (if you need a finaliser) instead of the oldm_new_obj() and setting thebase.type explicitly. Take a look at some othermake_news in existing modules.

Copy link
CollaboratorAuthor

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.

Comment on lines +1 to +5
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2025 Lucian Copeland
//
// SPDX-License-Identifier: MIT
Copy link
Collaborator

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 toshared-module/?

Copy link
CollaboratorAuthor

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 themicrocontroller/ResetReason example you mentioned to see if it's a better solution.

Copy link
CollaboratorAuthor

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.

@dhalbertdhalbert marked this pull request as draftAugust 4, 2025 16:31
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dhalbertdhalbertdhalbert requested changes

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

rclcpyMicro-ROS client module

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@hierophect@dhalbert

[8]ページ先頭

©2009-2025 Movatter.jp