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

+46
View File
@@ -9,6 +9,7 @@
#include "Comms.h"
#include "ServoDriver.h"
#include "SmoothedValue.h"
#include "Battery.h"
// Uncomment to drive the robot from the Serial Monitor before a remote exists.
// See README.md for the key map.
@@ -21,6 +22,7 @@ StateMachine state_machine;
InputMapper mapper;
Comms comms;
ServoDriver servo_driver;
Battery battery;
float current_heading_deg = 0; // open-loop: accumulates commanded omega. See note in loop().
SmoothedValue stance_height(STANCE_HEIGHT_RATE_MM_S); // remote height slider, rate-limited
@@ -28,6 +30,7 @@ float gyro_corr_roll_deg = 0, gyro_corr_pitch_deg = 0; // robot-gyro self-level
float last_joint_deg[NUM_LEGS][3] = {}; // for per-joint rate limiting
uint32_t last_loop_us = 0;
RobotState last_state = RobotState::DISARMED;
bool servo_cal_active = false; // SERVO_CAL: servos held at the centre pose for trimming
#ifdef TEST_SERIAL_INPUT
CmdPacket test_packet;
@@ -63,6 +66,33 @@ void pollSerialTestInput() {
}
#endif
// Robot state for the remote's display, sent back in the radio's ack payload.
void sendTelemetry(const CmdPacket& cmd, const MapperOutput& mapped, RobotState state) {
Telemetry t;
t.roll_ddeg = (int16_t)lroundf(constrain(imu.rollDeg(), -3000.0f, 3000.0f) * 10);
t.pitch_ddeg = (int16_t)lroundf(constrain(imu.pitchDeg(), -3000.0f, 3000.0f) * 10);
t.battery_mv = battery.millivolts();
t.state = servo_cal_active ? TSTATE_SERVO_CAL : (uint8_t)state;
t.status = (imu.ok() ? TSTAT_IMU_OK : 0) |
(mapped.robot_gyro_enabled ? TSTAT_GYRO_ON : 0) |
(state != RobotState::DISARMED || servo_cal_active ? TSTAT_SERVOS_ON : 0) |
(ServoDriver::trimsDirty() ? TSTAT_CAL_DIRTY : 0) |
(ServoDriver::trimsStored() ? TSTAT_TRIMS_STORED : 0);
t.cal_servo = cmd.cal_servo;
t.cal_trim_us = ServoDriver::trim(cmd.cal_servo);
t.rx_per_sec = comms.packetsPerSec();
for (int i = 0; i < NUM_LEGS; i++) {
const float* j = last_joint_deg[i];
float c = servo_cal_active ? ServoDriver::CAL_POSE.coxa_deg : j[0];
float f = servo_cal_active ? ServoDriver::CAL_POSE.femur_deg : j[1];
float b = servo_cal_active ? ServoDriver::CAL_POSE.tibia_deg : j[2];
t.joint_deg[i * 3] = (int8_t)constrain(lroundf(c), -127L, 127L);
t.joint_deg[i * 3 + 1] = (int8_t)constrain(lroundf(f), -127L, 127L);
t.joint_deg[i * 3 + 2] = (int8_t)constrain(lroundf(b) + TELEMETRY_TIBIA_OFFSET_DEG, -127L, 127L);
}
comms.setTelemetry(t);
}
void setup() {
Serial.begin(115200);
gait.begin();
@@ -73,6 +103,7 @@ void setup() {
if (!imu.begin()) Serial.println("robot IMU not responding - stabilization disabled");
if (!comms.begin()) Serial.println("radio not responding - waiting for injected/test commands only");
ServoDriver::loadTrims();
servo_driver.begin();
last_loop_us = micros();
}
@@ -115,6 +146,18 @@ void loop() {
} else if (state != RobotState::DISARMED && last_state == RobotState::DISARMED) {
servo_driver.begin();
}
// Servo centre calibration (remote CAL page): only while disarmed. The
// servos hold the centre pose through their trims; leaving it - CAL_NONE,
// arming or link loss (cmd is then a default packet) - relaxes them again.
bool servo_cal = !mapped.armed && cmd.cal_cmd != CAL_NONE;
if (servo_cal) {
if (!servo_cal_active) servo_driver.begin();
servo_driver.calibrate(cmd.cal_cmd, cmd.cal_servo, cmd.cal_value);
} else if (servo_cal_active && state == RobotState::DISARMED) {
servo_driver.relaxAll();
}
servo_cal_active = servo_cal;
// The stand pose holds every foot at neutral, so walking starts from there.
if (state == RobotState::WALKING && last_state != RobotState::WALKING) gait.resetFeet();
last_state = state;
@@ -203,4 +246,7 @@ void loop() {
servo_driver.writeLeg(i, angles);
}
}
battery.update(dt);
sendTelemetry(cmd, mapped, state);
}