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

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

#include <UnicycleModel.hpp>

Classes

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

Public Member Functions

 UnicycleModel ()
 Construct a new Unicycle Model object.
 
 UnicycleModel (const double dXPosition, const double dYPosition, const double dTheta)
 Construct a new Unicycle 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 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 SetAngularVelocity (const double dAngularVelocity)
 Mutator for the Angular Velocity 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 GetAngularVelocity () const
 Accessor for the Angular Velocity private member.
 

Private Attributes

double m_dXPosition
 
double m_dYPosition
 
double m_dTheta
 
double m_dVelocity
 
double m_dAngularVelocity
 
std::chrono::system_clock::time_point m_tmLastUpdateTime
 

Detailed Description

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

Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-4

Constructor & Destructor Documentation

◆ UnicycleModel() [1/2]

UnicycleModel::UnicycleModel ( )
inline

Construct a new Unicycle Model object.

Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-4
68 {
69 // Initialize member variables.
70 m_dXPosition = 0.0;
71 m_dYPosition = 0.0;
72 m_dTheta = 0.0;
73 m_dVelocity = -1.0;
74 m_dAngularVelocity = 0.0;
75 m_tmLastUpdateTime = std::chrono::system_clock::now();
76 }

◆ UnicycleModel() [2/2]

UnicycleModel::UnicycleModel ( const double  dXPosition,
const double  dYPosition,
const double  dTheta 
)
inline

Construct a new Unicycle Model object.

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
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-4
89 {
90 // Initialize member variables.
91 m_dXPosition = dXPosition;
92 m_dYPosition = dYPosition;
93 m_dTheta = dTheta;
94 m_dVelocity = -1.0;
95 m_dAngularVelocity = 0.0;
96 m_tmLastUpdateTime = std::chrono::system_clock::now();
97 }

Member Function Documentation

◆ ResetState() [1/2]

void UnicycleModel::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
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-4
110 {
111 // Update member variables.
112 m_dXPosition = dXPosition;
113 m_dYPosition = dYPosition;
114 m_dTheta = dTheta;
115 m_dAngularVelocity = 0.0;
116 m_dVelocity = -1.0;
117 m_tmLastUpdateTime = std::chrono::system_clock::now();
118 }
Here is the caller graph for this function:

◆ ResetState() [2/2]

void UnicycleModel::ResetState ( )
inline

Resets the state of the model to a default state.

Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-04
128 {
129 // Update member variables.
130 m_dXPosition = 0.0;
131 m_dYPosition = 0.0;
132 m_dTheta = 0.0;
133 m_dAngularVelocity = 0.0;
134 m_dVelocity = -1.0;
135 m_tmLastUpdateTime = std::chrono::system_clock::now();
136 }

◆ UpdateState()

void UnicycleModel::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
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-04
152 {
153 // Check if this is our first update.
154 if (m_dVelocity == -1.0)
155 {
156 // Set the velocity to zero.
157 m_dVelocity = 0.0;
158 }
159 // Calculate the velocity of the rover as long as the new position is different from the current position.
160 else if (dXPosition != m_dXPosition || dYPosition != m_dYPosition)
161 {
162 // Calculate the velocity of the rover.
163 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
164 double dTimeElapsed = std::chrono::duration_cast<std::chrono::milliseconds>(tmCurrentTime - m_tmLastUpdateTime).count() / 1000.0;
165 m_dVelocity = std::sqrt(std::pow(dXPosition - m_dXPosition, 2) + std::pow(dYPosition - m_dYPosition, 2)) / dTimeElapsed;
166
167 // Update the last update time.
168 m_tmLastUpdateTime = tmCurrentTime;
169 }
170
171 // Update member variables.
172 m_dXPosition = dXPosition;
173 m_dYPosition = dYPosition;
174 m_dTheta = dTheta;
175 }
Here is the caller graph for this function:

◆ Predict()

void UnicycleModel::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
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-04
188 {
189 // Start from the current state.
190 double dXPredicted = m_dXPosition;
191 double dYPredicted = m_dYPosition;
192 double dThetaPredicted = m_dTheta;
193
194 // Perform prediction for a specified number of time steps.
195 for (int nIter = 0; nIter < nNumPredictions; ++nIter)
196 {
197 // Convert theta from degrees to radians for calculation.
198 double dThetaRad = dThetaPredicted * M_PI / 180.0;
199
200 // Calculate the new state.
201 dXPredicted += m_dVelocity * std::sin(dThetaRad) * dTimeStep;
202 dYPredicted += m_dVelocity * std::cos(dThetaRad) * dTimeStep;
203 dThetaPredicted += (m_dAngularVelocity) *dTimeStep;
204
205 // Ensure theta stays within 0-360 degrees.
206 dThetaPredicted = numops::InputAngleModulus(dThetaPredicted, 0.0, 360.0);
207
208 // Store the new state.
209 Prediction stPrediction{dXPredicted, dYPredicted, dThetaPredicted};
210 vPredictions.push_back(stPrediction);
211 }
212 }
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:

◆ SetXPosition()

void UnicycleModel::SetXPosition ( const double  dXPosition)
inline

Mutator for the XPosition private member.

Parameters
dXPosition- The x position of the rover.
Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-04
226{ m_dXPosition = dXPosition; }

◆ SetYPosition()

void UnicycleModel::SetYPosition ( const double  dYPosition)
inline

Mutator for the YPosition private member.

Parameters
dYPosition- The y position of the rover.
Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-01-10
236{ m_dYPosition = dYPosition; }

◆ SetTheta()

void UnicycleModel::SetTheta ( const double  dTheta)
inline

Mutator for the Theta private member.

Parameters
dTheta- The heading angle of the rover in degrees.
Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-04
246{ m_dTheta = dTheta; }

◆ SetAngularVelocity()

void UnicycleModel::SetAngularVelocity ( const double  dAngularVelocity)
inline

Mutator for the Angular Velocity private member.

Parameters
dAngularVelocity- The angular velocity of the rover in degrees per second.
Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-4
256{ m_dAngularVelocity = dAngularVelocity; }

◆ GetXPosition()

double UnicycleModel::GetXPosition ( ) const
inline

Accessor for the XPosition private member.

Returns
double - The x position of the rover.
Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-04
270{ return m_dXPosition; }

◆ GetYPosition()

double UnicycleModel::GetYPosition ( ) const
inline

Accessor for the YPosition private member.

Returns
double - The y position of the rover.
Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-04
280{ return m_dYPosition; }

◆ GetTheta()

double UnicycleModel::GetTheta ( ) const
inline

Accessor for the Theta private member.

Returns
double - The heading angle of the rover in degrees.
Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-04
290{ return m_dTheta; }

◆ GetVelocity()

double UnicycleModel::GetVelocity ( ) const
inline

Accessor for the Velocity private member.

Returns
double - The velocity of the rover.
Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-04
300{ return m_dVelocity; }
Here is the caller graph for this function:

◆ GetAngularVelocity()

double UnicycleModel::GetAngularVelocity ( ) const
inline

Accessor for the Angular Velocity private member.

Returns
double - The angular velocity of the rover in degrees per second.
Author
Bailey Schoenike (baile.nosp@m.yps0.nosp@m.3@gma.nosp@m.il.c.nosp@m.om)
Date
2025-10-4
310{ return m_dAngularVelocity; }

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