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

The VerifyingObjectState class implements the Verifying Object state for the Autonomy State Machine. More...

#include <VerifyingObjectState.h>

Inheritance diagram for statemachine::VerifyingObjectState:
Collaboration diagram for statemachine::VerifyingObjectState:

Public Member Functions

 VerifyingObjectState ()
 Accessor for the State private member. Returns the state as a string.
 
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< ObjectDetector > > m_vObjectDetectors
 
std::chrono::system_clock::time_point m_tmObjectVerificationStartTime
 
std::chrono::system_clock::time_point m_tmObjectLastSeenTime
 

Detailed Description

The VerifyingObjectState class implements the Verifying Object state for the Autonomy State Machine.

Author
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

Constructor & Destructor Documentation

◆ VerifyingObjectState()

statemachine::VerifyingObjectState::VerifyingObjectState ( )

Accessor for the State private member. Returns the state as a string.

Returns
std::string - The current state as a string.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-01-17
70 : State(States::eVerifyingObject)
71 {
72 LOG_INFO(logging::g_qConsoleLogger, "Entering State: {}", ToString());
73
74 m_bInitialized = false;
75
76 if (!m_bInitialized)
77 {
78 Start();
79 m_bInitialized = true;
80 }
81 }
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 VerifyingObjectState.cpp:34
Here is the call graph for this function:

Member Function Documentation

◆ Start()

void statemachine::VerifyingObjectState::Start ( )
overrideprotectedvirtual

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

Author
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.

35 {
36 // Schedule the next run of the state's logic
37 LOG_INFO(logging::g_qSharedLogger, "VerifyingObjectState: Scheduling next run of state logic.");
38
39 // Initialize member variables.
40 m_stGoalWaypoint = globals::g_pWaypointHandler->PeekNextWaypoint();
41 m_tmObjectVerificationStartTime = std::chrono::system_clock::now();
42 m_tmObjectLastSeenTime = std::chrono::system_clock::now();
43
44 // Get object detectors.
45 m_vObjectDetectors = {globals::g_pObjectDetectionHandler->GetObjectDetector(ObjectDetectionHandler::ObjectDetectors::eHeadMainCam)};
46 }
std::shared_ptr< ObjectDetector > GetObjectDetector(ObjectDetectors eDetectorName)
Accessor for ObjectDetector detectors.
Definition ObjectDetectionHandler.cpp:127
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::VerifyingObjectState::Exit ( )
overrideprotectedvirtual

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

Author
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.

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

◆ Run()

void statemachine::VerifyingObjectState::Run ( )
overridevirtual

Run the state machine. Returns the next state.

Author
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

Implements statemachine::State.

90 {
91 LOG_DEBUG(logging::g_qSharedLogger, "VerifyingObjectState: Running state-specific behavior.");
92
93 // Identify target object.
94 objectdetectutils::Object stBestObject;
95 statemachine::IdentifyTargetObject(m_vObjectDetectors, stBestObject, m_stGoalWaypoint.eType);
96 // Calculate how long we've been in this state.
97 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
98 double dElapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(tmCurrentTime - m_tmObjectVerificationStartTime).count() / 1000.0;
99 // Calculate the time since the last time we saw an object.
100 double dTimeSinceLastSeen = std::chrono::duration_cast<std::chrono::milliseconds>(tmCurrentTime - m_tmObjectLastSeenTime).count() / 1000.0;
101
102 /*
103 If we consistently detect an object for a certain amount of time, we can assume that we are in fact in front of the object.
104 At this point, we can also assume we are close enough for the pointcloud to be usable and pick up the object.
105 */
106 // Check if object is detected.
107 if (stBestObject.dConfidence == 0.0)
108 {
109 // Check if the time last seen is greater than the time to give up.
110 if (dTimeSinceLastSeen > constants::APPROACH_OBJECT_LOST_BUFFER_TIME)
111 {
112 // No objects are detected, trigger verify failed event.
113 LOG_INFO(logging::g_qSharedLogger, "VerifyingObjectState: No objects detected. Triggering verify failed event.");
114 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingFailed);
115 return;
116 }
117 }
118 else
119 {
120 // Check the object distance.
121 if (stBestObject.dConfidence > 0.0 && stBestObject.dStraightLineDistance > constants::APPROACH_OBJECT_PROXIMITY_THRESHOLD)
122 {
123 // Object is too far away, trigger verify failed event.
124 LOG_INFO(logging::g_qSharedLogger, "VerifyingObjectState: Object detected but too far away. Triggering verify failed event.");
125 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingFailed);
126 return;
127 }
128
129 // Update time last seen.
130 m_tmObjectLastSeenTime = std::chrono::system_clock::now();
131
132 // Check if we have been in this state long enough to verify the object.
133 if (dElapsedTime >= constants::APPROACH_OBJECT_VERIFY_TIME)
134 {
135 // Submit logger message.
136 LOG_INFO(logging::g_qSharedLogger, "VerifyingObjectState: Object verified. Triggering verify complete event.");
137 // Trigger verify complete event.
138 globals::g_pStateMachineHandler->HandleEvent(Event::eVerifyingComplete);
139 return;
140 }
141 }
142 }
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 IdentifyTargetObject(const std::vector< std::shared_ptr< ObjectDetector > > &vObjectDetectors, objectdetectutils::Object &stObjectTarget, const geoops::WaypointType &eDesiredDetectionType=geoops::WaypointType::eUNKNOWN)
Identify a target object in the rover's vision, using Torch detection.
Definition ObjectDetectionChecker.hpp:90
Represents a single detected object. Combines attributes from TorchObject and TensorflowObject struct...
Definition ObjectDetectionUtility.hpp:73
Here is the call graph for this function:

◆ TriggerEvent()

States statemachine::VerifyingObjectState::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
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

Implements statemachine::State.

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