DriverStation

Struct DriverStation 

Source
pub struct DriverStation { /* private fields */ }
Expand description

Represents a connection to the roboRIO acting as a driver station

This struct will contain relevant functions to update the state of the robot, and also manages the threads that manage network connections and joysticks

Implementations§

Source§

impl DriverStation

Source

pub fn new_team(team_number: u32, alliance: Alliance) -> DriverStation

Creates a new driver station with the given team number and alliance

This driver station will attempt to connect to a roboRIO at 10.TE.AM.2, if the roboRIO is at a different ip, use [new] and specify the ip directly.

Examples found in repository?
examples/simple.rs (line 9)
8fn main() {
9    let mut ds = DriverStation::new_team(4069, Alliance::new_red(1));
10
11    thread::sleep(Duration::from_millis(1500));
12    ds.restart_code();
13    loop {
14        println!("Code: {}", ds.trace().is_code_started());
15
16        thread::sleep(Duration::from_millis(20));
17    }
18}
Source

pub fn new(ip: &str, alliance: Alliance, team_number: u32) -> DriverStation

Creates a new driver station for the given alliance station and team number Connects to the roborio at ip. To infer the ip from team_number, use new_team instead.

Source

pub fn set_joystick_supplier( &mut self, supplier: impl Fn() -> Vec<Vec<JoystickValue>> + Send + Sync + 'static, )

Provides a closure that will be called when constructing outbound packets to append joystick values

Source

pub fn set_tcp_consumer( &mut self, consumer: impl FnMut(TcpPacket) + Send + Sync + 'static, )

Provides a closure that will be called when TCP packets are received from the roboRIO

Example usage: Logging all stdout messages from robot code.

Source

pub fn set_alliance(&mut self, alliance: Alliance)

Changes the alliance for the given DriverStation

Source

pub fn set_mode(&mut self, mode: Mode)

Changes the given mode the robot will be in

Source

pub fn ds_mode(&self) -> DsMode

Source

pub fn set_team_number(&mut self, team_number: u32)

Changes the team number of this driver station, as well as the ip the driver station will attempt to connect to. The ip of the new roboRIO target is 10.TE.AM.2

Source

pub fn set_use_usb(&mut self, use_usb: bool)

Source

pub fn team_number(&self) -> u32

Source

pub fn set_game_specific_message(&mut self, message: &str) -> Result<()>

Sets the game specific message sent to the robot, and used during the autonomous period

Source

pub fn mode(&self) -> Mode

Returns the current mode of the robot

Source

pub fn enable(&mut self)

Enables outputs on the robot

Source

pub fn restart_code(&mut self)

Instructs the roboRIO to restart robot code

Examples found in repository?
examples/simple.rs (line 12)
8fn main() {
9    let mut ds = DriverStation::new_team(4069, Alliance::new_red(1));
10
11    thread::sleep(Duration::from_millis(1500));
12    ds.restart_code();
13    loop {
14        println!("Code: {}", ds.trace().is_code_started());
15
16        thread::sleep(Duration::from_millis(20));
17    }
18}
Source

pub fn restart_roborio(&mut self)

Instructs the roboRIO to reboot

Source

pub fn enabled(&self) -> bool

Returns whether the robot is currently enabled

Source

pub fn trace(&self) -> Trace

Returns the last received Trace from the robot

Examples found in repository?
examples/simple.rs (line 14)
8fn main() {
9    let mut ds = DriverStation::new_team(4069, Alliance::new_red(1));
10
11    thread::sleep(Duration::from_millis(1500));
12    ds.restart_code();
13    loop {
14        println!("Code: {}", ds.trace().is_code_started());
15
16        thread::sleep(Duration::from_millis(20));
17    }
18}
Source

pub fn battery_voltage(&self) -> f32

Returns the last received battery voltage from the robot

Source

pub fn queue_udp(&mut self, udp_tag: UdpTag)

Queues a UDP tag to be transmitted with the next outbound packet to the roboRIO

Source

pub fn udp_queue(&self) -> Vec<UdpTag>

Returns a Vec of the current contents of the UDP queue

Source

pub fn queue_tcp(&mut self, tcp_tag: TcpTag)

Queues a TCP tag to be transmitted to the roboRIO

Source

pub fn estop(&mut self)

Disables outputs on the robot and disallows enabling it until the code is restarted.

Source

pub fn estopped(&self) -> bool

Returns whether the robot is currently E-stopped

Source

pub fn disable(&mut self)

Disables outputs on the robot

Trait Implementations§

Source§

impl Drop for DriverStation

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V