LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
spline.hpp
Go to the documentation of this file.
1
7#ifndef _SQUIGGLES_SPLINE_HPP_
8#define _SQUIGGLES_SPLINE_HPP_
9
10#include <initializer_list>
11#include <memory>
12#include <vector>
13
14#include "constraints.hpp"
20
21namespace squiggles {
23 public:
33 std::shared_ptr<PhysicalModel> imodel =
34 std::make_shared<PassthroughModel>(),
35 double idt = 0.1);
36
48 std::vector<ProfilePoint> generate(std::vector<Pose> iwaypoints,
49 bool fast = false);
50 std::vector<ProfilePoint> generate(std::initializer_list<Pose> iwaypoints,
51 bool fast = false);
52
61 std::vector<ProfilePoint> generate(std::vector<ControlVector> iwaypoints);
62 std::vector<ProfilePoint>
63 generate(std::initializer_list<ControlVector> iwaypoints);
64
65 protected:
70
75 std::shared_ptr<PhysicalModel> model;
76
80 double dt;
81
86 const int T_MIN = 2;
87 const int T_MAX = 15;
89
100 public:
101 const double K_DEFAULT_VEL = 1.0;
102
109 GeneratedPoint(Pose ipose, double icurvature = 0.0)
110 : pose(ipose), curvature(icurvature) {}
111
112 std::string to_string() const {
113 return "GeneratedPoint: {" + pose.to_string() +
114 ", curvature: " + std::to_string(curvature) + "}";
115 }
116
118 double curvature;
119 };
120
128 double ivel,
129 double iaccel,
130 double ijerk)
131 : point(ipoint), vel(ivel), accel(iaccel), jerk(ijerk) {}
132
134 double vel;
135 double accel;
136 double jerk;
137
138 std::string to_string() const {
139 return "GeneratedVector: {" + point.to_string() +
140 ", vel: " + std::to_string(vel) +
141 ", accel: " + std::to_string(accel) +
142 ", jerk: " + std::to_string(jerk) + "}";
143 }
144 };
145
146 std::vector<GeneratedVector> gen_single_raw_path(ControlVector start,
147 ControlVector end,
148 int duration,
149 double start_vel,
150 double end_vel);
158 std::vector<GeneratedPoint>
160
168 double icurvature,
169 double idistance,
170 double imax_vel,
171 double imin_accel,
172 double imax_accel)
173 : pose(ipose),
174 curvature(icurvature),
175 distance(idistance),
176 max_vel(imax_vel),
177 min_accel(imin_accel),
178 max_accel(imax_accel) {}
179
180 ConstrainedState() = default;
181
183 double curvature = 0;
184 double distance = 0;
185 double max_vel = 0;
186 double min_accel = 0;
187 double max_accel = 0;
188
189 std::string to_string() const {
190 return "ConstrainedState: {x: " + std::to_string(pose.x) +
191 ", y: " + std::to_string(pose.y) +
192 ", yaw: " + std::to_string(pose.yaw) +
193 ", k: " + std::to_string(curvature) +
194 ", dist: " + std::to_string(distance) +
195 ", v: " + std::to_string(max_vel) +
196 ", min_a: " + std::to_string(min_accel) +
197 ", max_a: " + std::to_string(max_accel) + "}";
198 }
199 };
200
209 template <class Iter>
210 std::vector<ProfilePoint> _generate(Iter start, Iter end, bool fast);
211
212 public:
220 std::vector<GeneratedPoint>
221 gen_raw_path(ControlVector& start, ControlVector& end, bool fast);
222
229 std::vector<ProfilePoint>
231 const ControlVector end,
232 const std::vector<GeneratedPoint>& raw_path,
233 const double preferred_start_vel,
234 const double preferred_end_vel,
235 const double start_time);
236
241 std::vector<ProfilePoint>
242 integrate_constrained_states(std::vector<ConstrainedState> constrainedStates);
243
251 const ControlVector end,
252 std::vector<ProfilePoint> points,
253 double t);
254
260 ProfilePoint start,
261 ProfilePoint end,
262 double i);
263
268 const ControlVector end,
269 const double duration);
271 const ControlVector end,
272 const double duration);
273
278
283 void forward_pass(ConstrainedState* predecessor, ConstrainedState* successor);
284
290 ConstrainedState* successor);
291
295 double vf(double vi, double a, double ds);
296
301 double ai(double vf, double vi, double s);
302
306 static constexpr double K_EPSILON = 1e-5;
307};
308} // namespace squiggles
309
310#endif
double yaw
Definition pose.hpp:63
std::string to_string() const
Serializes the Pose data for debugging.
Definition pose.hpp:46
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.
Constraints constraints
The maximum allowable values for the robot's motion.
Definition spline.hpp:69
const double K_DEFAULT_VEL
This is factor is used to create a "dummy velocity" in the initial path generation step one or both o...
Definition spline.hpp:101
double ai(double vf, double vi, double s)
Calculates the initial acceleration needed to match the segments' velocities.
ProfilePoint lerp_point(QuinticPolynomial x_qp, QuinticPolynomial y_qp, ProfilePoint start, ProfilePoint end, double i)
Linearly interpolates between points along the profiled curve.
std::vector< ProfilePoint > 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.
const int T_MIN
The minimum and maximum durations for a path to take.
Definition spline.hpp:86
std::vector< GeneratedPoint > gen_raw_path(ControlVector &start, ControlVector &end, bool fast)
Performs the "naive" generation step.
void enforce_accel_lims(ConstrainedState *state)
Applies the general constraints and model constraints to the given state.
std::vector< ProfilePoint > generate(std::vector< ControlVector > iwaypoints)
Creates a motion profiled path between the given waypoints.
double dt
The time difference between each value in the generated path.
Definition spline.hpp:80
void forward_pass(ConstrainedState *predecessor, ConstrainedState *successor)
Imposes the motion profile constraints on a segment of the path from the perspective of iterating for...
std::vector< ProfilePoint > generate(std::vector< Pose > iwaypoints, bool fast=false)
Creates a motion profiled path between the given waypoints.
QuinticPolynomial get_y_spline(const ControlVector start, const ControlVector end, const double duration)
std::vector< ProfilePoint > generate(std::initializer_list< ControlVector > iwaypoints)
std::vector< GeneratedPoint > gradient_descent(ControlVector &start, ControlVector &end, bool fast)
Runs a Gradient Descent algorithm to minimize the linear acceleration, linear jerk,...
std::vector< ProfilePoint > _generate(Iter start, Iter end, bool fast)
The actual function called by the "generate" functions.
std::shared_ptr< PhysicalModel > model
Defines the physical structure of the robot and translates the linear kinematics to wheel velocities.
Definition spline.hpp:75
static constexpr double K_EPSILON
Values that are closer to each other than this value are considered equal.
Definition spline.hpp:306
void backward_pass(ConstrainedState *predecessor, ConstrainedState *successor)
Imposes the motion profile constraints on a segment of the path from the perspective of iterating bac...
SplineGenerator(Constraints iconstraints, std::shared_ptr< PhysicalModel > imodel=std::make_shared< PassthroughModel >(), double idt=0.1)
Generates curves that match the given motion constraints.
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.
double vf(double vi, double a, double ds)
Calculates the final velocity for a path segment.
std::vector< ProfilePoint > integrate_constrained_states(std::vector< ConstrainedState > constrainedStates)
Finds the new timestamps for each point along the curve based on the motion profile.
std::vector< GeneratedVector > gen_single_raw_path(ControlVector start, ControlVector end, int duration, double start_vel, double end_vel)
std::vector< ProfilePoint > generate(std::initializer_list< Pose > iwaypoints, bool fast=false)
const int MAX_GRAD_DESCENT_ITERATIONS
Definition spline.hpp:88
Copyright 2020 Jonathan Bayless.
An intermediate value used in the parameterization step.
Definition spline.hpp:166
ConstrainedState(Pose ipose, double icurvature, double idistance, double imax_vel, double imin_accel, double imax_accel)
Definition spline.hpp:167
The output of the initial, "naive" generation step.
Definition spline.hpp:108
GeneratedPoint(Pose ipose, double icurvature=0.0)
Definition spline.hpp:109
An intermediate value used in the "naive" generation step.
Definition spline.hpp:126
GeneratedVector(GeneratedPoint ipoint, double ivel, double iaccel, double ijerk)
Definition spline.hpp:127