Hardware profiles¶
If your robot is a bare microcontroller and an H-bridge, describe its parts instead of writing firmware. From the profile, Quatern Code derives a safe motor cap, generates the firmware, a wiring table and the protocol, flashes the board, and checks the real robot against the description with a wheels-up self-test. Nobody edits firmware source.
A robot whose base already drives its own motors (a TurtleBot, a Clearpath base, anything with micro-ROS or a vendor driver) doesn't need firmware. Give it a profile in interface-only mode instead.
quatern profile init --robot mybot --rated-v 6 --battery "2S li-ion" \
--describe "Arduino Uno, L298N, two TT motors, H206 slot sensors with 20-slot discs, 65 mm wheels"
quatern firmware build --robot mybot # sketch, quatern_config.h, WIRING.md, PROTOCOL.md
quatern firmware flash --robot mybot # arduino-cli compile + upload, then read the board back
quatern selftest --robot mybot --wheels-up # which sensor is which, counts per turn, sides, direction
quatern profile check --robot mybot # what the hardware deploy gate will say
What a profile is¶
The profile is the lowlevel section of the robot's <name>.quatern.json: the board, the motor driver, the motors, the wheel sensors, the battery and the drivetrain. Every value records where it came from:
| Source | Meaning |
|---|---|
user |
You typed or confirmed it. |
preset |
From a known kit. |
measured |
Measured by the self-test. |
described |
Read from your plain-English description. Not confirmed until you set it. |
detected |
Found on USB. Not confirmed until you set it. |
default |
A documented default, such as an L298N's typical 2 V drop. |
unknown |
Nobody knows yet. Never filled in with a guess. |
quatern profile show lists every field with its source, the cap, the pin table and the self-test record:
hardware profile of c101.default (firmware mode), profile 268dde8b213722aa
field value source
mode "firmware" user
controller.board "uno" user
motor_driver.type "mosfet_hbridge" user
motor_driver.part "DROK XY-160D" user
motor_driver.voltage_drop_v 0.1 user
motors.count 4 user
motors.rated_v 6.0 user
motors.no_load_rpm_at_rated null unknown
motors.wiring "paired_per_side" user
encoders.type "single_channel" user
encoders.per_rev 20 user
power.chemistry "li_ion" user
power.cells 2 user
drivetrain.wheel_diameter_m 0.065 user
drivetrain.track_width_m.from "urdf" user
...
PWM cap: 0.687 (PWM 175): 6 V motors / (8.40 V full - 0.1 V driver drop) x 0.95 = 0.687
firmware: 3b8675890967caef
...
self-test: not run for this profile
The profile hash covers the values (not their sources). It's written into the generated firmware, reported by the board, and keys the self-test record, so a test passed on one profile never counts for another.
Create a profile¶
Only two things are needed up front: the motors' rated voltage and the battery's chemistry and cell count. Anything else may be "don't know", and is filled in from a preset, your description, USB detection and the self-test, in that order. A later step never overwrites a value you set.
profile init says what it read and what's still missing:
from your description: motor_driver.type = l298n, motor_driver.part = L298N, motor_driver.pin_model = en_in1_in2, motor_driver.channels = 2, motor_driver.voltage_drop_v = 2.0, controller.board = uno, encoders.type = single_channel, encoders.part = LM393/H206 slot-type speed sensor, encoders.edges = both, motors.part = TT gear motor, motors.count = 2, encoders.per_rev = 20, encoders.per_rev_unit = slots, drivetrain.wheel_diameter_m = 0.065
wrote the hardware profile into ~/.quatern/robots/mybot.quatern.json
PWM cap: 6 V motors / (8.40 V full - 2 V driver drop) x 0.95 = 0.891
still needed: motor_driver.type = 'l298n' was described, not confirmed: `quatern profile set --robot mybot.default motor_driver.type l298n` to confirm it
still needed: motor_driver.voltage_drop_v = 2.0 was described, not confirmed: `quatern profile set --robot mybot.default motor_driver.voltage_drop_v 2.0` to confirm it
next:
quatern firmware build --robot mybot.default (sketch, WIRING.md, PROTOCOL.md)
quatern firmware flash --robot mybot.default
quatern selftest --robot mybot.default --wheels-up (wheels off the ground)
| Flag | Meaning |
|---|---|
--rated-v V |
The motors' rated voltage: the top of a range like "3–6 V". |
--battery TEXT |
Chemistry and cells, for example "2S li-ion" or "3S lipo". |
--preset NAME |
Start from a known kit. |
--describe TEXT |
Your parts in plain English. Values read from it are marked described until you confirm them. |
--detect |
Find the board on USB. |
--agent |
Have the agent read --describe and fill in the profile. |
Confirm or change a field¶
quatern profile set sets one field and so confirms it. unknown clears it.
$ quatern profile set --robot mybot motor_driver.type l298n
motor_driver.type = 'l298n' (user)
PWM cap: 6 V motors / (8.40 V full - 2 V driver drop) x 0.95 = 0.891
--source measured records a value you measured yourself.
Presets¶
$ quatern profile presets
Presets (quatern profile init --preset NAME):
c101-xy160d-2s C101 4WD skid-steer: Uno, DROK XY-160D, 4 TT motors paired per side, 4 LM393/H206 slot sensors (20 slots), 65 mm wheels, 2S Li-ion
c101-xy160d-3s C101 4WD skid-steer: Uno, DROK XY-160D, 4 TT motors paired per side, 4 LM393/H206 slot sensors (20 slots), 65 mm wheels, 3S LiPo
A preset is a profile without the parts that belong to one unit (motor inversion, measured speeds, sense-line calibration), plus a name, a description and a shopping list. quatern profile export --robot mybot --as-preset my-kit turns yours into one, but only once every field is confirmed (user, preset or measured) and the self-test has passed for it:
error: only confirmed profiles are shared; unconfirmed: motors.part, motors.count, motor_driver.part, ...
quatern profile detect lists boards on USB (an Uno by its USB id, including common CH340 clones).
The motor cap¶
The firmware never drives the motors above their rated voltage, whatever the host sends:
| Robot | Battery full | Driver drop | Cap | PWM |
|---|---|---|---|---|
| C101: 6 V motors, DROK XY-160D, 2S Li-ion | 8.4 V | 0.1 V | 0.687 | 175 |
| C101: same, 3S LiPo | 12.6 V | 0.1 V | 0.456 | 116 |
| 6 V motors, L298N, 2S Li-ion | 8.4 V | 2.0 V | 0.891 | 227 |
The battery's full voltage comes from the chemistry and cell count (per cell: Li-ion 4.20 V, LiPo 4.20 V, LiFePO4 3.65 V, NiMH 1.45 V, lead-acid 2.15 V) unless you give it. With a battery sense pin wired, the firmware recomputes the cap from the measured voltage every 100 ms, so a sagging pack keeps its top speed without overvolting a fresh one; a reading that can't be right falls back to the static cap.
Unknown rating or battery. The cap drops to a conservative 0.25: enough to turn the wheels on a stand for the self-test. A hardware deploy is refused until both are known:
PWM cap: 0.250 = PWM 63/255 (CONSERVATIVE: a hardware deploy is refused); conservative cap 0.25: motor rated voltage unknown
Generate and flash the firmware¶
$ quatern firmware build --robot c101
generated ~/.quatern/firmware/c101.default/c101 (profile 268dde8b213722aa, firmware 3b8675890967caef)
PWM cap: 0.687 = PWM 175/255; 6 V motors / (8.40 V full - 0.1 V driver drop) x 0.95 = 0.687
pins:
controller pin goes to
D5 driver ENA (left, PWM capped at 175)
D4 driver IN1 (left direction)
D7 driver IN2 (left direction)
D6 driver ENB (right, PWM capped at 175)
D8 driver IN3 (right direction)
D12 driver IN4 (right direction)
D2 wheel_front_left_joint sensor signal (INT0)
D3 wheel_front_right_joint sensor signal (INT1)
A0 (D14) wheel_rear_left_joint sensor signal (pin-change)
A1 (D15) wheel_rear_right_joint sensor signal (pin-change)
5V driver logic 5V input and every sensor VCC
GND driver signal GND and every sensor GND (common ground)
wiring: ~/.quatern/firmware/c101.default/c101/WIRING.md
It writes, under ~/.quatern/firmware/<robot>.<instance>/<robot>/ (or --out DIR):
| File | Holds |
|---|---|
<robot>.ino |
The sketch: one template for every profile. |
quatern_config.h |
Only data and switches: channels, pins, encoder mode, PWM_MAX, battery values, the profile hash. |
WIRING.md |
Parts list and pin tables: controller to driver, controller to each wheel sensor, power. |
PROTOCOL.md |
The serial protocol the host bridge speaks. |
host/ |
The ROS 2 bridge for the host, configured from the profile. |
Every generated file starts with a do-not-edit line naming the profile it came from. Pins are assigned for you (PWM pins for the enables, interrupt pins first for the wheel sensors, never the serial pins) unless the profile names them, and the build stops with a plain sentence if the board runs out.
The 0.5 s command-silence stop is not a setting. The template hard-codes it and refuses to compile with anything else.
--compile also compiles the sketch with arduino-cli:
Flash¶
It builds, compiles and uploads with arduino-cli, then asks the board for its INFO frame and checks it reports this profile's firmware hash. Without --port it uses the one matching board on USB, and stops if there isn't exactly one:
Without arduino-cli, it fails with install instructions (brew install arduino-cli on macOS, then arduino-cli core install arduino:avr) and nothing is written to the board.
The wheels-up self-test¶
The self-test checks the real robot against its profile and measures what the profile couldn't know. Put the robot on a stand with every wheel off the ground.
The wheels turn
It asks THE WHEELS WILL TURN. Is the robot on a stand with every wheel off the ground? [y/N] before anything moves, and it must run at a terminal: no flag answers a motion question.
It runs in three parts:
- Firmware. Reads the board's INFO frame and stops unless the flashed firmware matches the profile.
- Hand turns. Asks you to turn each wheel forward exactly one full turn and press Enter. That says which sensor reads which wheel, and how many counts a turn is. For quadrature sensors, a turn back also checks that the second channel is really wired.
--no-hand-turnsskips this and keeps the profile's values. - Powered pulses. Drives each channel forward briefly, at a fraction of the cap, then asks
Did the left wheels spin FORWARD? [y/n]. Single-channel slot sensors count the same either way, so only you can tell.
| Check | What it catches | What it offers |
|---|---|---|
| Sensor map | The sensors read different wheels than the profile says. | The measured map. |
| Counts per turn | Slots or pulses per turn differ from the profile. | The measured count. |
| Encoder type | "Quadrature" sensors whose second channel never changes. | encoders.type single_channel, or check the B wire. |
| Sides | Driving the left channel moves the right wheels. | The swapped channel map, or swap the motor leads. |
| Direction | A side spins backwards. | motor_invert for that side. |
| Wheel not counting | A sensor stays at zero while its sibling counts. | The pin to check, and that the disc passes through the slot. |
| Speed | Measured speed far from what the rated rpm predicts. | The battery or driver drop isn't what the profile says. Skipped when the rated rpm is unknown. |
Measured values are written into the profile as measured. When a fix changes the firmware (a different sensor map, an inverted side), the test doesn't pass yet: rebuild, flash and run it again. The result is recorded against the profile hash; quatern profile check shows it.
The first floor run¶
Slot sensors can't tell forward from backward, so the first hardware deploy after the self-test checks once more: against a pose source independent of the wheel sensors (the localizer's estimate from lidar, camera or depth; for quadrature sensors, wheel odometry too), a forward command must have moved the robot forward. A reversed side is recorded, and the gate refuses until it's fixed.
What the deploy gate checks¶
For a robot with a profile, a hardware deploy is refused until:
- every safety value is known and confirmed: the motors' rated voltage, the battery, the driver type and its voltage drop;
- the wheels-up self-test has passed for this profile;
- the flashed firmware was built from this profile;
- the first floor run, if there's been one, didn't show a reversed side.
quatern profile check shows exactly what the gate will say, and exits 1 while it refuses:
$ quatern profile check --robot mybot
hardware profile of mybot.default: a hardware deploy is refused:
- hardware: hardware profile: motor_driver.type = 'l298n' was described, not confirmed: `quatern profile set --robot mybot.default motor_driver.type l298n` to confirm it
- hardware: hardware profile: motor_driver.voltage_drop_v = 2.0 was described, not confirmed: `quatern profile set --robot mybot.default motor_driver.voltage_drop_v 2.0` to confirm it
- hardware: the wheels-up self-test has not passed for this profile: run `quatern selftest --robot mybot.default --wheels-up`
self-test: not run for this profile
Changing any value changes the profile hash, so the self-test has to pass again.
Interface-only mode¶
Use interface mode when something other than Quatern Code's firmware already drives the motors: micro-ROS, a vendor driver, or any commercial base. Nothing is generated or flashed, and the profile only needs the battery.
quatern profile init --robot turtlebot4
quatern profile set --robot turtlebot4 mode interface
quatern profile set --robot turtlebot4 power.chemistry li_ion
quatern profile set --robot turtlebot4 power.cells 4
$ quatern firmware build --robot turtlebot4
error: turtlebot4's profile is in interface mode: nothing to build or flash
Instead of the wheels-up test, the self-test runs at the robot's ROS 2 interface: a slow, straight nudge of about 15 cm through its hardware target, checked against its odometry. The robot is on the floor and moves.
quatern selftest --robot turtlebot4 --interface
quatern selftest --robot turtlebot4 --interface --target hardware
It asks THE ROBOT WILL MOVE about 15 cm forward. Is the space ahead clear? [y/N]. Until it has passed for the current profile, the hardware deploy gate refuses:
$ quatern profile check --robot turtlebot4
hardware profile of turtlebot4.default: a hardware deploy is refused:
- hardware: the interface check has not passed for this profile: run `quatern selftest --robot turtlebot4.default --interface` (a short forward nudge on the floor, checked against /odom)
Use firmware mode for a bare microcontroller and H-bridge, interface mode when anything else drives the motors. Never both on one robot.
No profile, no profile checks
A profile is optional. A robot without a lowlevel section deploys exactly as before: the gate's profile checks only apply to robots that have one.
The C101¶
The C101 test rover ships with a profile (Arduino Uno, DROK XY-160D, four TT motors paired per side, four LM393/H206 slot sensors, 2S Li-ion: cap 0.687, PWM 175). Its firmware is that profile's generated output. For the 3S LiPo pack, switch with quatern profile init --robot c101 --preset c101-xy160d-3s (cap 0.456, PWM 116).