- Nextion is on Serial2 (pins 7/8) - already in the last commit; docs updated. - MPU6050 on Wire (18/19) so everything is on the edge headers (owner's choice); the two stick wires from 18/19 move to A7/A8 (21/22). - Stick mapping checked on the real remote: left stick X/Y/twist on A3/A7/A8, right on A0/A1/A2, all inverted but the right twist. - RemoteIMU: full device reset before waking. The remote's MPU6050 (likely a clone) answers and wakes without it but every data register reads 0. Axis defaults confirmed (+pitch nose down, +roll right side down). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
145 lines
8.2 KiB
C++
145 lines
8.2 KiB
C++
#pragma once
|
|
#include <Arduino.h>
|
|
|
|
// =====================================================================
|
|
// Remote handset config (Teensy 4.0). Everything here is a placeholder
|
|
// until checked against your real wiring and parts - see the BENCH notes.
|
|
// Radio address/channel/rate/PA/payload size are NOT here: they live in
|
|
// shared/HexapodProtocol so they can't drift from the robot.
|
|
// =====================================================================
|
|
|
|
// ---- Loop rate ----
|
|
// Must be >= the robot's CONTROL_HZ (60) so every robot control tick sees a
|
|
// fresh packet. 100 Hz gives margin for the odd dropped packet.
|
|
constexpr float TX_HZ = 100.0f;
|
|
|
|
// ---- Radio (nRF24L01) on SPI0: MOSI 11, MISO 12, SCK 13 ----
|
|
// CE/CSN as in the old remote sketch (2019-teensy-nrf24/remote/Nrf.h).
|
|
constexpr uint8_t RADIO_CE_PIN = 9;
|
|
constexpr uint8_t RADIO_CSN_PIN = 10;
|
|
// Auto-retransmit: (delay units of 250us, count). Kept short on purpose - a
|
|
// newer packet replaces a lost one 10 ms later anyway, and write() blocks for
|
|
// the whole retry sequence. Worst case here is ~4 attempts x ~1.7 ms.
|
|
constexpr uint8_t RADIO_RETRY_DELAY = 1;
|
|
constexpr uint8_t RADIO_RETRY_COUNT = 3;
|
|
// No acks for this long -> remote considers the link lost and disarms itself,
|
|
// mirroring the robot's LINK_TIMEOUT_SEC (0.3 s) failsafe, so the robot can't
|
|
// spring back up on its own when the link returns.
|
|
constexpr uint32_t LINK_LOST_MS = 300;
|
|
|
|
// ---- Joysticks: 2 x 3-axis analog potentiometer sticks ----
|
|
// Logical axis order used everywhere in the remote code.
|
|
enum StickAxis : uint8_t { L_X = 0, L_Y, L_TWIST, R_X, R_Y, R_TWIST, NUM_AXES };
|
|
|
|
// The old remote had A0-A5 in a row (2019-teensy-nrf24/remote/Joysticks.h).
|
|
// The two wires on A4/A5 (pins 18/19) move to A7/A8 (pins 21/22), because
|
|
// 18/19 are Wire's SDA/SCL for the MPU6050 (owner's choice 2026-11-17: edge
|
|
// headers only, no pads underneath). A6 (20) stays free for the battery.
|
|
// Checked on the real remote (2026-11-17): the left stick is on A3/A7/A8, the
|
|
// right stick on A0/A1/A2.
|
|
constexpr uint8_t STICK_PINS[NUM_AXES] = { A3, A7, A8, A0, A1, A2 };
|
|
|
|
// Each logical axis must end up: X + = pushed RIGHT, Y + = pushed FORWARD
|
|
// (away from you), TWIST + = rotated COUNTERCLOCKWISE seen from above.
|
|
// Checked on the real remote (2026-11-17): every axis but the right twist reads inverted.
|
|
constexpr bool STICK_INVERT[NUM_AXES] = { true, true, true, true, true, false };
|
|
|
|
constexpr int ADC_BITS = 12; // 0..4095
|
|
constexpr int ADC_AVERAGING = 8; // hardware averaging per analogRead()
|
|
|
|
// Fallback calibration used until you run the on-device sweep calibration
|
|
// (which is saved to EEPROM and overrides these).
|
|
// BENCH: typical pot sticks don't use the full electrical range - run the
|
|
// sweep calibration once, then optionally paste the printed values here.
|
|
constexpr int16_t STICK_DEFAULT_MIN = 200;
|
|
constexpr int16_t STICK_DEFAULT_CENTER = 2048;
|
|
constexpr int16_t STICK_DEFAULT_MAX = 3900;
|
|
|
|
// At power-on the resting position of each axis is re-captured as its center
|
|
// (pots drift a little with temperature). Rejected if a stick is visibly
|
|
// deflected, i.e. further than this from the stored center (ADC counts).
|
|
constexpr int16_t CENTER_CAPTURE_TOLERANCE = 250;
|
|
// A sweep calibration is rejected unless every axis travels at least this
|
|
// far on both sides of center (ADC counts) - catches "forgot to move a stick".
|
|
constexpr int16_t CAL_MIN_HALF_SPAN = 600;
|
|
|
|
// Deadzone as a fraction of full deflection; output is rescaled so motion
|
|
// starts smoothly from 0 at the deadzone edge instead of jumping.
|
|
constexpr float STICK_DEADZONE[NUM_AXES] = { 0.06f, 0.06f, 0.10f, 0.06f, 0.06f, 0.10f };
|
|
// 0 = linear, 1 = fully cubic. A bit of expo gives fine control near center.
|
|
constexpr float STICK_EXPO[NUM_AXES] = { 0.25f, 0.25f, 0.30f, 0.20f, 0.20f, 0.20f };
|
|
// One-pole low-pass on raw ADC counts (1 = no filtering). Pots are noisy.
|
|
constexpr float STICK_FILTER_ALPHA = 0.5f;
|
|
|
|
// ---- Remote IMU: MPU6050 on Wire (SDA = 18, SCL = 19) ----
|
|
// Edge-header pins; the stick axes that used to be there moved to A7/A8.
|
|
#define IMU_WIRE Wire
|
|
constexpr uint8_t IMU_ADDR = 0x68; // 0x69 if AD0 is pulled high
|
|
// Mounting remap: which chip axis (0=X,1=Y,2=Z) and sign gives each handset
|
|
// axis. Handset frame: +X = away from you, +Y = your left, +Z = up.
|
|
// Checked on the real remote (2026-11-17): the defaults are right - tipping
|
|
// the far edge down reads +pitch, dipping the right side reads +roll.
|
|
constexpr uint8_t IMU_AXIS_FROM_CHIP[3] = { 0, 1, 2 };
|
|
constexpr int8_t IMU_AXIS_SIGN[3] = { +1, +1, +1 };
|
|
constexpr float IMU_ALPHA = 0.98f; // complementary filter, same as the robot
|
|
constexpr int IMU_GYRO_BIAS_SAMPLES = 200; // at boot; hold the remote still
|
|
|
|
// Handset tilt -> CmdPacket.remote_roll/pitch. This many degrees of tilt away
|
|
// from the zeroed "level" pose = full scale (1000); the robot then scales
|
|
// full scale to its own MAX_TILT_DEG.
|
|
constexpr float REMOTE_TILT_FULL_SCALE_DEG = 30.0f;
|
|
constexpr float REMOTE_TILT_DEADZONE_DEG = 2.0f; // ignore hand tremor around level
|
|
// Toggling "remote gyro" fades the tilt in/out at this rate (fraction/s)
|
|
// instead of stepping it. The robot rate-limits pose as well; this just
|
|
// keeps the flag change itself from being a hard edge.
|
|
constexpr float REMOTE_TILT_FADE_PER_SEC = 2.0f;
|
|
|
|
// ---- Operator setpoints ----
|
|
constexpr uint8_t SPEED_SCALE_DEFAULT = 128;
|
|
constexpr float SPEED_SCALE_RATE_PER_SEC = 255.0f; // slider jumps ramp over <= 1 s (robot doesn't smooth twist)
|
|
constexpr uint8_t SPEED_SCALE_STEP = 25; // serial console +/- step
|
|
// Standing height slider -> CmdPacket.body_height (-1000..1000, 0 = the
|
|
// robot's default). No smoothing here: the robot rate-limits height itself.
|
|
constexpr int16_t HEIGHT_STEP = 100; // serial console [ / ] step
|
|
// FLAG_WALK stays set this long after the left stick returns to center, so
|
|
// hovering at the deadzone edge doesn't chatter STAND <-> WALKING.
|
|
constexpr uint32_t WALK_LINGER_MS = 250;
|
|
// Arming is refused unless every stick axis is within this of center
|
|
// (post-deadzone, -1000..1000 scale), so the robot never arms mid-command.
|
|
constexpr int16_t ARM_CENTER_TOLERANCE = 50;
|
|
|
|
// ---- Nextion touchscreen on Serial2 (RX2 = pin 7, TX2 = pin 8) ----
|
|
// Found on the real remote (2026-11-17): the display answers on Serial2 at 115200. The old
|
|
// sketch's Serial1.begin() was a red herring; its ITEAD Nextion library used Serial2.
|
|
#define NEXTION_SERIAL Serial2
|
|
// The HMI (remote/remote.HMI) sets this with `bauds=115200` in Program.s.
|
|
constexpr uint32_t NEXTION_BAUD = 115200;
|
|
#define NEXTION_UPLOAD_PAGE "upload"
|
|
// The firmware only writes the page that is showing (each page reports itself
|
|
// with a 'P' frame), and only what changed since the last write.
|
|
constexpr uint32_t NEXTION_RENDER_MS = 50; // repaint rate of the showing page
|
|
constexpr uint32_t NEXTION_SERVOS_RENDER_MS = 100; // SERVOS page: 36 values, so a bit slower
|
|
constexpr uint32_t NEXTION_FULL_REFRESH_MS = 2000; // re-push everything periodically (self-heals after a display reset)
|
|
// A render is skipped while less than this is free in the TX buffer, so the
|
|
// TX loop never blocks on the display.
|
|
constexpr int NEXTION_TX_MIN_FREE = 400;
|
|
constexpr uint32_t STATUS_MESSAGE_MS = 2500; // how long transient status messages stay up
|
|
constexpr uint32_t UPLOAD_CONFIRM_MS = 3000; // UPDATE DISPLAY: second tap within this
|
|
|
|
// ---- Robot telemetry (ack payloads) ----
|
|
constexpr uint32_t TELEMETRY_STALE_MS = 500; // older than this -> the display shows "no data"
|
|
|
|
// ---- Servo centre calibration (CAL page) ----
|
|
constexpr int16_t SERVO_TRIM_STEP_SMALL_US = 1;
|
|
constexpr int16_t SERVO_TRIM_STEP_BIG_US = 10;
|
|
// SAVE / REVERT go out for this long (the robot acts once; repeats are harmless).
|
|
constexpr uint32_t SERVO_CAL_OP_MS = 300;
|
|
|
|
// ---- Battery voltage (STATUS page) ----
|
|
// BENCH: not built yet. Planned: the 18650's + through a 100k/100k divider
|
|
// into A6 (pin 20) with 100 nF to GND (see README.md "Planned"). Then set
|
|
// the pin to A6. 255 = not fitted: the display shows "--".
|
|
constexpr uint8_t BATTERY_SENSE_PIN = 255;
|
|
constexpr float BATTERY_DIVIDER = 2.0f; // battery V / pin V
|
|
constexpr float BATTERY_ADC_REF_V = 3.3f;
|