Nodes describe themselves: an SDO client (Can::Sdo) reads each esphome-canopen node's TPDOs and entities (type, name, unit, range) on its first heartbeat, cached by the TPDO layout hash, decoded with no hand-written signals — can.json keeps aliases (with unit conversion) and foreign devices; design doc (NPS planning, cockpit instruments, Unigrid band) with color tokens, the dashboard in cockpit colors; starting the simulation turns the GNSS follow on, the GNSS position an arrow by its course
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-30 19:51:03 +01:00
1 parent ce290f2162
commit e92f01db12
12 files changed
+713 -76

No files matched your search

+35 -28
View File
@@ -258,39 +258,46 @@ services:
ports: ["127.0.0.1:8002:8002"]
----
`data/can.json` (`lib/maptool/can.rb`) decodes the GNSS node
`mcu-stm32-xiao-c5-2` (CANopen node 0x21, esphome-canopen's
`canopen_entities`; layout in its `OBJECT_DICTIONARY.md`): TPDO2 (0x3A1)
carries latitude/longitude as REAL32, TPDO3 (0x4A1) altitude, speed (km/h)
and HDOP as Sensor16 over their `min_value..max_value` (`value = wire *
(max - min) / 65534 + min`, 65535 unknown) and satellites as Sensor8; TPDO1 (0x2A1) the on-board IMU's pitch, roll
(-180..180°) and temperature, Sensor16 too. The compass (HMC5883L on the
same node) isn't in the firmware yet:
Our esphome-canopen nodes describe themselves: on a node's first heartbeat
maptool reads over SDO its TPDOs (`0x1800+n`, `0x1A00+n`) and, per mapped
entity, its type, name, unit and range (`canopen_entities`' OD, its
`OBJECT_DICTIONARY.md`) and decodes them with no hand-written signals
(`lib/maptool/can_discovery.rb`); cached in `data/can_nodes/<node>.json`
by the TPDO layout hash (`0x3002`:1, checked every 10 min — read again after
an OTA that changed the layout). Signals are named `<node name>.<entity
name>` (the ESPHome name, e.g. `mcu-stm32-xiao-c5-2.Latitude`, as
`/can.html` lists them); `data/can.json` only maps the ones the app uses to
its names, with a unit conversion where needed (the node's km/h → m/s).
`"signals"` stays for devices that don't describe themselves (the car
bridge), `"discover": false` turns it off:
----
{ "interfaces": ["can0"],
"signals": [
{ "name": "gnss.lat", "id": "0x3A1", "byte": 0, "type": "f32" },
{ "name": "gnss.lon", "id": "0x3A1", "byte": 4, "type": "f32" },
{ "name": "gnss.alt", "id": "0x4A1", "byte": 0, "type": "u16", "scale": 0.14496292001098665, "offset": -500, "invalid": 65535, "unit": "m" },
{ "name": "gnss.speed", "id": "0x4A1", "byte": 2, "type": "u16", "scale": 0.001271604561499883, "invalid": 65535, "unit": "m/s" },
{ "name": "gnss.hdop", "id": "0x4A1", "byte": 4, "type": "u16", "scale": 0.0007629627368999298, "invalid": 65535 },
{ "name": "gnss.satellites", "id": "0x4A1", "byte": 6, "type": "u8", "scale": 1.0039370078740157, "invalid": 255 },
{ "name": "imu.pitch", "id": "0x2A1", "byte": 0, "type": "u16", "scale": 0.005493331705679495, "offset": -180, "invalid": 65535, "unit": "°" },
{ "name": "imu.roll", "id": "0x2A1", "byte": 2, "type": "u16", "scale": 0.005493331705679495, "offset": -180, "invalid": 65535, "unit": "°" },
{ "name": "imu.temperature", "id": "0x2A1", "byte": 4, "type": "u16", "scale": 0.0025177770317697684, "offset": -40, "invalid": 65535, "unit": "°C" },
{ "name": "mag.x", "id": "0x221", "byte": 0, "type": "u16", "scale": 0.006103701895199438, "offset": -200, "invalid": 65535, "unit": "µT" },
{ "name": "mag.y", "id": "0x221", "byte": 2, "type": "u16", "scale": 0.006103701895199438, "offset": -200, "invalid": 65535, "unit": "µT" },
{ "name": "mag.z", "id": "0x221", "byte": 4, "type": "u16", "scale": 0.006103701895199438, "offset": -200, "invalid": 65535, "unit": "µT" },
{ "name": "imu.heading", "id": "0x221", "byte": 6, "type": "u16", "scale": 0.005493331705679495, "invalid": 65535, "unit": "°" } ] }
"aliases": {
"mcu-stm32-xiao-c5-2.Latitude": "gnss.lat",
"mcu-stm32-xiao-c5-2.Longitude": "gnss.lon",
"mcu-stm32-xiao-c5-2.Altitude": "gnss.alt",
"mcu-stm32-xiao-c5-2.Speed": { "name": "gnss.speed", "scale": 0.2777777777777778, "unit": "m/s" },
"mcu-stm32-xiao-c5-2.HDOP": "gnss.hdop",
"mcu-stm32-xiao-c5-2.Satellites": "gnss.satellites",
"mcu-stm32-xiao-c5-2.Pitch": "imu.pitch",
"mcu-stm32-xiao-c5-2.Roll": "imu.roll",
"mcu-stm32-xiao-c5-2.IMU Temperature": "imu.temperature",
"mcu-stm32-xiao-c5-2.Field Strength X": "mag.x",
"mcu-stm32-xiao-c5-2.Field Strength Y": "mag.y",
"mcu-stm32-xiao-c5-2.Field Strength Z": "mag.z",
"mcu-stm32-xiao-c5-2.Heading": "imu.heading" } }
----
Speed's scale also converts km/h to m/s (`300 / 65534 / 3.6`). 0x221 is
the HMC5883L (TPDO 4 → `0x200 + node`): the field ±200 µT and ESPHome's
heading 0..360° (ESPHome's plain `atan2(-x, y)` is −180..180, the node
adds 360 to the negatives — a filter on `heading:`). No tilt compensation
or hard-iron calibration yet, so only roughly right standing level. The node
goes operational by itself, so no `nmt_start`.
What node 0x21 sends (read from it, 2026-11-30): TPDO1 0x2A1 pitch, roll
(-180..180°) and the IMU's temperature, Sensor16; TPDO2 0x3A1
latitude/longitude, REAL32; TPDO3 0x4A1 altitude, speed (km/h), HDOP
(Sensor16) and satellites (Sensor8); TPDO4 0x221 the HMC5883L, the field
±200 µT and the heading 0..360° (ESPHome's plain `atan2(-x, y)` is
−180..180, the node adds 360 to the negatives — a filter on `heading:`).
No tilt compensation or hard-iron calibration yet, so only roughly right
standing level. The node goes operational by itself, so no `nmt_start`.
Sensor16/8: `value = wire * (max - min) / (2^n - 2) + min`, all ones unknown.
The node sends no course: `App.gnss_update` (where every fix lands, the
node's and the GNSS simulation's) works it out from the fix ≥ 5 m back