2026 remote: tabbed Nextion UI, robot telemetry, servo centre calibration

Protocol v4: CmdPacket grows to 26 bytes (cal_cmd, cal_servo, cal_value);
new 30-byte Telemetry rides back on the nRF24 ack payload (robot state,
IMU, battery, 18 joint angles, packets/s, servo-cal echo). Each end drops
wrong-length packets, so version mismatches still fail closed.

Robot (owner-approved): SERVO_CAL state while disarmed, per-servo centre
trims (+-200 us) in EEPROM, telemetry, battery reading; the IMU estimate
now always runs (leveling still gated by ROBOT GYRO).

Remote: generated HMI (scripts/make_remote_hmi.py) with pages splash,
drive, status, servos, cal, setup, upload; page-aware NextionUI that only
writes the showing page and only what changed; servo calibration and
UPDATE DISPLAY on the touchscreen and serial console; battery module.
The display is on Serial2 (pins 7/8), found on the real remote; the old
sketch's Serial1 was never connected to it.

Sim: RF24 shim supports ack payloads, API version 8
(hxsim_get_ack_payload); sim_smoke checks telemetry and every CAL command.
Unity CmdPacket mirror updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-17 14:42:37 +01:00
1 parent 481610c9fd
commit 0b836af8de
40 files changed
+1463 -281

No files matched your search

+30 -3
View File
@@ -6,6 +6,7 @@
#include "RadioLink.h"
#include "NextionUI.h"
#include "SerialConsole.h"
#include "Battery.h"
// Hexapod remote (Teensy 4.0): reads two 3-axis sticks and the handset
// MPU6050, takes operator commands from the Nextion touchscreen (and the USB
@@ -19,6 +20,7 @@ PacketBuilder builder;
RadioLink radio_link;
NextionUI nextion;
SerialConsole console;
Battery battery;
uint32_t last_tx_us = 0;
bool dump_packets = false;
@@ -39,6 +41,22 @@ static void printStatus() {
state.modeB() ? "B" : "A", state.rstickXlate() ? "xlate" : "rot",
state.remoteGyro(), state.robotGyro(), state.speedTarget(), state.speedCurrent(), state.height());
sticks.printCalibration(Serial);
if (BATTERY_SENSE_PIN != 255) Serial.printf("battery %u mV\n", battery.millivolts());
const Telemetry& t = radio_link.telemetry();
if (radio_link.telemetryFresh(millis())) {
Serial.printf("robot: state %u status %02X roll %.1f pitch %.1f battery %u mV, hears %u/s\n",
t.state, t.status, t.roll_ddeg / 10.0f, t.pitch_ddeg / 10.0f, t.battery_mv, t.rx_per_sec);
Serial.print("robot joints (deg):");
for (int i = 0; i < 18; i++)
Serial.printf(" %d", t.joint_deg[i] - (i % 3 == 2 ? TELEMETRY_TIBIA_OFFSET_DEG : 0));
Serial.println();
} else {
Serial.println("robot: no telemetry");
}
Serial.printf("servo cal %s, servo %u (leg %u joint %u) trim %d us%s, robot reports servo %u trim %d\n",
state.servoCal() ? "ON" : "off", state.servoSel(), state.servoSel() / 3, state.servoSel() % 3,
state.trimTarget(), state.trimSynced() ? "" : " (not read back yet)", t.cal_servo, t.cal_trim_us);
}
static void dumpPacket(const CmdPacket& p) {
@@ -47,7 +65,7 @@ static void dumpPacket(const CmdPacket& p) {
p.remote_roll, p.remote_pitch, p.body_height, p.speed_scale, p.flags);
}
// Nextion Editor upload through this USB port (the old remote's b2 button).
// Nextion Editor upload through this USB port (SETUP > UPDATE DISPLAY, or 'U').
// Never returns: the TX loop stops, so the robot loses the link and
// disarms itself after LINK_TIMEOUT_SEC. Power-cycle the remote to leave.
static void enterNextionUpload() {
@@ -61,8 +79,8 @@ static void enterNextionUpload() {
static void pollInputs(uint32_t now_ms) {
UiEvent ev;
while (nextion.poll(ev)) {
if (ev.cmd == UiCmd::NextionUpload) enterNextionUpload();
state.handle(ev, sticks, imu, now_ms);
if (state.takeUploadRequest()) enterNextionUpload(); // UPDATE DISPLAY, tapped twice
}
SerialConsole::Local local;
@@ -114,7 +132,9 @@ void loop() {
sticks.update();
imu.update(dt);
radio_link.update(now_ms);
state.update(dt, radio_link.linkOk(), now_ms);
battery.update(dt);
bool tele_fresh = radio_link.telemetryFresh(now_ms);
state.update(dt, radio_link.linkOk(), tele_fresh, radio_link.telemetry(), now_ms);
last_packet = builder.build(sticks.frame(), imu, state, now_ms);
radio_link.send(last_packet);
@@ -123,6 +143,13 @@ void loop() {
state.fillView(view, now_ms);
view.link_ok = radio_link.linkOk();
view.link_pct = radio_link.qualityPct();
view.tele_ok = tele_fresh;
view.tele = radio_link.telemetry();
view.imu_ok = imu.ok();
view.imu_roll = imu.rollDeg();
view.imu_pitch = imu.pitchDeg();
for (int i = 0; i < NUM_AXES; i++) view.sticks[i] = sticks.frame().v[i];
view.battery_mv = battery.millivolts();
nextion.render(view, now_ms);
if (dump_packets && now_ms - last_dump_ms >= 100) {