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

The VerifyingMarkerState class implements the Verifying Marker state for the Autonomy State Machine. More...

#include <VerifyingMarkerState.h>

Inheritance diagram for statemachine::VerifyingMarkerState:
Collaboration diagram for statemachine::VerifyingMarkerState:

Public Member Functions

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

bool m_bInitialized
 
geoops::Waypoint m_stGoalWaypoint
 
std::vector< std::shared_ptr< TagDetector > > m_vTagDetectors
 
std::chrono::system_clock::time_point m_tmTagVerificationStartTime
 
std::chrono::system_clock::time_point m_tmTagLastSeenTime
 

Detailed Description

The VerifyingMarkerState class implements the Verifying Marker 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

◆ VerifyingMarkerState()

statemachine::VerifyingMarkerState::VerifyingMarkerState ( )

Construct a new State object.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-01-17
67 : State(States::eVerifyingMarker)
68 {
69 LOG_INFO(logging::g_qConsoleLogger, "Entering State: {}", ToString());
70
71 m_bInitialized = false;
72
73 if (!m_bInitialized)
74 {
75 Start();
76 m_bInitialized = true;
77 }
78 }
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 VerifyingMarkerState.cpp:32
Here is the call graph for this function:

Member Function Documentation

◆ Start()

void statemachine::VerifyingMarkerState::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.

33 {
34 // Schedule the next run of the state's logic
35 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: Scheduling next run of state logic.");
36
37 // Initialize member variables.
38 m_stGoalWaypoint = globals::g_pWaypointHandler->PeekNextWaypoint();
39 m_tmTagVerificationStartTime = std::chrono::system_clock::now();
40 m_tmTagLastSeenTime = std::chrono::system_clock::now();
41
42 // Get tag detectors.
43 m_vTagDetectors = {globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eHeadMainCam)};
44 }
std::shared_ptr< TagDetector > GetTagDetector(TagDetectors eDetectorName)
Accessor for TagDetector detectors.
Definition TagDetectionHandler.cpp:132
const geoops::Waypoint PeekNextWaypoint()
Returns an immutable reference to the geoops::Waypoint struct at the front of the list without removi...
Definition WaypointHandler.cpp:540
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Exit()

void statemachine::VerifyingMarkerState::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.

55 {
56 // Clean up the state before exiting
57 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: Exiting state.");
58 }
Here is the caller graph for this function:

◆ Run()

void statemachine::VerifyingMarkerState::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.

87 {
88 // Submit logger message.
89 LOG_DEBUG(logging::g_qSharedLogger, "VerifyingMarkerState: Running state-specific behavior.");
90
91 // Identify target marker.
92 tagdetectutils::ArucoTag stBestArucoTag, stBestTorchTag;
93 statemachine::IdentifyTargetMarker(m_vTagDetectors, stBestArucoTag, stBestTorchTag, m_stGoalWaypoint.nID);
94 // Calculate how long we've been in this state.
95 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
96 double dElapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(tmCurrentTime - m_tmTagVerificationStartTime).count() / 1000.0;
97 // Calculate the time since the last time we saw a tag.
98 double dTimeSinceLastSeen = std::chrono::duration_cast<std::chrono::milliseconds>(tmCurrentTime - m_tmTagLastSeenTime).count() / 1000.0;
99
100 /*
101 If we consistently detect a marker for a certain amount of time, we can assume that we are in fact in front of the marker.
102 At this point, we can also assume we are close enough for the pointcloud to be usable and for aruco to pick up the tag.
103 */
104 // Check if ArUco tag is detected.
105 if (stBestArucoTag.nID == -1 && stBestTorchTag.dConfidence == 0.0)
106 {
107 // Check if the time last seen is greater than the time to give up.
108 if (dTimeSinceLastSeen > constants::APPROACH_MARKER_TAG_LOST_BUFFER_TIME)
109 {
110 // No tags are detected, trigger verify failed event.
111 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: No tags detected. Triggering verify failed event.");
112 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingFailed);
113 return;
114 }
115 }
116 else
117 {
118 // Check the tags distance.
119 if (stBestArucoTag.nID != -1 && stBestArucoTag.dStraightLineDistance > constants::APPROACH_MARKER_PROXIMITY_THRESHOLD)
120 {
121 // Tag is too far away, trigger verify failed event.
122 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: ArUco tag detected but too far away. Triggering verify failed event.");
123 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingFailed);
124 return;
125 }
126 else if (stBestTorchTag.dConfidence > 0.0 && stBestTorchTag.dStraightLineDistance > constants::APPROACH_MARKER_PROXIMITY_THRESHOLD)
127 {
128 // Tag is too far away, trigger verify failed event.
129 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: Torch tag detected but too far away. Triggering verify failed event.");
130 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingFailed);
131 return;
132 }
133
134 // Update time last seen.
135 m_tmTagLastSeenTime = std::chrono::system_clock::now();
136
137 // Check if we have been in this state long enough to verify the marker.
138 if (dElapsedTime >= constants::APPROACH_MARKER_VERIFY_TIME)
139 {
140 // Submit logger message.
141 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: Marker verified. Triggering verify complete event.");
142 // Trigger verify complete event.
143 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingComplete);
144 return;
145 }
146 }
147 }
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
int IdentifyTargetMarker(const std::vector< std::shared_ptr< TagDetector > > &vTagDetectors, tagdetectutils::ArucoTag &stArucoTarget, tagdetectutils::ArucoTag &stTorchTarget, const int nTargetTagID=static_cast< int >(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::ANY))
Identify a target marker in the rover's vision, using OpenCV detection.
Definition TagDetectionChecker.hpp:91
Represents a single ArUco tag. Combines attributes from TorchTag, TensorflowTag, and the original Aru...
Definition TagDetectionUtilty.hpp:59
Here is the call graph for this function:

◆ TriggerEvent()

States statemachine::VerifyingMarkerState::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.

159 {
160 // Create instance variables.
161 States eNextState = States::eVerifyingMarker;
162 bool bCompleteStateExit = true;
163
164 switch (eEvent)
165 {
166 case Event::eStart:
167 {
168 // Submit logger message.
169 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: Handling Start event.");
170 // Send multimedia command to update state display.
171 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
172 break;
173 }
174 case Event::eVerifyingComplete:
175 {
176 // Submit logger message.
177 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: Handling Verifying Complete event.");
178 // Send multimedia command to update state display.
179 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eReachedGoal);
180 // Pop old waypoint out of queue.
181 globals::g_pWaypointHandler->PopNextWaypoint();
182 // Clear saved states.
183 globals::g_pStateMachineHandler->ClearSavedStates();
184 // Submit logger message.
185 LOG_NOTICE(logging::g_qSharedLogger, "VerifyingMarkerState: Cleared old saved states.");
186 // Change state.
187 eNextState = States::eIdle;
188 break;
189 }
190 case Event::eVerifyingFailed:
191 {
192 // Submit logger message.
193 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: Handling Verifying Failed event.");
194 // Send multimedia command to update state display.
195 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
196 // Recall the previous state.
197 eNextState = globals::g_pStateMachineHandler->GetPreviousState();
198 break;
199 }
200 case Event::eAbort:
201 {
202 // Submit logger message.
203 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: Handling Abort event.");
204 // Send multimedia command to update state display.
205 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eOff);
206 // Change state.
207 eNextState = States::eIdle;
208 break;
209 }
210 default:
211 {
212 LOG_WARNING(logging::g_qSharedLogger, "VerifyingMarkerState: Handling unknown event.");
213 eNextState = States::eIdle;
214 break;
215 }
216 }
217
218 if (eNextState != States::eVerifyingMarker)
219 {
220 LOG_INFO(logging::g_qSharedLogger, "VerifyingMarkerState: Transitioning to {} State.", StateToString(eNextState));
221
222 // Exit the current state
223 if (bCompleteStateExit)
224 {
225 Exit();
226 }
227 }
228
229 return eNextState;
230 }
void SendLightingState(MultimediaBoardLightingState eState)
Sends a predetermined color pattern to board.
Definition MultimediaBoard.cpp:55
void ClearSavedStates()
Clear all saved states.
Definition StateMachineHandler.cpp:376
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 VerifyingMarkerState.cpp:54
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: