Message dataclasses: the payloads that cross the seam, and the ROS2 facts they carry.
A ROS2 message reaches the rest of this package as an instance of a frozen dataclass built here,
never as an rclpy object. There is one dataclass per ROS2 message type, built once and cached.
It carries its MessageDescription on the ros2 class variable, so Projections, field
selection and the publish-time guard read ROS2 facts from a plain value.
The structure is taken by introspection over the imported interface class, not by parsing definition text, which gets four things wrong: fixed-size arrays (double[9] is nine values), fields named like a constant (points beside POINTS), string bounds (string<256>) and float widths (float32 against float64).
Dataclasses built at run time have no static field set, so the types come from stubs beside this
module. <package>.py and <package>.pyi are generated from the definition catalog for
interface packages without a binary release. from opensmi.ros2.runtime.messages.neo_msgs2
import USBoardV2 type-checks against the stub and resolves through message_dataclass
at run time, to the dataclass a Binding of that type holds.
| Module | industrial |
The ROS2 interface package industrial_msgs, as message dataclasses. |
| Module | motoros2 |
The ROS2 interface package motoros2_interfaces, as message dataclasses. |
| Module | neo |
The ROS2 interface package neo_msgs2, as message dataclasses. |
| Module | neo |
The ROS2 interface package neo_srvs2, as message dataclasses. |
From __init__.py:
| Class | |
The three message types one ROS2 action carries, resolved together. |
| Class | |
A fixed-size array: exactly length elements, always. |
| Class | |
One field of a ROS2 message. |
| Class | |
Base of every message dataclass built by message_dataclass. |
| Class | |
Everything the rest of the package needs to know about one ROS2 message type. |
| Class | |
A field whose type is another ROS2 message. |
| Class | |
A single number, boolean or character. |
| Class | |
A variable-length sequence, bounded or not. |
| Class | |
The two message types one ROS2 service carries, resolved together. |
| Class | |
A string field, with the bound the interface declared for it. |
| Function | action |
Return the goal, feedback and result message dataclasses of a ROS2 action type. |
| Function | build |
Build the frozen dataclass a MessageDescription describes. |
| Function | canonical |
Return package/kind/Name, filling in msg for the two-part ROS2 shorthand. |
| Function | element |
Return the scalar type a field holds, unwrapping an array or a sequence. |
| Function | is |
Return whether a field is an array or sequence of bytes, and so renders as bytes. |
| Function | is |
Return whether a field is one value: a primitive or a string, neither nested nor repeated. |
| Function | message |
Return the message dataclass for a ROS2 message type, importing the interface package. |
| Function | parse |
Model one entry of an interface class's field-type mapping. |
| Function | repeated |
Return the message type one field repeats, or None when it repeats no message. |
| Function | service |
Return the request and response message dataclasses of a ROS2 service type. |
| Constant | ACTION |
The three message types a ROS2 action is made of, as the generated class spells them. |
| Constant | SERVICE |
The two message types a ROS2 service is made of, as the generated class spells them. |
| Type Alias | |
What may appear inside an array or a sequence, and on its own as a scalar field. |
| Type Alias | |
Every shape a ROS2 message field can have. |
| Type Alias | |
The primitive ROS2 field types this Runtime models, spelled as a .msg file spells them. |
| Function | _annotation |
Return the Python type a modelled field is annotated and decoded as. |
| Function | _build |
Build and memoise the dataclass for one canonical ROS2 type name. |
| Function | _parse |
Model the scalar type inside an array, inside a sequence, or standing on its own. |
| Constant | _ARRAY |
Undocumented |
| Constant | _BYTE |
Undocumented |
| Constant | _IDL |
Undocumented |
| Constant | _KINDS |
Undocumented |
| Constant | _NESTED |
Undocumented |
| Constant | _PYTHON |
Undocumented |
| Constant | _SEQUENCE |
Undocumented |
| Constant | _STRING |
Undocumented |
| Constant | _THREE |
Undocumented |
| Constant | _TWO |
Undocumented |
Return the goal, feedback and result message dataclasses of a ROS2 action type.
Synchronous and free of the Runtime, like message_dataclass.
| Parameters | |
typestr | package/action/Name. The msg shorthand is not accepted. |
| Returns | |
ActionTypes | Undocumented |
| Raises | |
InvalidMessageTypeNameError | When the name is not a three-part action name. |
MissingInterfacePackageError | When the interface package is not installed. |
UnusableMessageTypeError | When the package has no such action. |
MessageDescription, *, resolve: Callable[ [ str], type[ Message]] | None = None) -> type[ Message]:
¶
Build the frozen dataclass a MessageDescription describes.
A pure function of a value, so a test can hand it a description of a type nobody has installed.
| Parameters | |
description:MessageDescription | Undocumented |
resolve:Callable[ | How to turn a nested field's type name into its dataclass. Defaults to
message_dataclass. |
| Returns | |
type[ | Undocumented |
Return package/kind/Name, filling in msg for the two-part ROS2 shorthand.
| Raises | |
InvalidMessageTypeNameError | When the name has neither shape, or names a kind that is not one of msg, srv or action. |
Return whether a field is an array or sequence of bytes, and so renders as bytes.
Shared by the annotation and the Decoder, which must agree on which fields these are.
Return whether a field is one value: a primitive or a string, neither nested nor repeated.
What a key may be read from, and what a pair's two halves have to be.
Return the message dataclass for a ROS2 message type, importing the interface package.
Synchronous and free of the Runtime: a Binding declares its type while a Component is being constructed, before any event loop exists, and a missing interface package must fail there.
The result is cached, and two Bindings declaring the same type get the same dataclass, so isinstance checks between them hold.
| Parameters | |
typestr | package/kind/Name, or package/Name for a message. |
| Returns | |
type[ | Undocumented |
| Raises | |
InvalidMessageTypeNameError | When the name has the wrong shape. |
MissingInterfacePackageError | When the interface package is not installed. |
UnusableMessageTypeError | When the package has no such message. |
MessageTypeError | When a field has a type this Runtime does not model. |
Model one entry of an interface class's field-type mapping.
A pure function, so the type model needs no ROS2 installation to test.
| Parameters | |
text:str | The type string, as the interface class reports it (double, double[9], string<256>, sequence<uint8>, sequence<double, 3>, geometry_msgs/Point). |
nestedstr | None | The fully qualified name to give a nested type. Without it the package/Name form is read as a message type, which is wrong only for the generated wrapper types of a service or an action. |
| Returns | |
FieldType | Undocumented |
| Raises | |
MessageTypeError | When the string is a form this Runtime does not model. |
Return the message type one field repeats, or None when it repeats no message.
The field must exist, be an array or a sequence, and hold a message. The Keyed Binding and the recipe that turns such a field into a standard value both ask this.
Return the request and response message dataclasses of a ROS2 service type.
Synchronous and free of the Runtime, like action_types.
| Parameters | |
typestr | package/srv/Name. The msg shorthand is not accepted. |
| Returns | |
ServiceTypes | Undocumented |
| Raises | |
InvalidMessageTypeNameError | When the name is not a three-part service name. |
MissingInterfacePackageError | When the interface package is not installed. |
UnusableMessageTypeError | When the package has no such service. |
The three message types a ROS2 action is made of, as the generated class spells them.
They are ordinary message types (example_interfaces/action/Fibonacci_Goal).
| Value |
|
The two message types a ROS2 service is made of, as the generated class spells them.
A service package exports its members (std_srvs.srv.SetBool_Request), while an action's goal is only reachable as Fibonacci.Goal. The _Event member Jazzy adds is not listed.
| Value |
|
What may appear inside an array or a sequence, and on its own as a scalar field.
| Value |
|
The primitive ROS2 field types this Runtime models, spelled as a .msg file spells them.
| Value |
|
Undocumented
| Value |
|