Trait Compete

Source
pub trait Compete: Sized {
    // Provided methods
    async fn connected(&mut self) { ... }
    async fn disconnected(&mut self) { ... }
    async fn disabled(&mut self) { ... }
    async fn autonomous(&mut self) { ... }
    async fn driver(&mut self) { ... }
}
Expand description

A set of functions to run when the competition is in a particular mode.

This trait allows you to declare different functions on a common robot struct to be executed when competition state changes. By implementing Compete, your robot can respond to changes in the various phases of a competition, such as autonomous operation, driver control, or downtime between modes.

§Example

#![no_std]
#![no_main]

use vexide::prelude::*;

struct MyRobot {}

impl Compete for MyRobot {
    async fn autonomous(&mut self) {
        println!("Running in autonomous mode!");
    }

    async fn driver(&mut self) {
        println!("Running in driver mode!");
    }
}

#[vexide::main]
async fn main(_peripherals: Peripherals) {
    let my_robot = MyRobot {};
    my_robot.compete().await;
}

By awaiting the compete() function on our robot, we are handing over execution to vexide’s CompetitionRuntime, which will run a different function on the Compete trait depending on what is happening in the match.

Provided Methods§

Source

async fn connected(&mut self)

Runs when the robot becomes connected into a competition controller.

See CompetitionBuilder::on_connect for more information.

Source

async fn disconnected(&mut self)

Runs when the robot disconnects from a competition controller.

This function does NOT run if connection to the match is lost due to a radio issue. It will only execute if the field control wire becomes physically disconnected from the controller (i.e.) from unplugging after a match ends.

See CompetitionBuilder::on_disconnect for more information.

Source

async fn disabled(&mut self)

Runs when the robot is disabled.

When in disabled mode, voltage commands to motors are disabled. Motors are forcibly locked to the “coast” brake mode and cannot be moved.

Robots may be placed into disabled mode at any point in the competition after connecting, but are typically disabled before the autonomous period, between autonomous and opcontrol periods, and following the opcontrol period of a match.

Source

async fn autonomous(&mut self)

Runs when the robot is put into autonomous mode.

When in autonomous mode, all motors and sensors may be accessed, however user input from controller buttons and joysticks is not available to be read.

Robots may be placed into autonomous mode at any point in the competition after connecting, but are typically placed into this mode at the start of a match.

Source

async fn driver(&mut self)

Runs when the robot is put into driver control mode.

When in opcontrol mode, all device access is available including access to controller joystick values for reading user-input from drive team members.

Robots may be placed into opcontrol mode at any point in the competition after connecting, but are typically placed into this mode following the autonomous period.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§