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

geoops::RoverPose m_stStartRoverPose
 
bool m_bInitialized
 
std::vector< std::shared_ptr< TagDetector > > m_vTagDetectors
 

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
62 : State(States::eIdle)
63 {
64 LOG_INFO(logging::g_qConsoleLogger, "Entering State: {}", ToString());
65
66 m_bInitialized = false;
67
68 if (!m_bInitialized)
69 {
70 Start();
71 m_bInitialized = true;
72 }
73 }
void Start() override
This method is called when the state is first started. It is used to initialize the state.
Definition IdleState.cpp:31
virtual std::string ToString() const
Accessor for the State private member. Returns the state as a string.
Definition State.hpp:202
State(States eState)
Construct a new State object.
Definition State.hpp:145
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), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2024-01-17

Reimplemented from statemachine::State.

32 {
33 // Schedule the next run of the state's logic
34 LOG_INFO(logging::g_qSharedLogger, "IdleState: Scheduling next run of state logic.");
35
36 // Get tag detectors.
37 m_vTagDetectors = {globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eHeadMainCam),
38 globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eRearCam)};
39 }
std::shared_ptr< TagDetector > GetTagDetector(TagDetectors eDetectorName)
Accessor for TagDetector detectors.
Definition TagDetectionHandler.cpp:163
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.

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

82 {
83 // Submit logger message.
84 LOG_DEBUG(logging::g_qSharedLogger, "IdleState: Running state-specific behavior.");
85
86 // Create instance variables.
87 geoops::RoverPose stCurrentRoverPose = globals::g_pStateMachineHandler->SmartRetrieveRoverPose();
88
89 // Calculate distance from current position to position when idle state was entered.
90 geoops::GeoMeasurement stMeasurement = geoops::CalculateGeoMeasurement(m_stStartRoverPose.GetGPSCoordinate(), stCurrentRoverPose.GetGPSCoordinate());
91 // Check if the rover is still moving.
92 if (stMeasurement.dDistanceMeters > 0.1)
93 {
94 // Send stop drive command.
95 globals::g_pDriveBoard->SendStop();
96 // Update Idle start pose.
97 m_stStartRoverPose = stCurrentRoverPose;
98 // Submit logger message.
99 LOG_INFO(logging::g_qSharedLogger, "IdleState: Stopped drive.");
100 }
101 }
void SendStop()
Stop the drivetrain of the Rover.
Definition DriveBoard.cpp:246
geoops::RoverPose SmartRetrieveRoverPose(bool bIMUHeading=true)
This method is used to retrieve the rover's current position and heading. It uses the GPS data from t...
Definition StateMachineHandler.cpp:375
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:553
This struct is used to store the distance, arc length, and relative bearing for a calculated geodesic...
Definition GeospatialOperations.hpp:83
This struct is used by the WaypointHandler to provide an easy way to store all pose data about the ro...
Definition GeospatialOperations.hpp:708
const geoops::GPSCoordinate & GetGPSCoordinate() const
Accessor for the geoops::GPSCoordinate member variable.
Definition GeospatialOperations.hpp:756
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.

113 {
114 // Create instance variables.
115 States eNextState = States::eIdle;
116 bool bCompleteStateExit = true;
117
118 switch (eEvent)
119 {
120 case Event::eStart:
121 {
122 // Submit logger message.
123 LOG_INFO(logging::g_qSharedLogger, "IdleState: Handling Start event.");
124 // Send multimedia command to update state display.
125 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
126
127 bool tagInSight = false; // TODO: Replace with actual tag detection
128 bool reverseAlways = false; // TODO: Replace with actual reverse always flag
129
130 // If there is an ArUco marker in the camera's field of view, transition to backup before navigating.
131 if (tagInSight)
132 {
133 LOG_INFO(logging::g_qSharedLogger, "IdleState: Detected ArUco marker. Transitioning to Reverse State.");
134 eNextState = States::eReversing;
135 }
136 // If the reverse always flag is set, transition to backup before navigating.
137 else if (reverseAlways)
138 {
139 LOG_INFO(logging::g_qSharedLogger, "IdleState: Reverse always flag set. Transitioning to Reverse State.");
140 eNextState = States::eReversing;
141 }
142 // Otherwise, transition to navigating.
143 else
144 {
145 // Check if waypoint handler has any waypoints.
146 if (globals::g_pWaypointHandler->GetWaypointCount() > 0)
147 {
148 // Submit logger message.
149 LOG_INFO(logging::g_qSharedLogger, "IdleState: No ArUco marker detected. Transitioning to Navigating State.");
150 // Change states.
151 eNextState = States::eNavigating;
152 }
153 else
154 {
155 // Submit logger message.
156 LOG_NOTICE(logging::g_qSharedLogger,
157 "IdleState: Not transitioning to NavigatingState because no waypoints have been added to the waypoint handler!");
158 }
159 }
160
161 break;
162 }
163 case Event::eAbort:
164 {
165 // Submit logger message.
166 LOG_INFO(logging::g_qSharedLogger, "IdleState: Handling Abort event.");
167 // Send multimedia command to update state display.
168 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eOff);
169 // Ensure drive is stopped.
170 globals::g_pDriveBoard->SendStop();
171 break;
172 }
173 default:
174 {
175 // Submit logger message.
176 LOG_WARNING(logging::g_qSharedLogger, "IdleState: Handling unknown event.");
177 break;
178 }
179 }
180
181 if (eNextState != States::eIdle)
182 {
183 LOG_INFO(logging::g_qSharedLogger, "IdleState: Transitioning to {} State.", StateToString(eNextState));
184
185 // Exit the current state
186 if (bCompleteStateExit)
187 {
188 Exit();
189 }
190 }
191
192 return eNextState;
193 }
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:49
std::string StateToString(States eState)
Converts a state object to a string.
Definition State.hpp:85
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: