Skip to main content

SwerveTrajectoryGenerator

Struct SwerveTrajectoryGenerator 

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

This trajectory generator class contains functions to generate time-optimal trajectories for several drivetrain types.

Implementations§

Source§

impl SwerveTrajectoryGenerator

Source

pub fn new() -> SwerveTrajectoryGenerator

Constructs a new swerve trajectory optimization problem.

Source

pub fn set_drivetrain(&mut self, drivetrain: &SwerveDrivetrain)

Sets the Drivetrain object.

  • drivetrain - The drivetrain.
Source

pub fn set_bumpers(&mut self, front: f64, left: f64, right: f64, back: f64)

Adds a rectangular bumper to a list used when applying keep-out constraints.

  • front - Distance in meters from center to front bumper edge.
  • left - Distance in meters from center to left bumper edge.
  • right - Distance in meters from center to right bumper edge.
  • back - Distance in meters from center to back bumper edge.
Source

pub fn set_control_interval_counts(&mut self, counts: Vec<usize>)

Sets the number of discrete samples for each trajectory segment.

  • counts - The sequence of control interval counts per segment. Length is number of waypoints - 1.
Source

pub fn pose_wpt(&mut self, index: usize, pose: Pose2d)

Applies a pose constraint to a waypoint, and adds an initial guess with the same pose.

  • index - The waypoint’s index.
  • pose - The pose.
Source

pub fn translation_wpt( &mut self, index: usize, translation: Translation2d, heading_guess: f64, )

Applies a translation constraint to a waypoint, and adds an initial guess point with the same translation.

  • index - The waypoint’s index.
  • translation - The translation.
  • heading_guess - The heading initial guess.
Source

pub fn empty_wpt(&mut self, index: usize, pose_guess: Pose2d)

Sets a waypoint’s pose initial guess.

  • index - The waypoint’s index.
  • pose_guess - The pose initial guess.
Source

pub fn sgmt_initial_guess_points( &mut self, from_index: usize, guess_points: &Vec<Pose2d>, )

Adds a sequence of initial guess points between two waypoints.

The points are inserted between the waypoints at fromIndex and fromIndex + 1. Linear interpolation between the waypoint initial guess points and these segment initial guess points is used as the initial guess of the robot’s pose over the trajectory.

  • from_index - The index of the waypoint the initial guess point comes after.
  • guess_points - The sequence of initial guess points.
Source

pub fn wpt_linear_velocity_direction(&mut self, index: usize, angle: f64)

Applies a linear velocity direction constraint to a waypoint.

  • index - The waypoint’s index.
  • angle - The angle in radians.
Source

pub fn wpt_linear_velocity_max_magnitude( &mut self, index: usize, magnitude: f64, )

Applies a linear velocity max magnitude constraint to a waypoint.

  • index - The waypoint’s index.
  • magnitude - The magnitude.
Source

pub fn wpt_angular_velocity_max_magnitude( &mut self, index: usize, magnitude: f64, )

Applies an angular velocity max magnitude constraint to a waypoint.

  • index - The waypoint’s index.
  • magnitude - The magnitude.
Source

pub fn wpt_linear_acceleration_max_magnitude( &mut self, index: usize, magnitude: f64, )

Applies a linear acceleration max magnitude constraint to a waypoint.

  • index - The waypoint’s index.
  • magnitude - The magnitude.
Source

pub fn wpt_point_at( &mut self, index: usize, field_point: Translation2d, heading_tolerance: f64, flip: bool, )

Applies a point-at constraint to a waypoint.

  • index - The waypoint’s index.
  • field_point - The field point to point at.
  • heading_tolerance - The heading tolerance.
  • flip - Whether to point away from the field point.
Source

pub fn wpt_keep_in_circle( &mut self, index: usize, center: Translation2d, radius: f64, )

Applies a keep-in circle constraint to a waypoint.

Applies to the robot bumpers.

  • index - The waypoint’s index.
  • center - The circle’s center.
  • radius - The circle’s radius.
Source

pub fn wpt_keep_in_polygon( &mut self, index: usize, field_points: Vec<Translation2d>, )

Applies a keep-in polygon constraint to a waypoint.

Applies to the robot bumpers.

  • index - The waypoint’s index.
  • field_points - The points defining the keep-in polygon (must wind counterclockwise).
Source

pub fn wpt_keep_in_lane( &mut self, index: usize, center_line_start: Translation2d, center_line_end: Translation2d, tolerance: f64, )

Applies a keep-in lane constraint to a waypoint.

Applies to the robot center.

  • index - The waypoint’s index.
  • center_line_start - The center line’s start point.
  • center_line_end - The center line’s end point.
  • tolerance - The distance from the center line to each lane edge.
Source

pub fn wpt_keep_out_circle( &mut self, index: usize, center: Translation2d, radius: f64, )

Applies a keep-out circle constraint to a waypoint.

Applies to the robot bumpers.

  • index - The waypoint’s index.
  • center - The circle’s center.
  • radius - The circle’s radius.
Source

pub fn sgmt_linear_velocity_direction( &mut self, from_index: usize, to_index: usize, angle: f64, )

Applies a linear velocity direction constraint between two waypoints.

  • from_index - The first waypoint’s index.
  • to_index - The second waypoint’s index.
  • angle - The angle in radians.
Source

pub fn sgmt_linear_velocity_max_magnitude( &mut self, from_index: usize, to_index: usize, magnitude: f64, )

Applies a linear velocity max magnitude constraint between two waypoints.

  • from_index - The first waypoint’s index.
  • to_index - The second waypoint’s index.
  • magnitude - The magnitude.
Source

pub fn sgmt_angular_velocity_max_magnitude( &mut self, from_index: usize, to_index: usize, magnitude: f64, )

Applies an angular velocity max magnitude constraint between two waypoints.

  • from_index - The first waypoint’s index.
  • to_index - The second waypoint’s index.
  • magnitude - The magnitude.
Source

pub fn sgmt_linear_acceleration_max_magnitude( &mut self, from_index: usize, to_index: usize, magnitude: f64, )

Applies a linear acceleration max magnitude constraint between two waypoints.

  • from_index - The first waypoint’s index.
  • to_index - The second waypoint’s index.
  • magnitude - The magnitude.
Source

pub fn sgmt_point_at( &mut self, from_index: usize, to_index: usize, field_point: Translation2d, heading_tolerance: f64, flip: bool, )

Applies a point-at constraint between two waypoints.

  • from_index - The first waypoint’s index.
  • to_index - The second waypoint’s index.
  • field_point - The field point to point at.
  • heading_tolerance - The heading tolerance.
  • flip - Whether to point away from the field point.
Source

pub fn sgmt_keep_in_circle( &mut self, from_index: usize, to_index: usize, center: Translation2d, radius: f64, )

Applies a keep-in circle constraint between two waypoints.

Applies to the robot bumpers.

  • from_index - The first waypoint’s index.
  • to_index - The second waypoint’s index.
  • center - The circle’s center.
  • radius - The circle’s radius.
Source

pub fn sgmt_keep_in_polygon( &mut self, from_index: usize, to_index: usize, field_points: Vec<Translation2d>, )

Applies a keep-in polygon constraint between two waypoints.

Applies to the robot bumpers.

  • from_index - The first waypoint’s index.
  • to_index - The second waypoint’s index.
  • field_points - The points defining the keep-in polygon (must wind counterclockwise).
Source

pub fn sgmt_keep_in_lane( &mut self, from_index: usize, to_index: usize, center_line_start: Translation2d, center_line_end: Translation2d, tolerance: f64, )

Applies a keep-in lane constraint between two waypoints.

Applies to the robot center.

  • from_index - The first waypoint’s index.
  • to_index - The second waypoint’s index.
  • center_line_start - The center line’s start point.
  • center_line_end - The center line’s end point.
  • tolerance - The distance from the center line to each lane edge.
Source

pub fn sgmt_keep_out_circle( &mut self, from_index: usize, to_index: usize, center: Translation2d, radius: f64, )

Applies a keep-out circle constraint between two waypoints.

Applies to the robot bumpers.

  • from_index - The first waypoint’s index.
  • to_index - The second waypoint’s index.
  • center - The circle’s center.
  • radius - The circle’s radius.
Source

pub fn add_callback(&mut self, callback: fn(SwerveTrajectory, i64))

Adds a callback that will be called on each iteration of the solver.

  • callback - a fn (not a closure) to be executed. The callback’s first parameter will be a trajopt::SwerveTrajectory, and the second parameter will be an i64 equal to the handle passed in generate()

This function can be called multiple times to add multiple callbacks.

Source

pub fn generate( &self, diagnostics: bool, handle: i64, ) -> Result<SwerveTrajectory, TrajoptError>

Generates the trajectory.

  • diagnostics - If true, prints per-iteration details of the solver to stdout.
  • handle - A number used to identify results from this generation in the add_callback callback. If add_callback has not been called, this value has no significance.

Returns a result with either the final trajopt::SwerveTrajectory, or a TrajoptError if generation failed.

Trait Implementations§

Source§

impl Default for SwerveTrajectoryGenerator

Source§

fn default() -> Self

Returns the “default value” for a 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.