Skip to content

Commit 02c1c52

Browse files
committed
New docs
1 parent 33577f2 commit 02c1c52

1 file changed

Lines changed: 121 additions & 1 deletion

File tree

src/pycyphal2/__init__.py

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,127 @@ async def main():
4242
4343
### Name resolution
4444
45-
The topic naming system shares many similarities with ROS.
45+
The topic naming system shares many similarities with [ROS Names](https://wiki.ros.org/Names).
46+
47+
Name resolution is the process by which a topic name passed to `node.advertise()` or `node.subscribe()` is resolved to a topic name as used on the Cyphal network.
48+
49+
There exist 4 kinds of topic names in Cyphal, used effectively they allow the developer to split up complex systems into smaller sub-systems, simplifying development and debugging.
50+
51+
#### 1. Relative Name
52+
53+
A relative name is a name that does not start with '/' or `~/`.
54+
55+
```
56+
sensor/temperature
57+
cmd_vel
58+
camera/image_raw
59+
```
60+
61+
It's resolved name is prefixed with the node namespace.
62+
63+
| Input name | Namespace | Home | Resolved name |
64+
| ----------------- | --------- | ---- | --------------------- |
65+
| `foo` | `ns` | `me` | `ns/foo` |
66+
| `foo/bar` | `ns` | `me` | `ns/foo/bar` |
67+
68+
Use case: Use relative names for topics that are specific to a node, but might be reused across multiple nodes.
69+
70+
Example: A robot contains 4 motor controllers of the same type, each has its own namespace (`motor_1`, `motor_2`, `motor_3`, `motor_4`).
71+
Using relative names, the application code is the same for all 4 motor controllers, however the topics are resolved differently based on the node namespace.
72+
73+
| Input name | Namespace | Home | Resolved name |
74+
| ----------------- | --------- | ------- | ---------------------------- |
75+
| `speed` | `motor_1` | `robot` | `motor_1/speed` |
76+
| `speed` | `motor_2` | `robot` | `motor_2/speed` |
77+
| `speed` | `motor_3` | `robot` | `motor_3/speed` |
78+
| `speed` | `motor_4` | `robot` | `motor_4/speed` |
79+
80+
#### 2. Absolute Name
81+
82+
An absolute name starts with `/`.
83+
84+
```
85+
/temperature
86+
/diagnostics/status
87+
```
88+
89+
It ignores the node namespace.
90+
91+
| Input name | Namespace | Home | Resolved name |
92+
| ----------------- | --------- | ---- | ------------------ |
93+
| `foo` | `ns` | `me` | `foo` |
94+
| `foo/bar` | `ns` | `me` | `foo/bar` |
95+
96+
Use case: Use absolute names for topics that are shared across multiple nodes.
97+
98+
Example: Shared system topics like `/log`, since multiple nodes may publish to the same topic.
99+
Conversely, topics like `/battery_voltage` that might be sourced from multiple nodes but need one single source of truth for other nodes like the motor controllers to subscribe to.
100+
101+
| Input name | Namespace | Home | Resolved name |
102+
| --------------------- | --------------- | ------- | ------------------ |
103+
| `/log` | `cpu` | `robot` | `/log` |
104+
| `/battery_voltage` | `battery_1` | `robot` | `/battery_voltage` |
105+
106+
#### 3. Homeful Name
107+
108+
A homeful name starts with `~` of `~/`.
109+
110+
```
111+
~/config
112+
```
113+
114+
Note that the node namespace is ignored. Also note that `~foo` is not homeful and resolves as relative name to `ns/~foo` (this is confusing so don't use this).
115+
116+
| Input name | Namespace | Home | Resolved name |
117+
| --------------------- | --------------- | ------- | ------------------ |
118+
| `~` | `ns` | `me` | `me` |
119+
| `~/config` | `ns` | `me` | `me/config` |
120+
| `~config` | `ns` | `me` | `ns/~config` |
121+
122+
Use case: For topics tied to specific nodes. The most common use case is configuring a node's parameters or settings.
123+
124+
Example: We want to configure an antenna to transmit at a specific frequency. The antenna node has a `~/config/frequency` topic that we can publish to.
125+
126+
#### 4. Pattern Name
127+
128+
A pattern name contains wildcard `*` (matches any _single_ name segment)
129+
130+
```
131+
*/speed # matches any topic under `speed` (e.g. `motor_1/speed`, `motor_2/speed/`, `motor_3/value`, ...)
132+
```
133+
134+
or `>` (matches _zero or more_ trailing segments)
135+
136+
```
137+
sensor/> # matches any topic under `sensor` (e.g. `sensor/`, `sensor/temperature`, `sensor/pressure/`, ...)
138+
```
139+
140+
Use case: Use `*` to subscribe to a _specific_ topic coming from a undetermined number of nodes.
141+
Use `>` to subscribe to _multiple_ topics under a given namespace.
142+
143+
Example: `*/battery_pct` to subscribe to all nodes publishing battery data, of which there may be multiple per vehicle.
144+
'logs/>' to subscribe to all topics publishing under '/logs' which may contain 'log_info', 'log_warning', 'log_error' topics.
145+
146+
#### Extra functions
147+
148+
*Topping* is the process by which a unique subject ID is assigned upon initialization.
149+
For some applications that require a high level of reliability, determinism is required and can be achieved by using `#` to pin a topic to a specific subject ID.
150+
151+
```
152+
motor/speed#1234
153+
```
154+
155+
The resolved topic name is 'motor/speed' and the subject ID is fixed to 1234.
156+
157+
*Remapping* lets a node replace one name with another before final resolution.
158+
This can be useful when trying to match the expected topic name from one node to another (when integrating multiple subsystems).
159+
160+
```
161+
node.remap({"sensor/temperature": "temp"})
162+
```
163+
164+
Now any topic name matching `sensor/temperature` will be remapped to `temp` before final resolution.
165+
46166
A valid name contains printable ASCII characters except space (ASCII codes [33, 126]).
47167
Normalized names do not have leading or trailing segment separators `/` and do not have consecutive separators.
48168
Every node should have a unique name, which is called its *home*; home substitution is done via `~/`.

0 commit comments

Comments
 (0)