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
BicycleModel Class Reference

This class implements the Bicycle Model. This model is used to predict the future state of the rover given a current state and control input. More...

#include <BicycleModel.hpp>

Classes

struct  Prediction
 This struct is used to store the predicted state of the bicycle. More...
 

Public Member Functions

 BicycleModel ()
 Construct a new Bicycle Model object.
 
 BicycleModel (const double dWheelbase, const double dXPosition, const double dYPosition, const double dTheta)
 Construct a new Bicycle Model object.
 
void ResetState (const double dXPosition, const double dYPosition, const double dTheta)
 Resets the state of the model to a new position and heading.
 
void ResetState ()
 Resets the state of the model to a default state.
 
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 calculate the velocity of the rover base on the new and current position. The steering angle is also updated automatically based on the new and current heading.
 
void Predict (const double dTimeStep, const int nNumPredictions, std::vector< Prediction > &vPredictions)
 Accessor for the State private member.
 
void SetWheelbase (const double dWheelbase)
 Mutator for the Wheelbase private member.
 
void SetXPosition (const double dXPosition)
 Mutator for the XPosition private member.
 
void SetYPosition (const double dYPosition)
 Mutator for the YPosition private member.
 
void SetTheta (const double dTheta)
 Mutator for the Theta private member.
 
void SetSteeringAngle (const double dSteeringAngle)
 Mutator for the Steering Angle private member.
 
double GetWheelbase () const
 Accessor for the Wheelbase private member.
 
double GetXPosition () const
 Accessor for the XPosition private member.
 
double GetYPosition () const
 Accessor for the YPosition private member.
 
double GetTheta () const
 Accessor for the Theta private member.
 
double GetVelocity () const
 Accessor for the Velocity private member.
 
double GetSteeringAngle () const
 Accessor for the Steering Angle private member.
 

Private Attributes

double m_dWheelbase
 
double m_dXPosition
 
double m_dYPosition
 
double m_dTheta
 
double m_dVelocity
 
double m_dSteeringAngle
 
std::chrono::system_clock::time_point m_tmLastUpdateTime
 

Detailed Description

This class implements the Bicycle Model. This model is used to predict the future state of the rover given a current state and control input.

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

◆ BicycleModel() [1/2]

BicycleModel::BicycleModel ( )
inline

Construct a new Bicycle Model 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
68 {
69 // Initialize member variables.
70 m_dWheelbase = 0.0;
71 m_dXPosition = 0.0;
72 m_dYPosition = 0.0;
73 m_dTheta = 0.0;
74 m_dVelocity = -1.0;
75 m_dSteeringAngle = 0.0;
76 m_tmLastUpdateTime = std::chrono::system_clock::now();
77 }

◆ BicycleModel() [2/2]

BicycleModel::BicycleModel ( const double  dWheelbase,
const double  dXPosition,
const double  dYPosition,
const double  dTheta 
)
inline

Construct a new Bicycle Model object.

Parameters
dWheelbase- The distance between the front and rear axles of the rover.
dXPosition- The x position of the rover.
dYPosition- The y position of the rover.
dTheta- The heading angle of the rover in degrees.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
91 {
92 // Initialize member variables.
93 m_dWheelbase = dWheelbase;
94 m_dXPosition = dXPosition;
95 m_dYPosition = dYPosition;
96 m_dTheta = dTheta;
97 m_dVelocity = -1.0;
98 m_dSteeringAngle = 0.0;
99 m_tmLastUpdateTime = std::chrono::system_clock::now();
100 }

Member Function Documentation

◆ ResetState() [1/2]

void BicycleModel::ResetState ( const double  dXPosition,
const double  dYPosition,
const double  dTheta 
)
inline

Resets the state of the model to a new position and heading.

Parameters
dXPosition- The x position of the rover.
dYPosition- The y position of the rover.
dTheta- The heading angle of the rover in degrees.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
113 {
114 // Update member variables.
115 m_dXPosition = dXPosition;
116 m_dYPosition = dYPosition;
117 m_dTheta = dTheta;
118 m_dSteeringAngle = 0.0;
119 m_dVelocity = -1.0;
120 m_tmLastUpdateTime = std::chrono::system_clock::now();
121 }
Here is the caller graph for this function:

◆ ResetState() [2/2]

void BicycleModel::ResetState ( )
inline

Resets the state of the model to a default state.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
131 {
132 // Update member variables.
133 m_dXPosition = 0.0;
134 m_dYPosition = 0.0;
135 m_dTheta = 0.0;
136 m_dSteeringAngle = 0.0;
137 m_dVelocity = -1.0;
138 m_tmLastUpdateTime = std::chrono::system_clock::now();
139 }

◆ UpdateState()

void BicycleModel::UpdateState ( const double  dXPosition,
const double  dYPosition,
const double  dTheta 
)
inline

Update the state of the model, given a new position and heading. This method will automatically calculate the velocity of the rover base on the new and current position. The steering angle is also updated automatically based on the new and current heading.

Parameters
dXPosition- The x position of the rover.
dYPosition- The y position of the rover.
dTheta- The heading angle of the rover in degrees.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
155 {
156 // Check if this is our first update.
157 if (m_dVelocity == -1.0)
158 {
159 // Set the velocity to zero.
160 m_dVelocity = 0.0;
161 }
162 // Calculate the velocity of the rover as long as the new position is different from the current position.
163 else if (dXPosition != m_dXPosition || dYPosition != m_dYPosition)
164 {
165 // Calculate the velocity of the rover.
166 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
167 double dTimeElapsed = std::chrono::duration_cast<std::chrono::milliseconds>(tmCurrentTime - m_tmLastUpdateTime).count() / 1000.0;
168 m_dVelocity = std::sqrt(std::pow(dXPosition - m_dXPosition, 2) + std::pow(dYPosition - m_dYPosition, 2)) / dTimeElapsed;
169
170 // Update the last update time.
171 m_tmLastUpdateTime = tmCurrentTime;
172 }
173
174 // Calculate the steering angle of the rover.
175 m_dSteeringAngle = (std::atan2(dYPosition - m_dYPosition, dXPosition - m_dXPosition) * 180.0 / M_PI) - m_dTheta;
176 // Ensure the steering angle stays within 0-360 degrees.
177 m_dSteeringAngle = numops::InputAngleModulus(m_dSteeringAngle, 0.0, 360.0);
178
179 // Update member variables.
180 m_dXPosition = dXPosition;
181 m_dYPosition = dYPosition;
182 m_dTheta = dTheta;
183 }
constexpr T InputAngleModulus(T tValue, T tMinValue, T tMaxValue)
Calculates the modulus of an input angle.
Definition NumberOperations.hpp:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Predict()

void BicycleModel::Predict ( const double  dTimeStep,
const int  nNumPredictions,
std::vector< Prediction > &  vPredictions 
)
inline

Accessor for the State private member.

Parameters
dTimeStep- The time step to predict the future state. How far into the future to predict.
nNumPredictions- The number of predictions to make.
vPredictions- The vector of predictions to store the predicted states.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
196 {
197 // Start from the current state.
198 double dXPredicted = m_dXPosition;
199 double dYPredicted = m_dYPosition;
200 double dThetaPredicted = m_dTheta;
201
202 // Perform prediction for a specified number of time steps.
203 for (int nIter = 0; nIter < nNumPredictions; ++nIter)
204 {
205 // Convert theta from degrees to radians for calculation.
206 double dThetaRad = dThetaPredicted * M_PI / 180.0;
207 double dSteeringAngleRad = m_dSteeringAngle * M_PI / 180.0;
208
209 // Calculate the new state.
210 dXPredicted += m_dVelocity * std::sin(dThetaRad) * dTimeStep;
211 dYPredicted += m_dVelocity * std::cos(dThetaRad) * dTimeStep;
212 dThetaPredicted += (m_dVelocity / m_dWheelbase) * std::tan(dSteeringAngleRad - M_PI_2) * dTimeStep;
213
214 // Ensure theta stays within 0-360 degrees.
215 dThetaPredicted = numops::InputAngleModulus(dThetaPredicted, 0.0, 360.0);
216
217 // Store the new state.
218 Prediction stPrediction{dXPredicted, dYPredicted, dThetaPredicted};
219 vPredictions.push_back(stPrediction);
220 }
221 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetWheelbase()

void BicycleModel::SetWheelbase ( const double  dWheelbase)
inline

Mutator for the Wheelbase private member.

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-10
235{ m_dWheelbase = dWheelbase; }

◆ SetXPosition()

void BicycleModel::SetXPosition ( const double  dXPosition)
inline

Mutator for the XPosition private member.

Parameters
dXPosition- The x position 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-10
245{ m_dXPosition = dXPosition; }

◆ SetYPosition()

void BicycleModel::SetYPosition ( const double  dYPosition)
inline

Mutator for the YPosition private member.

Parameters
dYPosition- The y position 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-10
255{ m_dYPosition = dYPosition; }

◆ SetTheta()

void BicycleModel::SetTheta ( const double  dTheta)
inline

Mutator for the Theta private member.

Parameters
dTheta- The heading angle of the rover in degrees.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
265{ m_dTheta = dTheta; }

◆ SetSteeringAngle()

void BicycleModel::SetSteeringAngle ( const double  dSteeringAngle)
inline

Mutator for the Steering Angle private member.

Parameters
dSteeringAngle- The steering angle of the rover in degrees.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
275{ m_dSteeringAngle = dSteeringAngle; }

◆ GetWheelbase()

double BicycleModel::GetWheelbase ( ) const
inline

Accessor for the Wheelbase private member.

Returns
double - 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-10
289{ return m_dWheelbase; }

◆ GetXPosition()

double BicycleModel::GetXPosition ( ) const
inline

Accessor for the XPosition private member.

Returns
double - The x position 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-10
299{ return m_dXPosition; }

◆ GetYPosition()

double BicycleModel::GetYPosition ( ) const
inline

Accessor for the YPosition private member.

Returns
double - The y position 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-10
309{ return m_dYPosition; }

◆ GetTheta()

double BicycleModel::GetTheta ( ) const
inline

Accessor for the Theta private member.

Returns
double - The heading angle of the rover in degrees.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
319{ return m_dTheta; }

◆ GetVelocity()

double BicycleModel::GetVelocity ( ) const
inline

Accessor for the Velocity private member.

Returns
double - The velocity 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-10
329{ return m_dVelocity; }

◆ GetSteeringAngle()

double BicycleModel::GetSteeringAngle ( ) const
inline

Accessor for the Steering Angle private member.

Returns
double - The steering angle of the rover in degrees.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-01-10
339{ return m_dSteeringAngle; }

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