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
statemachine::VerifyingPositionState Class Reference

The VerifyingPositionState class implements the Verifying Position state for the Autonomy State Machine. More...

#include <VerifyingPositionState.h>

Inheritance diagram for statemachine::VerifyingPositionState:
Collaboration diagram for statemachine::VerifyingPositionState:

Public Member Functions

 VerifyingPositionState ()
 Construct a new State object.
 
void Run () override
 Run the state machine. Returns the next state.
 
States TriggerEvent (Event eEvent) override
 Trigger an event in the state machine. Returns the next state.
 
- Public Member Functions inherited from statemachine::State
 State (States eState)
 Construct a new State object.
 
virtual ~State ()=default
 Destroy the State object.
 
States GetState () const
 Accessor for the State private member.
 
virtual std::string ToString () const
 Accessor for the State private member. Returns the state as a string.
 
virtual bool operator== (const State &other) const
 Checks to see if the current state is equal to the passed state.
 
virtual bool operator!= (const State &other) const
 Checks to see if the current state is not equal to the passed state.
 

Protected Member Functions

void Start () override
 This method is called when the state is first started. It is used to initialize the state.
 
void Exit () override
 This method is called when the state is exited. It is used to clean up the state.
 

Private Attributes

std::vector< geoops::GPSCoordinatem_vCheckPoints
 
int m_nMaxDataPoints
 
bool m_bInitialized
 
std::chrono::system_clock::time_point m_tmVerifyStartTime
 

Detailed Description

The VerifyingPositionState class implements the Verifying Position state for the Autonomy State Machine.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-05-24

Constructor & Destructor Documentation

◆ VerifyingPositionState()

statemachine::VerifyingPositionState::VerifyingPositionState ( )

Construct a new State object.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-05-24
64 : State(States::eVerifyingPosition)
65 {
66 LOG_INFO(logging::g_qConsoleLogger, "Entering State: {}", ToString());
67
68 m_nMaxDataPoints = 100;
69
70 m_bInitialized = false;
71
72 if (!m_bInitialized)
73 {
74 Start();
75 m_bInitialized = true;
76 }
77 }
virtual std::string ToString() const
Accessor for the State private member. Returns the state as a string.
Definition State.hpp:207
State(States eState)
Construct a new State object.
Definition State.hpp:150
void Start() override
This method is called when the state is first started. It is used to initialize the state.
Definition VerifyingPositionState.cpp:31
Here is the call graph for this function:

Member Function Documentation

◆ Start()

void statemachine::VerifyingPositionState::Start ( )
overrideprotectedvirtual

This method is called when the state is first started. It is used to initialize the state.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-05-24

Reimplemented from statemachine::State.

32 {
33 // Schedule the next run of the state's logic
34 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Scheduling next run of state logic.");
35
36 m_vCheckPoints.reserve(m_nMaxDataPoints);
37
38 m_tmVerifyStartTime = std::chrono::system_clock::now();
39 }
Here is the caller graph for this function:

◆ Exit()

void statemachine::VerifyingPositionState::Exit ( )
overrideprotectedvirtual

This method is called when the state is exited. It is used to clean up the state.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-05-24

Reimplemented from statemachine::State.

50 {
51 // Clean up the state before exiting
52 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Exiting state.");
53
54 m_vCheckPoints.clear();
55 }
Here is the caller graph for this function:

◆ Run()

void statemachine::VerifyingPositionState::Run ( )
overridevirtual

Run the state machine. Returns the next state.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-05-24

Implements statemachine::State.

86 {
87 LOG_DEBUG(logging::g_qSharedLogger, "VerifyingPositionState: Running state-specific behavior.");
88
89 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
90 double dTimeElapsed = std::chrono::duration_cast<std::chrono::seconds>(tmCurrentTime - m_tmVerifyStartTime).count();
91
92 if (dTimeElapsed >= 30.0)
93 {
94 if (int(m_vCheckPoints.size()) < m_nMaxDataPoints)
95 {
96 if (!globals::g_pNavigationBoard->IsOutOfDate())
97 {
98 m_vCheckPoints.push_back(globals::g_pNavigationBoard->GetGPSData());
99 }
100 }
101 else
102 {
103 // Realign the ZED
104 globals::g_pStateMachineHandler->RealignZEDPosition(CameraHandler::ZEDCamName::eHeadMainCam,
105 geoops::ConvertGPSToUTM(globals::g_pNavigationBoard->GetGPSData()),
106 globals::g_pNavigationBoard->GetHeading());
107
108 // Create Average GPS Coordinate
110
111 // Calculate Sum of GPS Coordinates
112 for (geoops::GPSCoordinate& stPoint : m_vCheckPoints)
113 {
114 stAverage.dLatitude += stPoint.dLatitude;
115 stAverage.dLongitude += stPoint.dLongitude;
116 }
117
118 // Calculate Average GPS Coordinate
119 stAverage.dLatitude /= m_vCheckPoints.size();
120 stAverage.dLongitude /= m_vCheckPoints.size();
121
122 // Calculate distance and bearing from goal waypoint.
123 geoops::GeoMeasurement stGoalWaypointMeasurement =
124 geoops::CalculateGeoMeasurement(stAverage, globals::g_pWaypointHandler->PeekNextWaypoint().GetGPSCoordinate());
125
126 // Check if the rover is within the goal waypoint's tolerance.
127 if (stGoalWaypointMeasurement.dDistanceMeters > constants::NAVIGATING_REACHED_GOAL_RADIUS)
128 {
129 // Trigger event to transition to next state.
130 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingFailed, false);
131 }
132 else
133 {
134 // Trigger event to transition to next state.
135 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingComplete, false);
136 }
137 }
138 }
139 }
void RealignZEDPosition(CameraHandler::ZEDCamName eCameraName, const geoops::UTMCoordinate &stNewCameraPosition, const double dNewCameraHeading)
This is used to realign the ZEDs forward direction with the rover's current compass heading....
Definition StateMachineHandler.cpp:427
void HandleEvent(statemachine::Event eEvent, const bool bSaveCurrentState=false)
This method Handles Events that are passed to the State Machine Handler. It will check the current st...
Definition StateMachineHandler.cpp:337
UTMCoordinate ConvertGPSToUTM(const GPSCoordinate &stGPSCoord)
Given a GPS coordinate, convert to UTM and create a new UTMCoordinate object.
Definition GeospatialOperations.hpp:351
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:445
This struct stores/contains information about a GPS data.
Definition GeospatialOperations.hpp:148
This struct is used to store the distance, arc length, and relative bearing for a calculated geodesic...
Definition GeospatialOperations.hpp:82
Here is the call graph for this function:

◆ TriggerEvent()

States statemachine::VerifyingPositionState::TriggerEvent ( Event  eEvent)
overridevirtual

Trigger an event in the state machine. Returns the next state.

Parameters
eEvent- The event to trigger.
Returns
std::shared_ptr<State> - The next state.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-05-24

Implements statemachine::State.

151 {
152 // Create instance variables.
153 States eNextState = States::eVerifyingPosition;
154 bool bCompleteStateExit = true;
155
156 switch (eEvent)
157 {
158 case Event::eStart:
159 {
160 // Submit logger message.
161 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Handling Start event.");
162 // Send multimedia command to update state display.
163 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
164 break;
165 }
166 case Event::eVerifyingComplete:
167 {
168 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Handling Verifying Complete event.");
169 // Send multimedia command to update state display.
170 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eReachedGoal);
171 // Pop the next waypoint.
172 globals::g_pWaypointHandler->PopNextWaypoint();
173 // Change state.
174 eNextState = States::eIdle;
175 break;
176 }
177 case Event::eVerifyingFailed:
178 {
179 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Handling Verifying Failed event.");
180 // Send multimedia command to update state display.
181 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
182 // Change state.
183 eNextState = States::eNavigating;
184 break;
185 }
186 case Event::eAbort:
187 {
188 // Submit logger message.
189 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Handling Abort event.");
190 // Send multimedia command to update state display.
191 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
192 // Change state.
193 eNextState = States::eIdle;
194 break;
195 }
196 default:
197 {
198 LOG_WARNING(logging::g_qSharedLogger, "VerifyingPositionState: Handling unknown event.");
199 eNextState = States::eIdle;
200 break;
201 }
202 }
203
204 if (eNextState != States::eVerifyingPosition)
205 {
206 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Transitioning to {} State.", StateToString(eNextState));
207
208 // Exit the current state
209 if (bCompleteStateExit)
210 {
211 Exit();
212 }
213 }
214
215 return eNextState;
216 }
void SendLightingState(MultimediaBoardLightingState eState)
Sends a predetermined color pattern to board.
Definition MultimediaBoard.cpp:55
geoops::Waypoint PopNextWaypoint()
Removes and returns the next waypoint at the front of the list.
Definition WaypointHandler.cpp:499
void Exit() override
This method is called when the state is exited. It is used to clean up the state.
Definition VerifyingPositionState.cpp:49
std::string StateToString(States eState)
Converts a state object to a string.
Definition State.hpp:89
States
The states that the state machine can be in.
Definition State.hpp:31
Here is the call graph for this function:

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