Skip to Content
VectorLib

TrChassis

vectorlib::TrChassis — fields, methods, parameters and return types.


pub struct TrChassis

Performs distance sensor resets (tr_chassis).

Create it while the robot is not moving.

View source

Methods

Prop

Type

new

pub fn new(chassis: impl TrDrivebase + 'static, sensors: [TrSensor; 4]) -> Self

A TitanReset chassis on a plastic field. sensors are [north, east, south, west]: the sensors facing the front, right, back and left of the robot.

Parameters

Returns

Self

View source

new_with_field

pub fn new_with_field(
        chassis: impl TrDrivebase + 'static,
        sensors: [TrSensor; 4],
        field_radius: f32,
    ) -> Self

Like TrChassis::new, with the field radius (see tr_fields).

Parameters

Prop

Type

Returns

Self

View source

sensor

pub fn sensor(&self, index: usize) -> &TrSensor

The sensor in index: 0 north, 1 east, 2 south, 3 west.

Panics

If index is greater than 3.

Parameters

Prop

Type

Returns

&TrSensor

View source

quadrant_recursive

pub fn quadrant_recursive(mut heading: f32) -> f32

Normalize a heading to [0, 360] by adding or subtracting whole turns.

Parameters

Prop

Type

Returns

f32

View source

can_position_exist

pub fn can_position_exist(pose: TrVector3) -> bool

Whether the position is inside the field (not out of bounds).

Parameters

Prop

Type

Returns

bool

View source

get_quadrant_string

pub fn get_quadrant_string(quadrant: TrQuadrant) -> &'static str

The quadrant's name, as TitanReset spells it.

Parameters

Prop

Type

Returns

&'static str

View source

sensor_relevancy

pub fn sensor_relevancy(&self) -> TrQuadrant

The heading sector of the robot's current heading (which sensors face which walls).

Returns

TrQuadrant

View source

sensor_relevancy_for

pub fn sensor_relevancy_for(heading: f32) -> TrQuadrant

The heading sector of a heading normalized to [0, 360]: (315, 45] → PosPos, (45, 135] → NegPos, (135, 225] → NegNeg, (225, 315] → PosNeg.

Parameters

Prop

Type

Returns

TrQuadrant

View source

get_quadrant

pub fn get_quadrant(&self) -> TrQuadrant

The field quadrant of the robot's current position (PosPos on an axis).

Returns

TrQuadrant

View source

conf_avg

pub fn conf_avg(one: TrDistance, two: TrDistance) -> f32

Average confidence of two readings.

Parameters

Prop

Type

Returns

f32

View source

get_position_calculation

pub fn get_position_calculation(&self, quadrant: TrQuadrant) -> TrConfPair<TrVector3>

The position the sensors give in quadrant, using the robot's current heading.

Parameters

Prop

Type

Returns

TrConfPair<TrVector3>

View source

get_position_calculation_with

pub fn get_position_calculation_with(
        &self,
        quadrant: TrQuadrant,
        heading: f32,
    ) -> TrConfPair<TrVector3>

The position the sensors give in quadrant for a robot at heading, with the confidence of the two readings used (0 if the position is out of bounds).

Parameters

Prop

Type

Returns

TrConfPair<TrVector3>

View source

perform_dsr

pub fn perform_dsr(&self) -> bool

Distance sensor reset when the robot knows roughly where it is and where it faces: uses the quadrant of the current position. Returns whether the reset happened (the calculated position was in bounds and the readings had confidence).

Returns

bool

View source

perform_dsr_quad

pub fn perform_dsr_quad(&self, quadrant: TrQuadrant) -> bool

Distance sensor reset in a given quadrant. Use after a movement that may have crossed quadrants, such as driving over a parking zone.

Parameters

Prop

Type

Returns

bool

View source

perform_dsr_init

pub fn perform_dsr_init(&self, quadrant: TrQuadrant, heading: f32) -> bool

Distance sensor reset when the robot does not know where it is: sets the heading, then resets in quadrant. Use before an autonomous starts, where the robot always starts in a familiar place.

Parameters

Prop

Type

Returns

bool

View source

is_sensor_used

pub fn is_sensor_used(&self, r_sensor: i32) -> bool

Whether a sensor (a tr_sensors flag) was used by the last position calculation.

Parameters

Prop

Type

Returns

bool

View source

debug_lines

pub fn debug_lines(&self) -> [(u8, String); 5]

The lines TitanReset's debug screen (update_display) prints, as (LLEMU line, text).

TitanReset reads the heading for this screen from an inertial-sensor pointer it never sets; this reads the drivebase heading instead.

Returns

[(u8, String); 5]

View source

start_location_recording

pub fn start_location_recording(&self, name: &str, date: Option<&str>, time: Option<&str>)

Record the drivebase pose every 50 ms in a background task, to the file <name>_<date>_<time>_<millis>.txt on the SD card, one x, y, heading line each.

date and time default to the date and time VectorLib was built, in the format of C's __DATE__ ("Mar 7 2026") and __TIME__ ("17:36:11"); spaces in the date and colons in the time become dashes. Starting a recording stops the previous one.

Parameters

Prop

Type

Returns

()

View source

stop_location_recording

pub fn stop_location_recording(&self)

Stop the current location recording.

Returns

()

View source