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>
97 lines
3.6 KiB
C++
97 lines
3.6 KiB
C++
#pragma once
|
|
#include <Arduino.h>
|
|
#include <HexapodProtocol.h>
|
|
#include "Config.h"
|
|
|
|
// Operator commands. Produced by the Nextion touchscreen (NextionUI) and by
|
|
// the USB serial console (SerialConsole) through the same path, so the
|
|
// remote can be fully exercised on the bench without the display attached.
|
|
enum class UiCmd : uint8_t {
|
|
None = 0,
|
|
ToggleArm,
|
|
Disarm, // unconditional - the big red button
|
|
ToggleStand,
|
|
ToggleGait, // tripod <-> wave
|
|
ToggleWalkMode, // direct (A) <-> heading-hold (B)
|
|
ToggleRStickXlate, // right stick: rotation <-> translation
|
|
ToggleRemoteGyro,
|
|
ToggleRobotGyro,
|
|
SetSpeed, // value = 0..255
|
|
SpeedUp, // serial console only
|
|
SpeedDown, // serial console only
|
|
SetHeight, // value = 0..200, 100 = default standing height
|
|
HeightUp, // serial console only
|
|
HeightDown, // serial console only
|
|
ZeroGyro, // capture the handset's current attitude as "level"
|
|
CalStartSave, // stick sweep calibration: start, or save it if running
|
|
CalCancel,
|
|
PageShown, // value = Nextion page id (UiPage); the display just showed it
|
|
ServoCalToggle, // servo centre calibration on/off (robot holds the centre pose)
|
|
ServoCalLeg, // value = leg 0..5
|
|
ServoCalJoint, // value = joint 0..2 (coxa, femur, tibia)
|
|
ServoCalNext, // serial console only: next servo
|
|
ServoCalTrim, // value = SERVO_TRIM_* step code
|
|
ServoCalSave, // store the trims in the robot's EEPROM
|
|
ServoCalRevert, // reload the trims from the robot's EEPROM
|
|
UploadRequest, // display update mode from the touchscreen: needs a second tap
|
|
NextionUpload, // display update mode right away (serial console 'U')
|
|
};
|
|
|
|
// ServoCalTrim values.
|
|
constexpr uint8_t SERVO_TRIM_MINUS_BIG = 0;
|
|
constexpr uint8_t SERVO_TRIM_MINUS_SMALL = 1;
|
|
constexpr uint8_t SERVO_TRIM_PLUS_SMALL = 2;
|
|
constexpr uint8_t SERVO_TRIM_PLUS_BIG = 3;
|
|
constexpr uint8_t SERVO_TRIM_ZERO = 4;
|
|
|
|
struct UiEvent {
|
|
UiCmd cmd = UiCmd::None;
|
|
uint8_t value = 0;
|
|
};
|
|
|
|
// The HMI's pages (remote/remote.HMI, page id = position in the Editor's
|
|
// page list). Each page reports itself with a 'P' frame when it opens.
|
|
enum UiPage : uint8_t {
|
|
PAGE_SPLASH = 0, PAGE_DRIVE, PAGE_STATUS, PAGE_SERVOS, PAGE_CAL, PAGE_SETUP, PAGE_UPLOAD,
|
|
PAGE_UNKNOWN = 0xFF,
|
|
};
|
|
|
|
// Everything the display shows. The remote is authoritative: the Nextion
|
|
// only sends requests, and always renders what's in here.
|
|
struct UiView {
|
|
// Operator state (DRIVE page)
|
|
bool armed = false;
|
|
bool stand = false;
|
|
bool gait_wave = false;
|
|
bool mode_b = false;
|
|
bool rstick_xlate = false;
|
|
bool remote_gyro = false;
|
|
bool robot_gyro = false;
|
|
uint8_t speed_target = 0;
|
|
int16_t height = 0; // -1000..1000, 0 = default
|
|
|
|
// Radio + robot telemetry
|
|
bool link_ok = false;
|
|
uint8_t link_pct = 0;
|
|
bool tele_ok = false; // fresh telemetry from the robot
|
|
Telemetry tele;
|
|
|
|
// Handset (STATUS page)
|
|
bool imu_ok = false;
|
|
float imu_roll = 0, imu_pitch = 0; // degrees, vs the zeroed level
|
|
int16_t sticks[NUM_AXES] = {};
|
|
uint16_t battery_mv = 0; // 0 = not measured
|
|
|
|
// SETUP page
|
|
bool stick_calibrating = false;
|
|
bool upload_confirm = false; // UPDATE DISPLAY tapped once, waiting for the second tap
|
|
|
|
// CAL page (servo centre calibration)
|
|
bool servo_cal = false;
|
|
uint8_t servo_sel = 0; // leg * 3 + joint
|
|
bool trim_synced = false; // trim below is known (read back from the robot)
|
|
int16_t trim_us = 0;
|
|
|
|
const char* message = "";
|
|
};
|