Skip to main content

Crate vesc

Crate vesc 

Source
Expand description

The VESC® firmware is an open source motor controller firmware, and this library implements the necessary structures and functions to encode commands and decode replies.

§Examples

§Encoding a Command

use vesc::{Command, ValuesMask};

let mut buf = [0u8; 64];
let command = Command::GetValuesSelective(ValuesMask::RPM | ValuesMask::VOLTAGE_IN);
let frame_len = vesc::encode(command, &mut buf).unwrap();
let frame = &buf[..frame_len];

§Decoding a Reply

use vesc::CommandReply;

match vesc::decode(&[2, 7, 50, 0, 0, 1, 128, 0, 0, 4, 210, 1, 176, 254, 22, 3]) {
    Ok((_, CommandReply::GetValuesSelective(values))) => {
        let rpm = values.rpm;
        let voltage_in = values.voltage_in;
    },
    _ => (),
}

§Decoding a Stream

use vesc::{Decoder, CommandReply};

let mut decoder = Decoder::default();
decoder.feed(&[2, 7, 50, 0, 0, 1, 128, 0, 0, 4, 210, 1, 176, 254, 22, 3]);

for reply in decoder.by_ref() {
    match reply {
        CommandReply::GetValuesSelective(values) => {
            let rpm = values.rpm;
            let voltage_in = values.voltage_in;
        },
        _ => (),
    }
}

Structs§

Decoder
A streaming decoder for VESC communication protocol.
FwInfo
Firmware build information returned by the motor controller.
FwVersion
Firmware version data returned by the motor controller.
NrfFlags
QmlAppFlags
SetupValues
Setup telemetry data returned by the motor controller in response to Command::GetValuesSetupSelective.
Stats
Runtime statistics returned by the motor controller.
StatsMask
A bitmask used with Command::GetStats to request specific statistics fields.
Values
Telemetry data returned by the motor controller.
ValuesMask
A bitmask used with Command::GetValuesSelective to request specific telemetry fields. This allows for efficient communication by requesting only the data you need, reducing bandwidth and processing overhead. Each flag corresponds to a field in the Values struct.
ValuesSetupMask
A bitmask used with Command::GetValuesSetupSelective to request setup telemetry fields. This corresponds to COMM_GET_VALUES_SETUP_SELECTIVE in firmware.

Enums§

Command
Commands that can be sent to a VESC controller.
CommandReply
Reply messages received from the VESC in response to commands.
DecodeError
Errors that can occur during command reply decoding.
EncodeError
Errors that can occur during command encoding.
FaultCode
Indicates specific error conditions or hardware failures.
HwType
QmlHw

Functions§

decode
Decodes a CommandReply from a byte buffer.
encode
Encodes a Command into a byte buffer.