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
62 : State(States::eVerifyingPosition)
63 {
64 LOG_INFO(logging::g_qConsoleLogger, "Entering State: {}", ToString());
65 // Initialize member variables.
66 m_bInitialized = false;
67
68 if (!m_bInitialized)
69 {
70 Start();
71 m_bInitialized = true;
72 }
73 }
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_tmVerifyStartTime = std::chrono::system_clock::now();
37 }
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.

48 {
49 // Clean up the state before exiting
50 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Exiting state.");
51
52 m_vCheckPoints.clear();
53 }
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.

82 {
83 LOG_DEBUG(logging::g_qSharedLogger, "VerifyingPositionState: Running state-specific behavior.");
84
85 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
86 double dTimeElapsed = std::chrono::duration_cast<std::chrono::milliseconds>(tmCurrentTime - m_tmVerifyStartTime).count() / 1000.0;
87
88 if (dTimeElapsed <= constants::NAVIGATING_VERIFY_SAMPLE_TIME)
89 {
90 if (!globals::g_pNavigationBoard->IsOutOfDate())
91 {
92 m_vCheckPoints.emplace_back(globals::g_pNavigationBoard->GetGPSData());
93 }
94 }
95 else
96 {
97 // Realign the ZED
98 globals::g_pStateMachineHandler->RealignZEDPosition(CameraHandler::ZEDCamName::eHeadMainCam,
99 geoops::ConvertGPSToUTM(globals::g_pNavigationBoard->GetGPSData()),
100 globals::g_pNavigationBoard->GetHeading());
101
102 // Create Average GPS Coordinate
104
105 // Calculate Sum of GPS Coordinates
106 for (geoops::GPSCoordinate& stPoint : m_vCheckPoints)
107 {
108 stAverage.dLatitude += stPoint.dLatitude;
109 stAverage.dLongitude += stPoint.dLongitude;
110 }
111
112 // Calculate Average GPS Coordinate
113 stAverage.dLatitude /= m_vCheckPoints.size();
114 stAverage.dLongitude /= m_vCheckPoints.size();
115
116 // Calculate distance and bearing from goal waypoint.
117 geoops::GeoMeasurement stGoalWaypointMeasurement =
118 geoops::CalculateGeoMeasurement(stAverage, globals::g_pWaypointHandler->PeekNextWaypoint().GetGPSCoordinate());
119
120 // Check if the rover is within the goal waypoint's tolerance.
121 if (stGoalWaypointMeasurement.dDistanceMeters > constants::NAVIGATING_REACHED_GOAL_RADIUS)
122 {
123 // Trigger event to transition to next state.
124 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingFailed, false);
125 }
126 else
127 {
128 // Trigger event to transition to next state.
129 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingComplete, false);
130 }
131 }
132 }
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:443
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:350
UTMCoordinate ConvertGPSToUTM(const GPSCoordinate &stGPSCoord)
Given a GPS coordinate, convert to UTM and create a new UTMCoordinate object.
Definition GeospatialOperations.hpp:302
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
This struct stores/contains information about a GPS data.
Definition GeospatialOperations.hpp:99
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.

144 {
145 // Create instance variables.
146 States eNextState = States::eVerifyingPosition;
147 bool bCompleteStateExit = true;
148
149 switch (eEvent)
150 {
151 case Event::eStart:
152 {
153 // Submit logger message.
154 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Handling Start event.");
155 // Send multimedia command to update state display.
156 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
157 break;
158 }
159 case Event::eVerifyingComplete:
160 {
161 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Handling Verifying Complete event.");
162 // Send multimedia command to update state display.
163 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eReachedGoal);
164 // Pop the next waypoint.
165 globals::g_pWaypointHandler->PopNextWaypoint();
166 // Change state.
167 eNextState = States::eIdle;
168 break;
169 }
170 case Event::eVerifyingFailed:
171 {
172 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Handling Verifying Failed event.");
173 // Send multimedia command to update state display.
174 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
175 // Recall the previous state. This should always be navigation, but we use previous state to be safe.
176 eNextState = globals::g_pStateMachineHandler->GetPreviousState();
177 break;
178 }
179 case Event::eAbort:
180 {
181 // Submit logger message.
182 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Handling Abort event.");
183 // Send multimedia command to update state display.
184 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eOff);
185 // Change state.
186 eNextState = States::eIdle;
187 break;
188 }
189 default:
190 {
191 LOG_WARNING(logging::g_qSharedLogger, "VerifyingPositionState: Handling unknown event.");
192 eNextState = States::eIdle;
193 break;
194 }
195 }
196
197 if (eNextState != States::eVerifyingPosition)
198 {
199 LOG_INFO(logging::g_qSharedLogger, "VerifyingPositionState: Transitioning to {} State.", StateToString(eNextState));
200
201 // Exit the current state
202 if (bCompleteStateExit)
203 {
204 Exit();
205 }
206 }
207
208 return eNextState;
209 }
void SendLightingState(MultimediaBoardLightingState eState)
Sends a predetermined color pattern to board.
Definition MultimediaBoard.cpp:55
statemachine::States GetPreviousState() const
Accessor for the Previous State private member.
Definition StateMachineHandler.cpp:423
geoops::Waypoint PopNextWaypoint()
Removes and returns the next waypoint at the front of the list.
Definition WaypointHandler.cpp:500
void Exit() override
This method is called when the state is exited. It is used to clean up the state.
Definition VerifyingPositionState.cpp:47
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: