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::IdleState Class Reference

The IdleState class implements the Idle state for the Autonomy State Machine. More...

#include <IdleState.h>

Inheritance diagram for statemachine::IdleState:
Collaboration diagram for statemachine::IdleState:

Public Member Functions

 IdleState ()
 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

time_t m_tIdleTime
 
bool m_bRealigned
 
geoops::RoverPose m_stStartRoverPose
 
std::vector< std::tuple< double, double > > m_vRoverPosition
 
int m_nMaxDataPoints
 
bool m_bInitialized
 

Detailed Description

The IdleState class implements the Idle state for the Autonomy State Machine.

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

Constructor & Destructor Documentation

◆ IdleState()

statemachine::IdleState::IdleState ( )

Construct a new State object.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-01-17
68 : State(States::eIdle)
69 {
70 LOG_INFO(logging::g_qConsoleLogger, "Entering State: {}", ToString());
71
72 m_bInitialized = false;
73
74 if (!m_bInitialized)
75 {
76 Start();
77 m_bInitialized = true;
78 }
79 }
void Start() override
This method is called when the state is first started. It is used to initialize the state.
Definition IdleState.cpp:30
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
Here is the call graph for this function:

Member Function Documentation

◆ Start()

void statemachine::IdleState::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-01-17

Reimplemented from statemachine::State.

31 {
32 // Schedule the next run of the state's logic
33 LOG_INFO(logging::g_qSharedLogger, "IdleState: Scheduling next run of state logic.");
34
35 m_tIdleTime = time(nullptr);
36 m_bRealigned = false;
37 m_nMaxDataPoints = 100;
38 m_vRoverPosition.reserve(m_nMaxDataPoints);
39
40 // Get the start rover pose.
41 m_stStartRoverPose = globals::g_pWaypointHandler->SmartRetrieveRoverPose();
42 }
geoops::RoverPose SmartRetrieveRoverPose(bool bVIOTracking=false)
Retrieve the rover's current position and heading. Automatically picks between getting the position/h...
Definition WaypointHandler.cpp:738
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Exit()

void statemachine::IdleState::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-01-17

Reimplemented from statemachine::State.

53 {
54 // Clean up the state before exiting
55 LOG_INFO(logging::g_qSharedLogger, "IdleState: Exiting state.");
56
57 // Clear rover position waypoints.
58 m_vRoverPosition.clear();
59 }
Here is the caller graph for this function:

◆ Run()

void statemachine::IdleState::Run ( )
overridevirtual

Run the state machine. Returns the next state.

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

Implements statemachine::State.

88 {
89 // Submit logger message.
90 LOG_DEBUG(logging::g_qSharedLogger, "IdleState: Running state-specific behavior.");
91
92 // Create instance variables.
93 geoops::RoverPose stCurrentRoverPose;
94
95 // Get the current rover gps position.
96 stCurrentRoverPose = globals::g_pWaypointHandler->SmartRetrieveRoverPose();
97 // Store the Rover's position.
98 m_vRoverPosition.push_back(std::make_tuple(stCurrentRoverPose.GetUTMCoordinate().dEasting, stCurrentRoverPose.GetUTMCoordinate().dNorthing));
99
100 // Calculate distance from current position to position when idle state was entered.
101 geoops::GeoMeasurement stMeasurement = geoops::CalculateGeoMeasurement(m_stStartRoverPose.GetGPSCoordinate(), stCurrentRoverPose.GetGPSCoordinate());
102 // Check if the rover is still moving.
103 if (stMeasurement.dDistanceMeters > 0.1)
104 {
105 // Send stop drive command.
106 globals::g_pDriveBoard->SendStop();
107 // Update Idle start pose.
108 m_stStartRoverPose = stCurrentRoverPose;
109 // Submit logger message.
110 LOG_INFO(logging::g_qSharedLogger, "IdleState: Stopped drive.");
111 }
112
113 // If the last state was searchpattern and the waypoint handler has been cleared, reset.
114 if (globals::g_pStateMachineHandler->GetPreviousState() != States::eIdle && globals::g_pWaypointHandler->GetWaypointCount() <= 0)
115 {
116 // Submit logger message.
117 LOG_NOTICE(logging::g_qSharedLogger, "IdleState: WaypointHandler queue is empty while in IdleState, deleting old saved states...");
118 // Reset all old states. Since waypoint handler has been cleared, there's no need to save old searchpattern state.
119 globals::g_pStateMachineHandler->ClearSavedStates();
120 }
121 }
void SendStop()
Stop the drivetrain of the Rover.
Definition DriveBoard.cpp:162
void ClearSavedStates()
Clear all saved states.
Definition StateMachineHandler.cpp:360
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 is used to store the distance, arc length, and relative bearing for a calculated geodesic...
Definition GeospatialOperations.hpp:82
This struct is used by the WaypointHandler to provide an easy way to store all pose data about the ro...
Definition GeospatialOperations.hpp:674
const geoops::GPSCoordinate & GetGPSCoordinate() const
Accessor for the geoops::GPSCoordinate member variable.
Definition GeospatialOperations.hpp:722
const geoops::UTMCoordinate & GetUTMCoordinate() const
Accessor for the geoops::UTMCoordinate member variable.
Definition GeospatialOperations.hpp:733
Here is the call graph for this function:

◆ TriggerEvent()

States statemachine::IdleState::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-01-17

Implements statemachine::State.

133 {
134 // Create instance variables.
135 States eNextState = States::eIdle;
136 bool bCompleteStateExit = true;
137
138 switch (eEvent)
139 {
140 case Event::eStart:
141 {
142 // Submit logger message.
143 LOG_INFO(logging::g_qSharedLogger, "IdleState: Handling Start event.");
144 // Send multimedia command to update state display.
145 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
146
147 bool tagInSight = false; // TODO: Replace with actual tag detection
148 bool reverseAlways = false; // TODO: Replace with actual reverse always flag
149
150 // If there is an ArUco marker in the camera's field of view, transition to backup before navigating.
151 if (tagInSight)
152 {
153 LOG_INFO(logging::g_qSharedLogger, "IdleState: Detected ArUco marker. Transitioning to Reverse State.");
154 eNextState = States::eReversing;
155 }
156 // If the reverse always flag is set, transition to backup before navigating.
157 else if (reverseAlways)
158 {
159 LOG_INFO(logging::g_qSharedLogger, "IdleState: Reverse always flag set. Transitioning to Reverse State.");
160 eNextState = States::eReversing;
161 }
162 // Otherwise, transition to navigating.
163 else
164 {
165 // Check if waypoint handler has any waypoints.
166 if (globals::g_pWaypointHandler->GetWaypointCount() > 0)
167 {
168 // Submit logger message.
169 LOG_INFO(logging::g_qSharedLogger, "IdleState: No ArUco marker detected. Transitioning to Navigating State.");
170 // Change states.
171 eNextState = States::eNavigating;
172 }
173 else
174 {
175 // Submit logger message.
176 LOG_NOTICE(logging::g_qSharedLogger,
177 "IdleState: Not transitioning to NavigatingState because no waypoints have been added to the waypoint handler!");
178 }
179 }
180
181 break;
182 }
183 case Event::eAbort:
184 {
185 // Submit logger message.
186 LOG_INFO(logging::g_qSharedLogger, "IdleState: Handling Abort event.");
187 // Send multimedia command to update state display.
188 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
189 // Ensure drive is stopped.
190 globals::g_pDriveBoard->SendStop();
191 break;
192 }
193 default:
194 {
195 // Submit logger message.
196 LOG_WARNING(logging::g_qSharedLogger, "IdleState: Handling unknown event.");
197 break;
198 }
199 }
200
201 if (eNextState != States::eIdle)
202 {
203 LOG_INFO(logging::g_qSharedLogger, "IdleState: Transitioning to {} State.", StateToString(eNextState));
204
205 // Exit the current state
206 if (bCompleteStateExit)
207 {
208 Exit();
209 }
210 }
211
212 return eNextState;
213 }
void SendLightingState(MultimediaBoardLightingState eState)
Sends a predetermined color pattern to board.
Definition MultimediaBoard.cpp:55
void Exit() override
This method is called when the state is exited. It is used to clean up the state.
Definition IdleState.cpp:52
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: