Writing the Book
This page is for anyone who writes or reorganizes a page of the nano-ros Book,
the user book under book/src/. It is the charter of
RFC-0124 put as a checklist, followed by one template for each kind of page. Read the
checklist before you open a template, and check your page against it before
you ask for review.
check-book-audience reads the gated rules and refuses every departure from
them, except the findings its baseline still lists (see
The charter baseline). --charter lists each finding
with its baseline key:
python3 scripts/check-book-audience.py --charter
The checklist
Who and why
- Three purposes, stated budgets. Every page serves at least one of
education, field solutions and industrial, within its budget: a 15-minute
install and labs under two hours; 30 minutes from box to
ros2 topic echo; reproducible, auditable, offline builds (RFC-0116 D1). - Two books by reader. Application developers and porters read the Book. Contributors read this book, Internals. Contributor material in a user page moves here.
What may be in the Book
- A board enters the Book only with an emulator twin, or a track that replays its chapter (RFC-0115 D4). QEMU mps2-an385 is the concepts board. Gated: a board page whose registry rows are neither Verified nor an emulator twin of a named board is refused.
- Claims follow the registry. Board facts and status words are generated, never typed. A board, feature or integration with no registry row gets no user page. Gated (rule E refuses a typed status word).
- Only the user tier. No
nros dev, no checkout steps, no internal ids in prose. RFC numbers appear only in a closing “Design background”. Gated (rules D andcheck-user-surface-idsrefuse).
The current release only. The book describes the release it is published from, and that release keeps rolling. It keeps no list of retired names: the CLI refuses an old variable, board, knob or command spelling and names the one to use. A removal that needs more than a rename (an install layout, a board family) gets a section in Migrating from older releases. When nano-ros publishes LTS releases, the book will be versioned per release, with a migration page for each.
How it is organized
- Sections follow what the reader is doing: Start here, Get started on your board, Tutorial, User guide, Background, Reference, Extending, Releases. RFC-0124 Appendix A names every page and its sources. A page not in Appendix A needs an RFC amendment first.
- One topic, one page per type. Tutorial, how-to, explanation and reference are separate pages that link to each other. A topic has at most one page of each type. Gated: the declared type must fit the section, and two pages may not declare the same type and topic.
- Starters before depth. Every admitted board has a starter that needs only Install, twin-and-hardware boards first.
- Reference is generated from its owner: the contract format, the CLI,
the APIs,
system.toml, boards. A hand-written table that copies a generated one is deleted.
How it is written
-
Procedure first. A task page is steps. Each step is a command or an edit, followed by its expected output. The page ends with a complete working example.
-
Concepts at the point of need. Explain a concept only if it is uncommon outside nano-ros and central inside it: the bringup, the image, the contract, static pools, the execution sched tasks. Start from the example in front of the reader, not from the model. For what a ROS 2 user knows, link to the ROS 2 documentation.
-
The simplest working path first. The Tutorial runs one board in every language, the FreeRTOS MPS2-AN385 on QEMU’s user network (see One board for every language); serial links are a how-to, and WiFi is stated as deferred. The first chapter names no launch file, image or entry. One run verb,
nros run, withnros flash --monitoron hardware. -
Say plainly where nano-ros differs from ROS 2. Never imply a symmetry that is not there.
-
Every runnable step is probed on its row’s evidence. A step that cannot run yet carries an
awaitsline on its track and fails loudly. Nothing is skipped. Gated: a shell fence (bash,sh,shell,zshorfish) with noprobe=is refused. A fence that is not a step, such as output, a file’s contents or a command with a placeholder the reader fills in, is tagged with what it is (text,console,toml), notbash. -
Budgets. Gated:
Type Words of prose how-to 300–1,500 tutorial chapter 1,500–3,000 explanation 800–2,500 reference no limit, but tables and lookups only A page under 300 words is merged into its parent. Rust, C and C++ variants of one step are tabs on one page, not parallel pages.
Voice
Follow the Google developer documentation style guide: second person, present tense, active voice, sentence-case headings, and no “simply”, “just” or “easy”. Name a thing once, then use that name throughout.
The charter baseline
The gate refuses every finding of the rules above, except the ones
.config/book-charter-baseline.txt lists: the findings that were left in the
book when the rules began to refuse, in pages that other open work owns or
that no track replays yet. Each row names one finding by the key --charter
prints in its first column, then its reason or owner:
guide/rmw/use-cyclone-dds.md unprobed-steps=7 # probe coverage follow-up
The baseline only shrinks:
- A finding it does not list is refused. Fix it; do not add a row.
- A row that no longer fires is refused until you remove it.
- A counted row (
unprobed-steps=N) is refused when the page gains a step with no probe fence, and when it loses one, until you lowerNto the new count.
To remove a row, fix its finding, then delete or lower the row in the same commit:
-
Find the steps:
python3 scripts/check-book-audience.py --charterprints each finding’s lines. -
Fix each one. Give a runnable step a
probe=on a track that replays the page (a[[probe]]row inpackages/boards/board-support.toml, thenpython3 scripts/gen-board-support.pyand a recipe injust/probe.just). A step that cannot run yet still gets itsprobe=, on a track whoseawaitsnames why. Tag a fence that is not a step with what it is. Merge a page under the floor into its parent throughbook/page-map.tomlandscripts/book-move.py, so it keeps a redirect. -
Check that each track you touched still extracts:
PROBE_EXTRACT_ONLY="$PWD/track.sh" PROBE_TRACK=installed PROBE_PLATFORM=<track> \ bash scripts/probe/run-bootstrap-probe.sh && bash -n track.sh python3 scripts/check-book-probe-tracks.py -
Run
python3 scripts/check-book-audience.py. It names the row to delete or the count to lower.
Declare the type and level
Every hand-written user page carries one declaration on the line after its title. Generated pages are reference pages and carry none.
# Configure zenoh
<!-- type: how-to · level: 2 -->
The rendered book shows the declaration as a badge under the title, such as
“How-to · Level 2: Building real applications”, so a reader sees the page’s
kind and what it assumes. scripts/mdbook-level-badge.py renders it, with the
level names of the table below.
Add · topic: <slug> when a topic has pages of several types, so the gate
can tell that each type appears once:
<!-- type: tutorial · level: 2 · topic: contract -->
Topic levels
A page may assume only topics at its own level or below. It lists them on a “needs first” line, and the gate refuses a link to a higher level.
| Level | Topics | Where |
|---|---|---|
| 1. First contact | install; a board starter; run a talker; what you built; add a node; pick and configure the RMW | Start, starters, Tutorial 1–4 |
| 2. Building real applications | your own message; services and actions; parameters and launch files; the contract and sizing; another target; ROS 2 interop and QoS; a serial link; logging; workspace layout; mixing languages | Tutorial 5–10, User guide |
| 3. Production and tuning | configuring an image; build profiles; offline and vendored builds; deploying; static memory; scheduling and timing; throughput; bridges; porting a ROS 2 node | User guide, Background |
| 4. Extending nano-ros | a board, platform or transport; a custom RMW backend; runner and command packages; API design | Extending, then Internals |
A reference page carries the level of the most advanced topic it describes. Anyone may look it up.
Organizing the sidebar
The sidebar is the book’s table of contents, and a reader scans it before reading anything. These rules keep it short enough to scan. They follow Diátaxis, the Kubernetes page content types, the Ubuntu developer docs structure and Rust’s error codes index, which keeps one page per code out of the Rust books.
- A list of like things is one page. Boards, forks, diagnostic codes,
retired names: one generated page, an index table at the top, then one
section per item with a stable anchor (
#<name>) and a “Back to the list” link. The sidebar shows the page, and the page’s headings show the items. Link to an item by its anchor. Examples: Board Support Levels, Forks nano-ros carries, Diagnostic codes. - No page that is one table or one paragraph. It is a section of the page it belongs to (checklist item 15: under 300 words merges into its parent).
- Shallow. At most two levels under a section: a group, then its pages.
A group is a heading the page map names (
GROUPSinscripts/lib/book_pages.py), from the page’s directory or itssidebar_grouprow key, so grouping never moves a page or changes its URL.SUMMARY.mdis generated (scripts/book-move.py --summary); never type a group into it. - Short groups. About a dozen entries per section or group at most. Past that, group related pages. A group whose pages need orientation gets a landing page saying what each is for.
- Titles by type. Tutorial and how-to titles are verb phrases (“Add a board”); reference and explanation titles are noun phrases (“Diagnostic codes”). Siblings follow one pattern. No package name, code or internal id as a sidebar title.
- Order by need. Within a section, the order a reader needs pages: task order, or the most used first. Not alphabetical, not by when a page was written.
- Folding pages keeps their URLs. A page folded into another becomes a
merge-intorow inbook/page-map.toml, and each released URL gets a redirect inbook/book.tomlto its section’s anchor.
Languages in tabs
When a step has a Rust, a C and a C++ version, write the versions as one tab group. The rendered book shows them as tabs, and the language a reader picks switches every group on the page and stays picked on the next page.
<!-- tabs -->
#### Rust
```rust
executor.spin_once(10)?;
```
#### C
```c
rclc_executor_spin_some(&executor, 10);
```
#### C++
```cpp
executor.spin_some(10);
```
<!-- /tabs -->
It renders as:
#![allow(unused)]
fn main() {
executor.spin_once(10)?;
}
rclc_executor_spin_some(&executor, 10);
executor.spin_some(10);
The rules:
<!-- tabs -->and<!-- /tabs -->each stand alone on a line, at column 0, so a group cannot sit inside a list or a quote.- The first line after
<!-- tabs -->(blank lines aside) is a heading whose text isRust,CorC++. Every heading at that level inside the group starts the next tab. Use one level below the section you are in. - A tab holds any markdown: prose, several fences, a list. Deeper headings are content. A group has at least two tabs and each language once.
- Show only the languages the step has. Rust first, then C, then C++.
On GitHub, which does not run the preprocessor, a group reads as one sub-heading per language. The tab headings do not appear in the rendered page, so do not link to them.
A probe step inside a tab belongs to that tab’s language. Give each
language’s version of a step the same probe=NN, and set lang (rust, c
or cpp) on the [[probe]] row of each track that replays the page, in
packages/boards/board-support.toml. The extractor keeps that language’s
blocks and every untabbed one, and it refuses a tabbed step on a track that
names no language. The charter counts a group’s prose once, as its longest
tab.
scripts/mdbook-lang-tabs.py renders the groups and scripts/lib/book_tabs.py
parses them. check-book-audience refuses a malformed group.
Code blocks
The reader types into a terminal and edits in an editor such as VS Code. A
page shows each of those as what it is, so the reader can tell at a glance
what to type, what to expect and what to change. The rendered book labels a
block from its fence (book/theme/nros.css); the probe replays the same
blocks (scripts/probe/extract-book-steps.py).
| The block holds | Fence | Renders as |
|---|---|---|
| commands the reader types, probed | ```bash probe=NN | Terminal, accent edge |
a command that is not a step (a <placeholder>, hardware only) | ```console | Terminal |
| what a program prints | ```text | Output, tinted, wraps |
| a new file | ```<lang> file=PATH | the path above the file |
| lines added to the end of a file | ```<lang> append=PATH | “Add to the end of PATH” |
| a change to part of a file | ```diff edit=PATH | “In PATH, change the marked lines” |
| a directory layout | ```tree | coloured, never wraps |
| other plain text (a formula, a sketch) | ```txt | no label |
- A Terminal block holds commands only. No output, no file content, no
cat > PATH <<'EOF'. One block may hold the few commands of one step. - Show the output, short. After a command whose result matters, show
what it prints in its own Output block, trimmed to the lines the reader
looks for. A value that changes per run is written
…(data: 'Hello World: …'); in aprobe-expectblock the run must print the text before the…. Say “trimmed” when you cut lines. - No text tools for the reader’s work. A Tutorial or how-to never edits
a file with
sed,awkorperl, never writes one with a heredoc, and does not pipe output throughgrep,tee,headorcutfor the reader to read. Edits are file, append or diff blocks. Usegreponly when the output runs to pages and the reader needs one line of it, and say so. - A diff shows where. Keep two or three unchanged lines (a space first)
around the
-and+lines, enough for the reader to find the place in an editor, and for the probe: the unchanged and-lines must occur in the file exactly once. - Several blocks, one step. A command, the file it needs and the command
after it are three blocks under one
probe=NN; the probe runs them in page order. nros runruns until Ctrl-C. A Tutorial chapter or starter runs it plainly, shows the first lines it prints, and tells the reader to press Ctrl-C.--expectand--timeoutare for scripts and CI: the deploy how-to and the CLI reference name them; a chapter does not. The probe asserts the Output block (probe-run=SECS,probe-expect=NN), andprobe-keepkeeps a run going for the step after it.- A command that finishes is a plain step, which must exit 0. When its
output is the point (a refusal,
nros pin’s answer), tag itprobe-run=SECS probe-exit=0, orprobe-exit=failfor a refusal. It then runs to its end and its exit status is checked as well as its Output block. Aprobe-runstep withoutprobe-exitis stopped as soon as its output prints, which is right only for a command that runs until stopped. - Trees fit the page. Each line within about 80 columns; a note longer than a few words goes in the prose under the tree.
- Width. Commands and source lines stay within about 80 columns: break a
long command with
\continuations, one argument or package per line.
The Tutorial project’s tree
The Tutorial grows one workspace, sensor_ws, chapter by chapter. A chapter
that adds or changes files shows the part of the tree it touches, near its
start or where the work begins, and marks each file it adds (new) and each
it changes (changed):
sensor_ws/
└── src/
├── sensor_node/
└── sensor_node_bringup/
├── system.toml (changed)
└── launch/
└── system.launch.xml (new)
Show only the branches the chapter touches, with their parents for orientation; leave the rest out. The reader then sees where this chapter’s work sits in what the earlier chapters built.
One board for every language
Every Tutorial chapter runs on one board in Rust, C and C++ alike, the
FreeRTOS MPS2-AN385 in QEMU (mps2-an385-freertos), so a tab differs only in
the code, never in the board, the commands or the output. A board’s own
page or starter shows the others.
Consistency and length
- Name a thing once and keep the name: “router”, not “router” in one paragraph and “zenoh daemon” in the next; “image”, “bringup”, “board” as the glossary defines them.
- Headings are sentence case and verb phrases on task pages.
- A step is: one sentence saying what and why, the block, its output, one or two sentences on what the output shows. Explanations longer than that go in “What just happened” or a Background page.
- The budgets in checklist item 15 count prose only, not code blocks. A revision that adds a block takes words out elsewhere: prefer a block the reader can see to a paragraph describing it.
Templates
Each template gives the headings in order. Replace the comments. Keep the headings a reader scans for, even when a section is one line.
Tutorial chapter
One chapter of the one Tutorial project, run on a Verified row, small enough for a two-hour lab.
# <What the reader does, as a verb phrase>
<!-- type: tutorial · level: <1|2> -->
**Needs first:** [<previous chapter>](<link>)
<!-- One paragraph: what the reader has at the end, stated as output they will see. -->
## <Step 1, a verb phrase>
<!-- The command or edit. Then the output they should see. -->
## <Step n>
## What just happened
<!-- The ONE nano-ros concept this chapter introduces, explained from the
example the reader just ran. Link to Background for the full model. -->
## Next
<!-- The next chapter, and the User guide pages that go deeper. -->
How-to
One task, for a reader who already knows what they want.
# <Task, as a verb phrase: "Use a serial link">
<!-- type: how-to · level: <2|3|4> -->
**Needs first:** [<page>](<link>)
<!-- One sentence: when you would do this. -->
## Before you start
<!-- What must already be true: board, packages, a working project. -->
## Steps
1. <!-- A command or edit. -->
<!-- Its expected output. -->
## Example
<!-- One complete, working example the reader can copy whole. -->
## If it doesn't work
<!-- The two or three failures a reader actually meets, each with its fix. -->
## See also
<!-- The reference page for the options; the Background page for the why. -->
Board starter
The Tutorial’s chapter 1 done on one board, needing only Install. About 1,500 words. The status header and the list of starters are generated from the registry; do not type them.
# Get started on <board>
<!-- type: how-to · level: 1 -->
**Needs first:** [Install](<link>)
## What you need
## Provision
## Scaffold the project
## Run it in the <emulator or twin>
## Flash the board
<!-- Only when the row names `hardware`. -->
## See it in ROS 2
## If it doesn't work
## Next
Platform page
What the platform’s starter leaves out: configuration, board notes, deeper
tasks. Needs only Tutorial 1–2 and the starter. It sits in the User guide
group its row’s generated status word names: the board row names the page
with book_platform in packages/boards/board-support.toml, and
scripts/book-move.py --summary nests it under that group, so neither the
group nor the status header is typed. check-book-audience refuses
a page whose group and row disagree, and a page whose rows sit in two groups,
which splits by status. Each deeper task’s commands are probe= steps on a
track that replays the starter first (after).
# <Platform>
<!-- type: how-to · level: <2|3> -->
**Needs first:** [Run a talker on an emulated board](<link>), [What you just built](<link>), [Get started on <board>](<link>)
<!-- BEGIN GENERATED by scripts/gen-board-support.py: platform status -->
<!-- END GENERATED platform status -->
## Configure the platform
## Board notes
## <Deeper task, one heading each>
## Reference
<!-- Links to the generated board pages. -->
Explanation
A Background page: the nano-ros “why” a reader needs before production work.
# <The thing explained, as a noun phrase>
<!-- type: explanation · level: 3 -->
<!-- Open with a concrete example the reader has already run or will run:
a build, a log line, a measured number. Then explain the model behind
it. No steps. -->
## <Part of the model>
## Where nano-ros differs from ROS 2
<!-- Stated plainly, when it differs. -->
## Design background
<!-- The only place an RFC number appears. -->
Reference
Lookup only: tables, keys, options. If the page’s content has an owner (the CLI’s help, a schema, a generator), generate the page from it instead.
# <Thing> reference
<!-- type: reference · level: <level of its most advanced topic> -->
<!-- One sentence: what this lists and where it is generated from. -->
| Name | Type | Default | Meaning |
| --- | --- | --- | --- |
Before you ask for review
State in the PR description, for every page you add or rewrite:
- its type, level and section in RFC-0124 Appendix A;
- the principles you checked it against, and any you could not meet yet,
with the reason (for example, a step waiting on a CLI change, with its
awaitsline); - the output of
python3 scripts/check-book-audience.py --charterfor that page.
Moves go through book/page-map.toml and scripts/book-move.py, so every
moved page keeps a redirect. Land the work in section-sized PRs, rebased onto
main rather than merging main in.