sts3215-controller 0.1.4

A Rust library for controlling ST3215 servos
Documentation
// Constantes pour la bibliothèque ST3215

pub const DEFAULT_BAUDRATE: u32 = 1_000_000;
pub const LATENCY_TIMER: f64 = 50.0;

pub const TXPACKET_MAX_LEN: usize = 250;
pub const RXPACKET_MAX_LEN: usize = 250;

pub const MIN_POSITION: u16 = 0;
pub const MAX_POSITION: u16 = 4095;

pub const MAX_SPEED: u16 = 3400;
pub const MAX_CORRECTION: u16 = 2047;

// Indices de paquet pour le protocole
pub const PKT_HEADER_0: usize = 0;
pub const PKT_HEADER_1: usize = 1;
pub const PKT_ID: usize = 2;
pub const PKT_LENGTH: usize = 3;
pub const PKT_INSTRUCTION: usize = 4;
pub const PKT_ERROR: usize = 4;
pub const PKT_PARAMETER0: usize = 5;

// Bits d'erreur du protocole
pub const ERRBIT_VOLTAGE: u8 = 1;
pub const ERRBIT_ANGLE: u8 = 2;
pub const ERRBIT_OVERHEAT: u8 = 4;
pub const ERRBIT_OVERELE: u8 = 8;
pub const ERRBIT_OVERLOAD: u8 = 32;

pub const BROADCAST_ID: u8 = 0xFE; // 254
pub const MAX_ID: u8 = 0xFC; // 252
pub const STS_END: u8 = 0;

// Instructions pour le protocole STS
pub const INST_PING: u8 = 1;
pub const INST_READ: u8 = 2;
pub const INST_WRITE: u8 = 3;
pub const INST_REG_WRITE: u8 = 4;
pub const INST_ACTION: u8 = 5;
pub const INST_SYNC_WRITE: u8 = 131; // 0x83
pub const INST_SYNC_READ: u8 = 130; // 0x82

// Résultats de communication
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommResult {
    Success = 0,
    PortBusy = -1,
    TxFail = -2,
    RxFail = -3,
    TxError = -4,
    RxWaiting = -5,
    RxTimeout = -6,
    RxCorrupt = -7,
    NotAvailable = -9,
}

impl CommResult {
    pub fn is_success(&self) -> bool {
        matches!(self, CommResult::Success)
    }

    pub fn as_i32(&self) -> i32 {
        *self as i32
    }
}

// Vitesse du bus
#[allow(dead_code)]
pub const STS_1M: u8 = 0;
#[allow(dead_code)]
pub const STS_0_5M: u8 = 1;
#[allow(dead_code)]
pub const STS_250K: u8 = 2;
#[allow(dead_code)]
pub const STS_128K: u8 = 3;
#[allow(dead_code)]
pub const STS_115200: u8 = 4;
#[allow(dead_code)]
pub const STS_76800: u8 = 5;
#[allow(dead_code)]
pub const STS_57600: u8 = 6;
#[allow(dead_code)]
pub const STS_38400: u8 = 7;

// EPROM RO
pub const STS_MODEL_L: u8 = 3;
pub const STS_MODEL_H: u8 = 4;

// EPROM RW
pub const STS_ID: u8 = 5;
pub const STS_BAUD_RATE: u8 = 6;
pub const STS_MIN_ANGLE_LIMIT_L: u8 = 9;
pub const STS_MIN_ANGLE_LIMIT_H: u8 = 10;
pub const STS_MAX_ANGLE_LIMIT_L: u8 = 11;
pub const STS_MAX_ANGLE_LIMIT_H: u8 = 12;
pub const STS_CW_DEAD: u8 = 26;
pub const STS_CCW_DEAD: u8 = 27;
pub const STS_OFS_L: u8 = 31;
pub const STS_OFS_H: u8 = 32;
pub const STS_MODE: u8 = 33;

// SRAM RW
pub const STS_TORQUE_ENABLE: u8 = 40;
pub const STS_ACC: u8 = 41;
pub const STS_GOAL_POSITION_L: u8 = 42;
pub const STS_GOAL_POSITION_H: u8 = 43;
pub const STS_GOAL_TIME_L: u8 = 44;
pub const STS_GOAL_TIME_H: u8 = 45;
pub const STS_GOAL_SPEED_L: u8 = 46;
pub const STS_GOAL_SPEED_H: u8 = 47;
pub const STS_LOCK: u8 = 55;

// SRAM RO
pub const STS_PRESENT_POSITION_L: u8 = 56;
pub const STS_PRESENT_POSITION_H: u8 = 57;
pub const STS_PRESENT_SPEED_L: u8 = 58;
pub const STS_PRESENT_SPEED_H: u8 = 59;
pub const STS_PRESENT_LOAD_L: u8 = 60;
pub const STS_PRESENT_LOAD_H: u8 = 61;
pub const STS_PRESENT_VOLTAGE: u8 = 62;
pub const STS_PRESENT_TEMPERATURE: u8 = 63;
pub const STS_STATUS: u8 = 65;
pub const STS_MOVING: u8 = 66;
pub const STS_PRESENT_CURRENT_L: u8 = 69;
pub const STS_PRESENT_CURRENT_H: u8 = 70;