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:
1 parent
481610c9fd
commit
0b836af8de
40 files changed
+1463
-281
No files matched your search
@@ -227,6 +227,21 @@ int main() {
|
||||
snprintf(buf, sizeof(buf), "%u servo writes in 1.5 s (0 = every IK solution was rejected as invalid)", writes);
|
||||
check(writes > 0, "IK produces valid joint solutions at the stance pose", buf);
|
||||
printLegs("standing:");
|
||||
{
|
||||
Telemetry t;
|
||||
int len = hxsim_get_ack_payload(reinterpret_cast<uint8_t*>(&t), sizeof(t));
|
||||
float deg[18]; hxsim_get_joints_deg(deg);
|
||||
float worst = 0;
|
||||
for (int i = 0; i < 18; i++) {
|
||||
float tj = t.joint_deg[i] - (i % 3 == 2 ? TELEMETRY_TIBIA_OFFSET_DEG : 0);
|
||||
worst = fmaxf(worst, fabsf(tj - deg[i]));
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "%d bytes, state %u, status %02X, joints off by up to %.1f deg, %u packets/s",
|
||||
len, t.state, t.status, worst, t.rx_per_sec);
|
||||
check(len == (int)sizeof(Telemetry) && t.state == TSTATE_STAND && (t.status & TSTAT_SERVOS_ON) &&
|
||||
worst < 1.5f && t.rx_per_sec >= 90,
|
||||
"telemetry comes back in the ack payload (state, servo angles, packet rate)", buf);
|
||||
}
|
||||
|
||||
float feet[18]; hxsim_get_feet_mm(feet);
|
||||
float worst = 0;
|
||||
@@ -553,6 +568,68 @@ int main() {
|
||||
s = status();
|
||||
check(!s.link_ok && s.robot_state == 0, "link loss (>0.3 s silence) disarms the robot");
|
||||
|
||||
// ---- Servo centre calibration (CAL_* commands, only while disarmed) ----
|
||||
{
|
||||
auto tele = []() { Telemetry t; hxsim_get_ack_payload(reinterpret_cast<uint8_t*>(&t), sizeof(t)); return t; };
|
||||
int us[18], att[18]; uint32_t wr[18];
|
||||
CmdPacket c; // disarmed
|
||||
c.cal_cmd = CAL_HOLD;
|
||||
c.cal_servo = 4; // leg 1 (mid-right) femur
|
||||
run(c, 0.3f);
|
||||
float deg[18]; hxsim_get_joints_deg(deg);
|
||||
hxsim_get_servos(us, att, wr);
|
||||
float worst = 0; int relaxed = 0;
|
||||
for (int i = 0; i < 18; i++) {
|
||||
worst = fmaxf(worst, fabsf(deg[i] - (i % 3 == 2 ? -90.0f : 0.0f)));
|
||||
if (!att[i]) relaxed++;
|
||||
}
|
||||
Telemetry t = tele();
|
||||
snprintf(buf, sizeof(buf), "state %u, %d relaxed, pose off by up to %.1f deg", t.state, relaxed, worst);
|
||||
check(t.state == TSTATE_SERVO_CAL && relaxed == 0 && worst < 1.0f,
|
||||
"CAL_HOLD holds every servo at the centre pose (coxa 0, femur 0, tibia -90)", buf);
|
||||
int us0 = us[4];
|
||||
|
||||
c.cal_cmd = CAL_SET; c.cal_value = 50;
|
||||
run(c, 0.2f);
|
||||
hxsim_get_servos(us, att, wr);
|
||||
t = tele();
|
||||
snprintf(buf, sizeof(buf), "pulse %d -> %d us, echo servo %u trim %d, status %02X", us0, us[4], t.cal_servo, t.cal_trim_us, t.status);
|
||||
check(abs(us[4] - us0 - 50) <= 1 && t.cal_servo == 4 && t.cal_trim_us == 50 && (t.status & TSTAT_CAL_DIRTY),
|
||||
"CAL_SET trims the selected servo and the telemetry echoes it", buf);
|
||||
|
||||
c.cal_cmd = CAL_SAVE;
|
||||
run(c, 0.2f);
|
||||
t = tele();
|
||||
check((t.status & TSTAT_TRIMS_STORED) && !(t.status & TSTAT_CAL_DIRTY), "CAL_SAVE stores the trims");
|
||||
|
||||
c.cal_cmd = CAL_SET; c.cal_value = -120;
|
||||
run(c, 0.2f);
|
||||
c.cal_cmd = CAL_REVERT;
|
||||
run(c, 0.2f);
|
||||
t = tele();
|
||||
snprintf(buf, sizeof(buf), "trim %d after revert", t.cal_trim_us);
|
||||
check(t.cal_trim_us == 50 && !(t.status & TSTAT_CAL_DIRTY), "CAL_REVERT drops unsaved trims", buf);
|
||||
|
||||
c.flags = FLAG_ARMED; // arming wins over calibration
|
||||
run(c, 0.3f);
|
||||
t = tele();
|
||||
check(t.state == TSTATE_SIT, "arming while CAL_* is sent leaves SERVO_CAL (robot arms into SIT)");
|
||||
|
||||
c.flags = 0; c.cal_cmd = CAL_SET; c.cal_value = 0; // put the trim back for the checks below
|
||||
run(c, 0.2f);
|
||||
c.cal_cmd = CAL_SAVE;
|
||||
run(c, 0.2f);
|
||||
c.cal_cmd = CAL_NONE;
|
||||
run(c, 0.2f);
|
||||
hxsim_get_servos(us, att, wr);
|
||||
relaxed = 0;
|
||||
for (int i = 0; i < 18; i++) if (!att[i]) relaxed++;
|
||||
t = tele();
|
||||
snprintf(buf, sizeof(buf), "state %u, %d of 18 relaxed, trim %d", t.state, relaxed, t.cal_trim_us);
|
||||
check(t.state == TSTATE_DISARMED && relaxed == 18 && t.cal_trim_us == 0, "CAL_NONE relaxes the servos again", buf);
|
||||
runSilent(0.5f);
|
||||
}
|
||||
|
||||
// ---- Protocol mismatch fails closed ----
|
||||
uint8_t short_payload[16] = {};
|
||||
short_payload[10] = FLAG_ARMED;
|
||||
|
||||
Reference in new issue
Block a user