by Drew Owens
Open-source 15-DoF XL330 biped goose robot with Spine molecule PCB, 3D-printed chassis, and Isaac Lab to MuJoCo sim-to-real RL stack
main
Drew Owens
Publish Microgoose Rev A full-stack hardware, CAD, datasheet, and 7-stage RL stack
e843249
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
/*
* host_frame.h
* COBS + CRC-16 binary telemetry and command framing over USART2 (PA2/PA3)
* between the STM32G431CB Spine MCU and Radxa Zero 3W Linux host.
*/
#ifndef MICROGOOSE_HOST_FRAME_H
#define MICROGOOSE_HOST_FRAME_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "board_pins.h"
#define HOST_FRAME_MAGIC 0xA5U
#define HOST_FRAME_HEADER_LEN 6U
#define HOST_FRAME_CRC_LEN 2U
#define HOST_FRAME_MAX_RAW_LEN 232U
#define HOST_FRAME_MAX_COBS_LEN 240U
/* Host <-> Spine Message Types */
#define HOST_MSG_TELEMETRY 0x01U /* Spine -> Radxa (200 Hz) */
#define HOST_MSG_CMD_JOINTS 0x02U /* Radxa -> Spine (50..200 Hz) */
#define HOST_MSG_CMD_ESTOP 0x03U /* Radxa -> Spine immediate e-stop */
#define HOST_MSG_PING 0x04U /* Radxa -> Spine ping */
#define HOST_MSG_PONG 0x84U /* Spine -> Radxa pong */
/* Spine Telemetry Status Flags */
#define SPINE_STATUS_TORQUE_ENABLED (1U << 0)
#define SPINE_STATUS_WATCHDOG_TRIPPED (1U << 1)
#define SPINE_STATUS_ESTOP_LATCHED (1U << 2)
#define SPINE_STATUS_UNDERVOLT_FAULT (1U << 3)
#define SPINE_STATUS_OVERCURRENT_FAULT (1U << 4)
#define SPINE_STATUS_DXL_BUS_OK (1U << 5)
#define SPINE_STATUS_TORSO_IMU_OK (1U << 6)
#define SPINE_STATUS_HEAD_I2C_OK (1U << 7)
/* Host Command Flags */
#define HOST_CMD_FLAG_TORQUE_ENABLE (1U << 0)
#define HOST_CMD_FLAG_ESTOP (1U << 1)
#define HOST_CMD_FLAG_CLEAR_FAULTS (1U << 2)
#define HOST_CMD_FLAG_LED_OVERRIDE (1U << 3)
#define HOST_TOF_ZONES 64U /* VL53L5CX 8x8 multizone grid */
#define MG_TELEMETRY_PAYLOAD_BYTES 194U
#define MG_CMD_JOINTS_PAYLOAD_BYTES 38U
/*
* Spine -> Radxa Telemetry Payload (194 bytes packed, little-endian).
* Fixed-point units avoid cross-architecture float alignment ambiguity:
* - Voltages in millivolts (mV)
* - Currents in milliamps (mA)
* - Power in milliwatts (mW)
* - Accelerometers in milli-g (mg)
* - Gyroscopes in milliradians/s (mrad/s)
* - Joint positions in 0.1 mrad (10000 LSB = 1.0 rad, +/- 3.2767 rad)
* - Joint velocities in mrad/s (1000 LSB = 1.0 rad/s, +/- 32.767 rad/s)
* - Joint loads in mA
* - ToF 8x8 zones in 4 mm units (0..1020 mm)
*/
typedef struct __attribute__((packed)) {
uint32_t uptime_us;
uint16_t status_flags;
uint16_t vbat_mv;
uint16_t bus_5v_mv;
int16_t bus_current_ma;
uint16_t bus_power_mw;
int16_t torso_accel_mg[3];
int16_t torso_gyro_mrad_s[3];
int16_t head_accel_mg[3];
int16_t head_gyro_mrad_s[3];
uint16_t tof_min_mm;
uint8_t tof_grid_4mm[HOST_TOF_ZONES];
int16_t joint_pos_0p1mrad[MG_TOTAL_SERVO_COUNT];
int16_t joint_vel_mrad_s[MG_TOTAL_SERVO_COUNT];
int16_t joint_load_ma[MG_TOTAL_SERVO_COUNT];
} mg_telemetry_payload_t;
/*
* Radxa -> Spine Joint Command Payload (38 bytes packed, little-endian).
*/
typedef struct __attribute__((packed)) {
uint16_t cmd_flags;
int16_t goal_pos_0p1mrad[MG_TOTAL_SERVO_COUNT];
uint8_t led0_rgb[3];
uint8_t led1_rgb[3];
} mg_cmd_joints_payload_t;
/* Decoded frame header + payload view */
typedef struct {
uint8_t msg_type;
uint16_t seq;
uint16_t payload_len;
uint8_t payload[HOST_FRAME_MAX_RAW_LEN];
} mg_host_decoded_frame_t;
/* COBS byte stuffing (0x00 delimiter excluded from cobs_encode output; host_frame_pack appends 0x00) */
size_t cobs_encode(const uint8_t *input, size_t len, uint8_t *output, size_t out_max);
size_t cobs_decode(const uint8_t *input, size_t len, uint8_t *output, size_t out_max);
/* Pack message into [COBS(header + payload + crc16), 0x00] wire frame */
size_t host_frame_pack(
uint8_t msg_type,
uint16_t seq,
const void *payload,
uint16_t payload_len,
uint8_t *wire_out,
size_t wire_max
);
/* Unpack a 0x00-terminated (or stripped) COBS wire frame and verify magic + CRC-16 */
bool host_frame_unpack(
const uint8_t *wire_in,
size_t wire_len,
mg_host_decoded_frame_t *out_frame
);
/* Convenience helpers for float <-> fixed-point joint conversions */
int16_t host_rad_to_0p1mrad(float rad);
float host_0p1mrad_to_rad(int16_t raw);
#endif /* MICROGOOSE_HOST_FRAME_H */