Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
controllers::PredictiveStanleyController Class Reference

This class implements the Predictive Stanley Controller. This controller is used to follow a path using the Stanley method with predictive control. More...

#include <PredictiveStanleyController.h>

Collaboration diagram for controllers::PredictiveStanleyController:

Classes

struct  DriveVector
 

Public Member Functions

 PredictiveStanleyController ()
 Construct a new Predictive Stanley Controller:: Predictive Stanley Controller object.
 
 PredictiveStanleyController (const double dControlGain, const double dSteeringAngleLimit, const double dWheelbase, const int nPredictionHorizon, const double dPredictionTimeStep)
 Construct a new Predictive Stanley Controller:: Predictive Stanley Controller object.
 
 ~PredictiveStanleyController ()
 Destroy the Predictive Stanley Controller:: Predictive Stanley Controller object.
 
DriveVector Calculate (const geoops::RoverPose &stCurrentPose, const double dMaxSpeed=constants::NAVIGATING_MOTOR_POWER)
 Calculate an updated steering angle for the rover based on the current pose using the predictive stanley controller.
 
void SetReferencePath (const std::vector< geoops::Waypoint > &vReferencePath)
 Sets the path that the controller will follow.
 
void SetReferencePath (const std::vector< geoops::UTMCoordinate > &vReferencePath)
 Sets the path that the controller will follow.
 
void SetReferencePath (const std::vector< geoops::GPSCoordinate > &vReferencePath)
 Sets the path that the controller will follow.
 
void SetControlGain (const double dControlGain)
 Setter for the control gain of the stanley controller.
 
void SetSteeringAngleLimit (const double dSteeringAngleLimit)
 Setter for the steering angle limit of the stanley controller.
 
void SetWheelbase (const double dWheelbase)
 Setter for the wheelbase of the stanley controller.
 
std::vector< geoops::WaypointGetReferencePath () const
 Accessor for the reference path that the controller is following.
 
double GetControlGain () const
 Accessor for the control gain of the stanley controller.
 
double GetSteeringAngleLimit () const
 Accessor for the steering angle limit of the stanley controller.
 
double GetWheelbase () const
 Accessor for the wheelbase of the stanley controller.
 
double GetReferencePathTargetIndex () const
 Accessor for the current target index in the reference path.
 

Private Member Functions

geoops::Waypoint FindClosestWaypointInPath (const geoops::UTMCoordinate &stCurrentPosition, const double dCurrentHeading)
 Given the current position of the rover, find the point on the reference path that is closest to the rover's front axle position (based on the wheelbase). This is what makes sure the rover progresses forward in indexes along the path.
 

Private Attributes

BicycleModel m_BicycleModel
 
double m_dControlGain
 
double m_dSteeringAngleLimit
 
double m_dWheelbase
 
int m_nPredictionHorizon
 
double m_dPredictionTimeStep
 
int m_nCurrentReferencePathTargetIndex
 
std::vector< double > m_vReferencePathCurvature
 
std::vector< geoops::Waypointm_vReferencePath
 

Detailed Description

This class implements the Predictive Stanley Controller. This controller is used to follow a path using the Stanley method with predictive control.

Note
See docs/WhitePapers/2020-A-Path-Tracking-Algorithm-Using-Predictive-Stanley-Lateral-Controller.pdf
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10

Constructor & Destructor Documentation

◆ PredictiveStanleyController() [1/2]

controllers::PredictiveStanleyController::PredictiveStanleyController ( )

Construct a new Predictive Stanley Controller:: Predictive Stanley Controller object.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
38 {
39 // Initialize member variables.
40 m_dControlGain = constants::STANLEY_CROSSTRACK_CONTROL_GAIN;
41 m_dWheelbase = constants::STANLEY_DIST_TO_FRONT_AXLE;
42 m_dSteeringAngleLimit = constants::STANLEY_STEERING_ANGLE_LIMIT;
43 m_nPredictionHorizon = constants::STANLEY_PREDICTION_HORIZON;
44 m_dPredictionTimeStep = constants::STANLEY_PREDICTION_TIME_STEP;
45 m_nCurrentReferencePathTargetIndex = 0;
46 m_BicycleModel = BicycleModel(m_dWheelbase, 0.0, 0.0, 0.0);
47 }
This class implements the Bicycle Model. This model is used to predict the future state of the rover ...
Definition BicycleModel.hpp:35

◆ PredictiveStanleyController() [2/2]

controllers::PredictiveStanleyController::PredictiveStanleyController ( const double  dControlGain,
const double  dSteeringAngleLimit,
const double  dWheelbase,
const int  nPredictionHorizon,
const double  dPredictionTimeStep 
)

Construct a new Predictive Stanley Controller:: Predictive Stanley Controller object.

Parameters
dControlGain- The control gain for the controller.
dSteeringAngleLimit- The maximum steering angle the rover can turn.
dWheelbase- The distance between the front and rear axles of the rover.
nPredictionHorizon- The number of predictions to make.
dPredictionTimeStep- The time step to predict the future state. How far into the future to predict.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
66 {
67 // Initialize member variables.
68 m_dControlGain = dControlGain;
69 m_dSteeringAngleLimit = dSteeringAngleLimit;
70 m_dWheelbase = dWheelbase;
71 m_nPredictionHorizon = nPredictionHorizon;
72 m_dPredictionTimeStep = dPredictionTimeStep;
73 m_nCurrentReferencePathTargetIndex = 0;
74 m_BicycleModel = BicycleModel(m_dWheelbase, 0.0, 0.0, 0.0);
75 }

◆ ~PredictiveStanleyController()

controllers::PredictiveStanleyController::~PredictiveStanleyController ( )

Destroy the Predictive Stanley Controller:: Predictive Stanley Controller object.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
85 {
86 // Nothing to do yet.
87 }

Member Function Documentation

◆ Calculate()

PredictiveStanleyController::DriveVector controllers::PredictiveStanleyController::Calculate ( const geoops::RoverPose stCurrentPose,
const double  dMaxSpeed = constants::NAVIGATING_MOTOR_POWER 
)

Calculate an updated steering angle for the rover based on the current pose using the predictive stanley controller.

Parameters
stCurrentPose- The current pose of the rover.
dMaxSpeed- The maximum speed the rover can travel.
Returns
double - The new output steering angle for the rover.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
101 {
102 // Create instance variables.
103 double dSteeringAngle = 0.0;
104 std::vector<BicycleModel::Prediction> vPredictions;
105
106 // Check if the reference path is empty.
107 if (m_vReferencePath.empty())
108 {
109 // Submit logger message.
110 LOG_WARNING(logging::g_qSharedLogger, "PredictiveStanleyController::Calculate: Reference path is empty. Cannot calculate drive powers.");
111
112 return DriveVector{0.0, 0.0};
113 }
114
115 // Check if we are at the end of the path. Normally stanley would continue driving in the last direction of the calculated path
116 // headings, but we want to make sure we get to the end point, so we'll just drive straight to it once at the end of the path.
117 if (m_nCurrentReferencePathTargetIndex >= static_cast<int>(m_vReferencePath.size()) - 1)
118 {
119 // Get the last point in the path.
120 geoops::Waypoint stLastWaypoint = m_vReferencePath.back();
121 // Calculate the heading to the last point.
122 double dHeadingToLastWaypoint = geoops::CalculateGeoMeasurement(stCurrentPose.GetUTMCoordinate(), stLastWaypoint.GetUTMCoordinate()).dStartRelativeBearing;
123
124 return DriveVector{dHeadingToLastWaypoint, 1.0};
125 }
126
127 // Update the bicycle model with the current state.
128 m_BicycleModel.UpdateState(stCurrentPose.GetUTMCoordinate().dEasting, stCurrentPose.GetUTMCoordinate().dNorthing, stCurrentPose.GetCompassHeading());
129 // Predict the future state of the model.
130 m_BicycleModel.Predict(m_dPredictionTimeStep, m_nPredictionHorizon, vPredictions);
131
132 // Loop through all the predicted future states to compute the steering angle.
133 for (size_t nIter = 0.0; nIter < vPredictions.size(); ++nIter)
134 {
135 // Create instance variables.
136 double dPredictedXPosition = vPredictions[nIter].dXPosition;
137 double dPredictedYPosition = vPredictions[nIter].dYPosition;
138 double dPredictedTheta = vPredictions[nIter].dTheta;
139
140 // Create a UTM coordinate for the predicted position.
141 geoops::UTMCoordinate stPredictedPosition = stCurrentPose.GetUTMCoordinate();
142 stPredictedPosition.dEasting = dPredictedXPosition;
143 stPredictedPosition.dNorthing = dPredictedYPosition;
144 // Find the closest point to the reference path.
145 geoops::Waypoint stClosestWaypoint = FindClosestWaypointInPath(stPredictedPosition, dPredictedTheta);
146
147 // Compute the heading error. This is the difference between the heading of the rover and the heading or curvature of the path.
148 double dHeadingError = numops::AngularDifference(m_vReferencePathCurvature[m_nCurrentReferencePathTargetIndex], dPredictedTheta);
149
150 /*
151 Compute the cross track error. This is the distance between the predicted position and the closest point on the path. The sign of the cross track error
152 indicates which side of the path the rover is on. Left is positive, right is negative. The sign of the crosstrack error is determined by the sign of the
153 */
154
155 // Get the reference path vector: from the closest waypoint to the next waypoint.
156 double dForwardVectorX = m_vReferencePath[m_nCurrentReferencePathTargetIndex + 1].GetUTMCoordinate().dEasting - stClosestWaypoint.GetUTMCoordinate().dEasting;
157 double dForwardVectorY =
158 m_vReferencePath[m_nCurrentReferencePathTargetIndex + 1].GetUTMCoordinate().dNorthing - stClosestWaypoint.GetUTMCoordinate().dNorthing;
159 // Compute the norm and unit vector for the path segment.
160 double dForwardNorm = sqrt(dForwardVectorX * dForwardVectorX + dForwardVectorY * dForwardVectorY);
161 double dFwdUnitX = dForwardVectorX / dForwardNorm;
162 double dFwdUnitY = dForwardVectorY / dForwardNorm;
163 // Get the vehicle's position vector relative to the closest waypoint.
164 double dVehicleVectorX = dPredictedXPosition - stClosestWaypoint.GetUTMCoordinate().dEasting;
165 double dVehicleVectorY = dPredictedYPosition - stClosestWaypoint.GetUTMCoordinate().dNorthing;
166 // Project the vehicle vector onto the path unit vector to obtain the longitudinal component.
167 double dLongitudinal = dVehicleVectorX * dFwdUnitX + dVehicleVectorY * dFwdUnitY;
168 // Compute the lateral error vector by subtracting the longitudinal projection from the vehicle vector.
169 double dLateralX = dVehicleVectorX - dLongitudinal * dFwdUnitX;
170 double dLateralY = dVehicleVectorY - dLongitudinal * dFwdUnitY;
171 // The cross-track error is the magnitude of this lateral vector.
172 double dLateralDistance = sqrt(dLateralX * dLateralX + dLateralY * dLateralY);
173 // Determine the sign of the cross-track error using the cross product (left positive, right negative).
174 int nCrossTrackErrorSign = (dFwdUnitX * dVehicleVectorY - dFwdUnitY * dVehicleVectorX) > 0 ? 1 : -1;
175 // Final cross-track error.
176 double dCrossTrackError = nCrossTrackErrorSign * dLateralDistance;
177
178 // Apply an exponential weight factor that decreases as we predict further into the future.
179 double dTimeWeight = std::exp(-1.5 * static_cast<double>(nIter));
180 // Limit the cross track error steering angle.
181 dCrossTrackError = std::clamp(m_dControlGain * dCrossTrackError, -m_dSteeringAngleLimit, m_dSteeringAngleLimit);
182 // Calculate the steering angle using lateral and heading errors, weighted by the time step.
183 dSteeringAngle += dTimeWeight * (dCrossTrackError - dHeadingError);
184
185 // Limit the steering angle to the given limit.
186 dSteeringAngle = std::clamp(dSteeringAngle, -m_dSteeringAngleLimit, m_dSteeringAngleLimit);
187 }
188
189 // The new steering heading must be from 0-360 degrees.
190 double dAbsoluteHeadingGoal = numops::InputAngleModulus(stCurrentPose.GetCompassHeading() + dSteeringAngle, 0.0, 360.0);
191
192 return DriveVector{dAbsoluteHeadingGoal, dMaxSpeed};
193 }
void Predict(const double dTimeStep, const int nNumPredictions, std::vector< Prediction > &vPredictions)
Accessor for the State private member.
Definition BicycleModel.hpp:195
void UpdateState(const double dXPosition, const double dYPosition, const double dTheta)
Update the state of the model, given a new position and heading. This method will automatically calcu...
Definition BicycleModel.hpp:154
geoops::Waypoint FindClosestWaypointInPath(const geoops::UTMCoordinate &stCurrentPosition, const double dCurrentHeading)
Given the current position of the rover, find the point on the reference path that is closest to the ...
Definition PredictiveStanleyController.cpp:442
void sqrt(InputArray src, OutputArray dst)
GeoMeasurement CalculateGeoMeasurement(const GPSCoordinate &stCoord1, const GPSCoordinate &stCoord2)
The shortest path between two points on an ellipsoid at (lat1, lon1) and (lat2, lon2) is called the g...
Definition GeospatialOperations.hpp:522
constexpr T InputAngleModulus(T tValue, T tMinValue, T tMaxValue)
Calculates the modulus of an input angle.
Definition NumberOperations.hpp:165
constexpr T AngularDifference(T tFirstValue, T tSecondValue)
Calculates the distance in degrees between two angles. This function accounts for wrap around so that...
Definition NumberOperations.hpp:204
double GetCompassHeading() const
Accessor for the Compass Heading private member.
Definition GeospatialOperations.hpp:756
const geoops::UTMCoordinate & GetUTMCoordinate() const
Accessor for the geoops::UTMCoordinate member variable.
Definition GeospatialOperations.hpp:736
This struct stores/contains information about a UTM coordinate.
Definition GeospatialOperations.hpp:195
This struct is used by the WaypointHandler class to store location, size, and type information about ...
Definition GeospatialOperations.hpp:392
const geoops::UTMCoordinate & GetUTMCoordinate() const
Accessor for the geoops::UTMCoordinate member variable.
Definition GeospatialOperations.hpp:477
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetReferencePath() [1/3]

void controllers::PredictiveStanleyController::SetReferencePath ( const std::vector< geoops::Waypoint > &  vReferencePath)

Sets the path that the controller will follow.

Parameters
vReferencePath- A reference to a vector of waypoints that make up the path.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
204 {
205 // Create instance variables.
206 double dCurvature = 0.0;
207
208 // Apply path smoothing first.
209 std::vector<geoops::Waypoint> vSmoothedPath = pathplanners::postprocessing::FitPathWithBSpline(vReferencePath);
210
211 // Loop through the reference path and calculate the curvature at each point.
212 for (size_t nIter = 0; nIter < vSmoothedPath.size(); ++nIter)
213 {
214 // Calculate the curvature at this point.
215 if (nIter > 0 && nIter < vSmoothedPath.size() - 1)
216 {
217 // Calculate the curvature.
218 dCurvature = geoops::CalculateGeoMeasurement(vSmoothedPath[nIter - 1].GetUTMCoordinate(), vSmoothedPath[nIter].GetUTMCoordinate()).dStartRelativeBearing;
219
220 // If this is the second iteration, then also set the curvature of the previous point.
221 if (nIter == 1)
222 {
223 m_vReferencePathCurvature[0] = dCurvature;
224 }
225 }
226
227 // Store the waypoint and curvature.
228 m_vReferencePathCurvature.push_back(dCurvature);
229 }
230
231 // Reset the current target index.
232 m_nCurrentReferencePathTargetIndex = 0;
233 // Reset the bicycle model.
234 m_BicycleModel.ResetState();
235 // Set the reference path.
236 m_vReferencePath = vSmoothedPath;
237 }
void ResetState(const double dXPosition, const double dYPosition, const double dTheta)
Resets the state of the model to a new position and heading.
Definition BicycleModel.hpp:112
std::vector< geoops::Waypoint > FitPathWithBSpline(const std::vector< geoops::Waypoint > &vRawPath)
Fits a B-spline to the given path using cubic interpolation.
Definition PathPostProcessing.hpp:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetReferencePath() [2/3]

void controllers::PredictiveStanleyController::SetReferencePath ( const std::vector< geoops::UTMCoordinate > &  vReferencePath)

Sets the path that the controller will follow.

Parameters
vReferencePath- A reference to a vector of UTM coordinates that make up the path.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
248 {
249 // Create instance variables.
250 double dCurvature = 0.0;
251
252 // Apply path smoothing first.
253 std::vector<geoops::Waypoint> vSmoothedPath = pathplanners::postprocessing::FitPathWithBSpline(vReferencePath);
254
255 // Loop through the reference path and calculate the curvature at each point.
256 for (size_t nIter = 0; nIter < vSmoothedPath.size(); ++nIter)
257 {
258 // Calculate the curvature at this point.
259 if (nIter > 0 && nIter < vSmoothedPath.size() - 1)
260 {
261 // Calculate the curvature.
262 dCurvature = geoops::CalculateGeoMeasurement(vSmoothedPath[nIter - 1].GetUTMCoordinate(), vSmoothedPath[nIter].GetUTMCoordinate()).dStartRelativeBearing;
263
264 // If this is the second iteration, then also set the curvature of the previous point.
265 if (nIter == 1)
266 {
267 m_vReferencePathCurvature[0] = dCurvature;
268 }
269 }
270
271 // Store the waypoint and curvature.
272 m_vReferencePathCurvature.push_back(dCurvature);
273 }
274
275 // Reset the current target index.
276 m_nCurrentReferencePathTargetIndex = 0;
277 // Reset the bicycle model.
278 m_BicycleModel.ResetState();
279 // Set the reference path.
280 m_vReferencePath = vSmoothedPath;
281 }
Here is the call graph for this function:

◆ SetReferencePath() [3/3]

void controllers::PredictiveStanleyController::SetReferencePath ( const std::vector< geoops::GPSCoordinate > &  vReferencePath)

Sets the path that the controller will follow.

Parameters
vReferencePath- A reference to a vector of GPS coordinates that make up the path.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
292 {
293 // Create instance variables.
294 double dCurvature = 0.0;
295
296 // Apply path smoothing first.
297 std::vector<geoops::Waypoint> vSmoothedPath = pathplanners::postprocessing::FitPathWithBSpline(vReferencePath);
298
299 // Loop through the reference path and calculate the curvature at each point.
300 for (size_t nIter = 0; nIter < vSmoothedPath.size(); ++nIter)
301 {
302 // Calculate the curvature at this point.
303 if (nIter > 0 && nIter < vSmoothedPath.size() - 1)
304 {
305 // Calculate the curvature.
306 dCurvature = geoops::CalculateGeoMeasurement(vSmoothedPath[nIter - 1].GetUTMCoordinate(), vSmoothedPath[nIter].GetUTMCoordinate()).dStartRelativeBearing;
307
308 // If this is the second iteration, then also set the curvature of the previous point.
309 if (nIter == 1)
310 {
311 m_vReferencePathCurvature[0] = dCurvature;
312 }
313 }
314
315 // Store the waypoint and curvature.
316 m_vReferencePathCurvature.push_back(dCurvature);
317 }
318
319 // Reset the current target index.
320 m_nCurrentReferencePathTargetIndex = 0;
321 // Reset the bicycle model.
322 m_BicycleModel.ResetState();
323 // Set the reference path.
324 m_vReferencePath = vSmoothedPath;
325 }
Here is the call graph for this function:

◆ SetControlGain()

void controllers::PredictiveStanleyController::SetControlGain ( const double  dControlGain)

Setter for the control gain of the stanley controller.

Parameters
dControlGain- The control gain for the controller.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
336 {
337 m_dControlGain = dControlGain;
338 }
Here is the caller graph for this function:

◆ SetSteeringAngleLimit()

void controllers::PredictiveStanleyController::SetSteeringAngleLimit ( const double  dSteeringAngleLimit)

Setter for the steering angle limit of the stanley controller.

Parameters
dSteeringAngleLimit- The steering angle limit for the controller.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-11
349 {
350 m_dSteeringAngleLimit = dSteeringAngleLimit;
351 }
Here is the caller graph for this function:

◆ SetWheelbase()

void controllers::PredictiveStanleyController::SetWheelbase ( const double  dWheelbase)

Setter for the wheelbase of the stanley controller.

Parameters
dWheelbase- The distance between the front and rear axles of the rover.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-11
362 {
363 m_dWheelbase = dWheelbase;
364 }
Here is the caller graph for this function:

◆ GetReferencePath()

std::vector< geoops::Waypoint > controllers::PredictiveStanleyController::GetReferencePath ( ) const

Accessor for the reference path that the controller is following.

Returns
std::vector<geoops::Waypoint> - A copy of the reference path.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
414 {
415 return m_vReferencePath;
416 }
Here is the caller graph for this function:

◆ GetControlGain()

double controllers::PredictiveStanleyController::GetControlGain ( ) const

Accessor for the control gain of the stanley controller.

Returns
double - The control gain for the controller.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
375 {
376 return m_dControlGain;
377 }
Here is the caller graph for this function:

◆ GetSteeringAngleLimit()

double controllers::PredictiveStanleyController::GetSteeringAngleLimit ( ) const

Accessor for the steering angle limit of the stanley controller.

Returns
double - The steering angle limit for the controller.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-11
388 {
389 return m_dSteeringAngleLimit;
390 }
Here is the caller graph for this function:

◆ GetWheelbase()

double controllers::PredictiveStanleyController::GetWheelbase ( ) const

Accessor for the wheelbase of the stanley controller.

Returns
double - The wheelbase of the controller.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-11
401 {
402 return m_dWheelbase;
403 }
Here is the caller graph for this function:

◆ GetReferencePathTargetIndex()

double controllers::PredictiveStanleyController::GetReferencePathTargetIndex ( ) const

Accessor for the current target index in the reference path.

Returns
double - The current target index in the reference path.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
427 {
428 return m_nCurrentReferencePathTargetIndex;
429 }
Here is the caller graph for this function:

◆ FindClosestWaypointInPath()

geoops::Waypoint controllers::PredictiveStanleyController::FindClosestWaypointInPath ( const geoops::UTMCoordinate stCurrentPosition,
const double  dCurrentHeading 
)
private

Given the current position of the rover, find the point on the reference path that is closest to the rover's front axle position (based on the wheelbase). This is what makes sure the rover progresses forward in indexes along the path.

Parameters
stCurrentPosition- The current position of the rover.
dCurrentHeading- The current heading of the rover in degrees from 0-360.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
443 {
444 // Initialize variables.
445 geoops::Waypoint stClosestWaypoint;
446 geoops::UTMCoordinate stFrontAxlePosition = stCurrentPosition;
447 double dClosestDistance = std::numeric_limits<double>::max();
448
449 // Convert the heading to radians.
450 double dCurrentHeadingRad = dCurrentHeading * M_PI / 180.0;
451
452 // Calculate the current position of the front axle based on the wheelbase, heading, and current position.
453 stFrontAxlePosition.dEasting = stCurrentPosition.dEasting + m_dWheelbase * std::sin(dCurrentHeadingRad);
454 stFrontAxlePosition.dNorthing = stCurrentPosition.dNorthing + m_dWheelbase * std::cos(dCurrentHeadingRad);
455
456 // Loop through the reference path.
457 for (size_t nIter = 0; nIter < m_vReferencePath.size(); ++nIter)
458 {
459 // Calculate the distance to the current waypoint.
460 double dDistance = geoops::CalculateGeoMeasurement(stFrontAxlePosition, m_vReferencePath[nIter].GetUTMCoordinate()).dDistanceMeters;
461
462 // Check if this waypoint is closer.
463 if (dDistance < dClosestDistance)
464 {
465 // Update the closest waypoint.
466 stClosestWaypoint = m_vReferencePath[nIter];
467 dClosestDistance = dDistance;
468
469 // Update the current target index based on the location of the closest waypoint in the vector path.
470 m_nCurrentReferencePathTargetIndex = nIter;
471 }
472 }
473
474 // Return the closest waypoint.
475 return stClosestWaypoint;
476 }
Here is the call graph for this function:
Here is the caller graph for this function:

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