LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
squiggles::SplineGenerator Class Reference

#include <spline.hpp>

Classes

struct  ConstrainedState
 An intermediate value used in the parameterization step. More...
 
struct  GeneratedPoint
 The output of the initial, "naive" generation step. More...
 
struct  GeneratedVector
 An intermediate value used in the "naive" generation step. More...
 

Public Member Functions

 SplineGenerator (Constraints iconstraints, std::shared_ptr< PhysicalModel > imodel=std::make_shared< PassthroughModel >(), double idt=0.1)
 Generates curves that match the given motion constraints.
 
std::vector< ProfilePointgenerate (std::vector< Pose > iwaypoints, bool fast=false)
 Creates a motion profiled path between the given waypoints.
 
std::vector< ProfilePointgenerate (std::initializer_list< Pose > iwaypoints, bool fast=false)
 
std::vector< ProfilePointgenerate (std::vector< ControlVector > iwaypoints)
 Creates a motion profiled path between the given waypoints.
 
std::vector< ProfilePointgenerate (std::initializer_list< ControlVector > iwaypoints)
 
std::vector< GeneratedVectorgen_single_raw_path (ControlVector start, ControlVector end, int duration, double start_vel, double end_vel)
 
std::vector< GeneratedPointgradient_descent (ControlVector &start, ControlVector &end, bool fast)
 Runs a Gradient Descent algorithm to minimize the linear acceleration, linear jerk, and curvature for the generated path.
 
template<class Iter >
std::vector< ProfilePoint_generate (Iter start, Iter end, bool fast)
 The actual function called by the "generate" functions.
 
std::vector< GeneratedPointgen_raw_path (ControlVector &start, ControlVector &end, bool fast)
 Performs the "naive" generation step.
 
std::vector< ProfilePointparameterize (const ControlVector start, const ControlVector end, const std::vector< GeneratedPoint > &raw_path, const double preferred_start_vel, const double preferred_end_vel, const double start_time)
 Imposes a linear motion profile on the raw path.
 
std::vector< ProfilePointintegrate_constrained_states (std::vector< ConstrainedState > constrainedStates)
 Finds the new timestamps for each point along the curve based on the motion profile.
 
ProfilePoint get_point_at_time (const ControlVector start, const ControlVector end, std::vector< ProfilePoint > points, double t)
 Finds the ProfilePoint on the profiled curve for the given timestamp.
 
ProfilePoint lerp_point (QuinticPolynomial x_qp, QuinticPolynomial y_qp, ProfilePoint start, ProfilePoint end, double i)
 Linearly interpolates between points along the profiled curve.
 
QuinticPolynomial get_x_spline (const ControlVector start, const ControlVector end, const double duration)
 Returns the spline curve for the given control vectors and path duration.
 
QuinticPolynomial get_y_spline (const ControlVector start, const ControlVector end, const double duration)
 
void enforce_accel_lims (ConstrainedState *state)
 Applies the general constraints and model constraints to the given state.
 
void forward_pass (ConstrainedState *predecessor, ConstrainedState *successor)
 Imposes the motion profile constraints on a segment of the path from the perspective of iterating forwards through the path.
 
void backward_pass (ConstrainedState *predecessor, ConstrainedState *successor)
 Imposes the motion profile constraints on a segment of the path from the perspective of iterating backwards through the path.
 
double vf (double vi, double a, double ds)
 Calculates the final velocity for a path segment.
 
double ai (double vf, double vi, double s)
 Calculates the initial acceleration needed to match the segments' velocities.
 

Public Attributes

const double K_DEFAULT_VEL = 1.0
 This is factor is used to create a "dummy velocity" in the initial path generation step one or both of the preferred start or end velocities is zero.
 

Static Public Attributes

static constexpr double K_EPSILON = 1e-5
 Values that are closer to each other than this value are considered equal.
 

Protected Attributes

Constraints constraints
 The maximum allowable values for the robot's motion.
 
std::shared_ptr< PhysicalModelmodel
 Defines the physical structure of the robot and translates the linear kinematics to wheel velocities.
 
double dt
 The time difference between each value in the generated path.
 
const int T_MIN = 2
 The minimum and maximum durations for a path to take.
 
const int T_MAX = 15
 
const int MAX_GRAD_DESCENT_ITERATIONS = 10
 

Detailed Description

Definition at line 22 of file spline.hpp.

Constructor & Destructor Documentation

◆ SplineGenerator()

squiggles::SplineGenerator::SplineGenerator ( Constraints  iconstraints,
std::shared_ptr< PhysicalModel imodel = std::make_shared< PassthroughModel >(),
double  idt = 0.1 
)

Generates curves that match the given motion constraints.

Parameters
iconstraintsThe maximum allowable values for the robot's motion.
imodelThe robot's physical characteristics and constraints
idtThe difference in time in seconds between each state for the generated paths.

Member Function Documentation

◆ _generate()

template<class Iter >
std::vector< ProfilePoint > squiggles::SplineGenerator::_generate ( Iter  start,
Iter  end,
bool  fast 
)

The actual function called by the "generate" functions.

Parameters
startAn iterator pointing to the first ControlVector in the path
endAn iterator pointting to the last ControlVector in the path
Returns
The points from each path concatenated together

◆ ai()

double squiggles::SplineGenerator::ai ( double  vf,
double  vi,
double  s 
)

Calculates the initial acceleration needed to match the segments' velocities.

◆ backward_pass()

void squiggles::SplineGenerator::backward_pass ( ConstrainedState predecessor,
ConstrainedState successor 
)

Imposes the motion profile constraints on a segment of the path from the perspective of iterating backwards through the path.

◆ enforce_accel_lims()

void squiggles::SplineGenerator::enforce_accel_lims ( ConstrainedState state)

Applies the general constraints and model constraints to the given state.

◆ forward_pass()

void squiggles::SplineGenerator::forward_pass ( ConstrainedState predecessor,
ConstrainedState successor 
)

Imposes the motion profile constraints on a segment of the path from the perspective of iterating forwards through the path.

◆ gen_raw_path()

std::vector< GeneratedPoint > squiggles::SplineGenerator::gen_raw_path ( ControlVector start,
ControlVector end,
bool  fast 
)

Performs the "naive" generation step.

This step calculates the spline polynomials that fit within the SplineGenerator's acceleration and jerk constraints and returns the points that form the curve.

◆ gen_single_raw_path()

std::vector< GeneratedVector > squiggles::SplineGenerator::gen_single_raw_path ( ControlVector  start,
ControlVector  end,
int  duration,
double  start_vel,
double  end_vel 
)

◆ generate() [1/4]

std::vector< ProfilePoint > squiggles::SplineGenerator::generate ( std::initializer_list< ControlVector iwaypoints)

◆ generate() [2/4]

std::vector< ProfilePoint > squiggles::SplineGenerator::generate ( std::initializer_list< Pose iwaypoints,
bool  fast = false 
)

◆ generate() [3/4]

std::vector< ProfilePoint > squiggles::SplineGenerator::generate ( std::vector< ControlVector iwaypoints)

Creates a motion profiled path between the given waypoints.

Parameters
iwaypointsThe list of vectors that the robot should reach along the path.
Returns
A series of robot states defining a path between the vectors.

◆ generate() [4/4]

std::vector< ProfilePoint > squiggles::SplineGenerator::generate ( std::vector< Pose iwaypoints,
bool  fast = false 
)

Creates a motion profiled path between the given waypoints.

Parameters
iwaypointsThe list of poses that the robot should reach along the path.
fastIf true, the path optimization process will stop as soon as the constraints are met. If false, the optimizer will find the smoothest possible path between the points.
Returns
A series of robot states defining a path between the poses.

◆ get_point_at_time()

ProfilePoint squiggles::SplineGenerator::get_point_at_time ( const ControlVector  start,
const ControlVector  end,
std::vector< ProfilePoint points,
double  t 
)

Finds the ProfilePoint on the profiled curve for the given timestamp.

This with interpolate between points on the curve if a point with an exact matching timestamp is not found.

◆ get_x_spline()

QuinticPolynomial squiggles::SplineGenerator::get_x_spline ( const ControlVector  start,
const ControlVector  end,
const double  duration 
)

Returns the spline curve for the given control vectors and path duration.

◆ get_y_spline()

QuinticPolynomial squiggles::SplineGenerator::get_y_spline ( const ControlVector  start,
const ControlVector  end,
const double  duration 
)

◆ gradient_descent()

std::vector< GeneratedPoint > squiggles::SplineGenerator::gradient_descent ( ControlVector start,
ControlVector end,
bool  fast 
)

Runs a Gradient Descent algorithm to minimize the linear acceleration, linear jerk, and curvature for the generated path.

This is used when there is not a start/end velocity specified for a given path.

◆ integrate_constrained_states()

std::vector< ProfilePoint > squiggles::SplineGenerator::integrate_constrained_states ( std::vector< ConstrainedState constrainedStates)

Finds the new timestamps for each point along the curve based on the motion profile.

◆ lerp_point()

ProfilePoint squiggles::SplineGenerator::lerp_point ( QuinticPolynomial  x_qp,
QuinticPolynomial  y_qp,
ProfilePoint  start,
ProfilePoint  end,
double  i 
)

Linearly interpolates between points along the profiled curve.

◆ parameterize()

std::vector< ProfilePoint > squiggles::SplineGenerator::parameterize ( const ControlVector  start,
const ControlVector  end,
const std::vector< GeneratedPoint > &  raw_path,
const double  preferred_start_vel,
const double  preferred_end_vel,
const double  start_time 
)

Imposes a linear motion profile on the raw path.

This step creates the velocity and acceleration values to command the robot at each point along the curve.

◆ vf()

double squiggles::SplineGenerator::vf ( double  vi,
double  a,
double  ds 
)

Calculates the final velocity for a path segment.

Member Data Documentation

◆ constraints

Constraints squiggles::SplineGenerator::constraints
protected

The maximum allowable values for the robot's motion.

Definition at line 69 of file spline.hpp.

◆ dt

double squiggles::SplineGenerator::dt
protected

The time difference between each value in the generated path.

Definition at line 80 of file spline.hpp.

◆ K_DEFAULT_VEL

const double squiggles::SplineGenerator::K_DEFAULT_VEL = 1.0

This is factor is used to create a "dummy velocity" in the initial path generation step one or both of the preferred start or end velocities is zero.

The velocity will be replaced with the preferred start/end velocity in parameterization but a nonzero velocity is needed for the spline calculation.

This was 1.2 in the WPILib example but that large of a value seems to create wild paths, 0.12 worked better in testing with VEX-sized paths.

Definition at line 101 of file spline.hpp.

◆ K_EPSILON

constexpr double squiggles::SplineGenerator::K_EPSILON = 1e-5
staticconstexpr

Values that are closer to each other than this value are considered equal.

Definition at line 306 of file spline.hpp.

◆ MAX_GRAD_DESCENT_ITERATIONS

const int squiggles::SplineGenerator::MAX_GRAD_DESCENT_ITERATIONS = 10
protected

Definition at line 88 of file spline.hpp.

◆ model

std::shared_ptr<PhysicalModel> squiggles::SplineGenerator::model
protected

Defines the physical structure of the robot and translates the linear kinematics to wheel velocities.

Definition at line 75 of file spline.hpp.

◆ T_MAX

const int squiggles::SplineGenerator::T_MAX = 15
protected

Definition at line 87 of file spline.hpp.

◆ T_MIN

const int squiggles::SplineGenerator::T_MIN = 2
protected

The minimum and maximum durations for a path to take.

A larger range allows for longer possible paths at the expense of a longer path generation time.

Definition at line 86 of file spline.hpp.


The documentation for this class was generated from the following file: