vexide-motorgroup

Crates.iovexide-motorgroup
lib.rsvexide-motorgroup
version
sourcesrc
created_at2025-02-28 13:59:18.425198+00
updated_at2025-04-13 13:58:26.188424+00
descriptionMotor groups for vexide in userland.
homepage
repositoryhttps://github.com/zabackary/vexide-motorgroup/
max_upload_size
id1572835
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
(zabackary)

documentation

README

vexide-motorgroup

Documentation Crates.io License Downloads CI status Made with vexide badge

Missing MotorGroup from VEXCode or PROS? This is a simple implementation of a MotorGroup for vexide which allows you to group motors together and control them as one.

Installation

Add the following to your Cargo.toml:

[dependencies]
# ... other dependencies
vexide-motorgroup = "2.1.0"

Or if you prefer the command line:

cargo add vexide-motorgroup

Usage

Normally, you would have to set each motor's target and other values individually even if the motors were physically connected in a drivetrain or similar, but with MotorGroup, you can control them as if they were one motor.

Just create a MotorGroup with a Vec of Motors and use the MotorGroup methods just like you would with a Motor. It's that simple!

#![no_std]
#![no_main]

extern crate alloc;

use core::time::Duration;

use alloc::vec;
use vexide_motorgroup::MotorGroup;

use vexide::prelude::*;

#[vexide::main]
async fn main(peripherals: Peripherals) {
    // Here's where the magic happens
    let mut motor_group = MotorGroup::new(vec![
        Motor::new(peripherals.port_1, Gearset::Green, Direction::Forward),
        Motor::new(peripherals.port_2, Gearset::Green, Direction::Forward),
    ]);

    // Set the motor group's target to a voltage as if it were a motor
    motor_group.set_voltage(5.0).unwrap();
    sleep(Duration::from_secs(1)).await;

    // Set the motor group's target to a position
    motor_group
        .set_position_target(Position::from_degrees(90.0), 200)
        .unwrap();
    sleep(Duration::from_secs(1)).await;

    // Set the motor group's target to a velocity
    motor_group.set_velocity(100).unwrap();
    sleep(Duration::from_secs(1)).await;

    // Brake the motor group
    motor_group.brake(BrakeMode::Hold).unwrap();
}

Error handling

Read errors

For functions returning values and reading data (i.e., those taking a read-only reference to self), upon encountering an error accessing any motor, the result will be a MotorGroupError that contains all the errors encountered during the operation. Using MotorGroupError::result will return the average of all the results that were successfully read.

Write errors

vexide-motorgroup provides two different strategies for handling write errors. Both of them will return an Err when any motor returns an error.

  1. WriteErrorStrategy::Ignore (default): This strategy will ignore errors and continue writing to the other motors.
  2. WriteErrorStrategy::Stop: This strategy will stop writing to the other motors and return the error immediately.
Commit count: 0

cargo fmt