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

The ApproachingMarkerState class implements the Approaching Marker state for the Autonomy State Machine. More...

#include <ApproachingMarkerState.h>

Inheritance diagram for statemachine::ApproachingMarkerState:
Collaboration diagram for statemachine::ApproachingMarkerState:

Public Member Functions

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

std::vector< std::shared_ptr< TagDetector > > m_vTagDetectors
 
statemachine::TimeIntervalBasedStuckDetector m_StuckDetector
 
States m_eTriggeringState
 
bool m_bInitialized
 
geoops::Waypoint m_stGoalWaypoint
 
double m_dHeadingSetPoint
 
double m_dDistanceFromTag
 
bool m_bDriveBackwards
 
geoops::Waypoint m_stLastGeolocatedPosition
 
bool m_bHasLastGeolocatedPosition
 
bool m_bHasSeenTarget
 
std::chrono::system_clock::time_point m_tmLastSeenTime
 
std::chrono::system_clock::time_point m_tmLastLogTime
 
bool m_bAlreadyPrintedLost
 
bool m_bAlreadyPrintedVisualLostFallback
 

Detailed Description

The ApproachingMarkerState class implements the Approaching 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

◆ ApproachingMarkerState()

statemachine::ApproachingMarkerState::ApproachingMarkerState ( )

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

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
89 : State(States::eApproachingMarker)
90 {
91 LOG_INFO(logging::g_qConsoleLogger, "Entering State: {}", ToString());
92
93 m_bInitialized = false;
94
95 m_StuckDetector = statemachine::TimeIntervalBasedStuckDetector(constants::APPROACH_MARKER_STUCK_CHECK_ATTEMPTS, constants::APPROACH_MARKER_STUCK_CHECK_INTERVAL);
96
97 if (!m_bInitialized)
98 {
99 Start();
100 m_bInitialized = true;
101 }
102 }
void Start() override
This method is called when the state is first started. It is used to initialize the state.
Definition ApproachingMarkerState.cpp:33
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
This class should be instantiated within another state to be used for detection of if the rover is st...
Definition StuckDetection.hpp:43
Here is the call graph for this function:

Member Function Documentation

◆ Start()

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

34 {
35 // Schedule the next run of the state's logic.
36 LOG_INFO(logging::g_qSharedLogger, "ApproachingMarkerState: Scheduling next run of state logic.");
37
38 // Initialize target parameters.
39 m_stGoalWaypoint = globals::g_pWaypointHandler->PeekNextWaypoint();
40 m_eTriggeringState = globals::g_pStateMachineHandler->GetPreviousState();
41
42 // Schedule the next run of the state's logic.
43 LOG_INFO(logging::g_qSharedLogger,
44 "ApproachingMarkerState: Started. Goal Waypoint -> Lat: {:.6f}, Lon: {:.6f}, Radius: {:.2f}m, Target ID: {}. Previous State: {}",
45 m_stGoalWaypoint.GetGPSCoordinate().dLatitude,
46 m_stGoalWaypoint.GetGPSCoordinate().dLongitude,
47 m_stGoalWaypoint.dRadius,
48 m_stGoalWaypoint.nID,
49 StateToString(m_eTriggeringState));
50
51 // Fetch detectors.
52 m_vTagDetectors = {globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eHeadMainCam),
53 globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eRearCam)};
54
55 LOG_INFO(logging::g_qSharedLogger, "ApproachingMarkerState: Fetched {} tag detectors for tracking.", m_vTagDetectors.size());
56
57 // Reset all persistent tracking variables for a clean slate.
58 m_dHeadingSetPoint = 0.0;
59 m_dDistanceFromTag = 0.0;
60 m_bDriveBackwards = false;
61 m_bHasLastGeolocatedPosition = false;
62 m_bHasSeenTarget = false;
63 m_bAlreadyPrintedLost = false;
64 m_bAlreadyPrintedVisualLostFallback = false;
65 m_tmLastSeenTime = std::chrono::system_clock::now();
66 m_tmLastLogTime = std::chrono::system_clock::now();
67 }
statemachine::States GetPreviousState() const
Accessor for the Previous State private member.
Definition StateMachineHandler.cpp:358
std::shared_ptr< TagDetector > GetTagDetector(TagDetectors eDetectorName)
Accessor for TagDetector detectors.
Definition TagDetectionHandler.cpp:163
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
std::string StateToString(States eState)
Converts a state object to a string.
Definition State.hpp:85
const geoops::GPSCoordinate & GetGPSCoordinate() const
Accessor for the geoops::GPSCoordinate member variable.
Definition GeospatialOperations.hpp:497
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Exit()

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

78 {
79 // Clean up the state before exiting.
80 LOG_INFO(logging::g_qSharedLogger, "ApproachingMarkerState: Exiting state.");
81 }
Here is the caller graph for this function:

◆ Run()

void statemachine::ApproachingMarkerState::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

STATE LOGIC FLOW:

  1. Geofence Check: Verify the rover is within the goal waypoint's radius.
  2. Target Identification: Find the closest target across all cameras using screen area %.
  3. Navigation Decision Tree: -> Target Unseen: Coast on last heading -> Drive to last GPS -> Timeout & Exit. -> Target Detected: Toggle Forward/Reverse based on camera (Front vs Rear).
  • Good Depth (> 0.0m): Calculate absolute GPS heading and save to history.
  • Bad Depth (== 0.0m): Fallback to pure relative vision heading (Yaw).
  1. Execution: Send drive commands, check proximity for success, and run stuck detection.

Implements statemachine::State.

111 {
112
124 LOG_DEBUG(logging::g_qSharedLogger, "ApproachingMarkerState: Running state-specific behavior.");
125
126 // Get the current rover pose and add to plot.
127 geoops::RoverPose stCurrentRoverPose = globals::g_pStateMachineHandler->SmartRetrieveRoverPose();
128
129 // 1. Boundary Check: Verify rover radius from marker waypoint.
130 geoops::GeoMeasurement stCurrentMeasurement = geoops::CalculateGeoMeasurement(m_stGoalWaypoint.GetGPSCoordinate(), stCurrentRoverPose.GetGPSCoordinate());
131 if (stCurrentMeasurement.dDistanceMeters > m_stGoalWaypoint.dRadius)
132 {
133 LOG_WARNING(logging::g_qSharedLogger,
134 "ApproachingMarkerState: Rover broke geofence! Radius threshold is {} m, current distance is {:.2f} m. Triggering MarkerUnseen.",
135 m_stGoalWaypoint.dRadius,
136 stCurrentMeasurement.dDistanceMeters);
137 globals::g_pStateMachineHandler->HandleEvent(Event::eMarkerUnseen);
138 return;
139 }
140
141 // 2. Identify target marker.
142 tagdetectutils::ArucoTag stBestArucoTag;
143 tagdetectutils::ArucoTag stBestTorchTag; // Used as placeholder for ML torch tag structure
144 statemachine::IdentifyTargetMarker(m_vTagDetectors, stBestArucoTag, stBestTorchTag, m_stGoalWaypoint.nID);
145
146 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
147 double dSecondsSinceLastSeen = std::chrono::duration_cast<std::chrono::milliseconds>(tmCurrentTime - m_tmLastSeenTime).count() / 1000.0;
148 bool bMarkerDetected = (stBestArucoTag.nID != -1 || stBestTorchTag.dConfidence != 0.0);
149
150 // Clear stale session data if re-entered after a long time.
151 if (dSecondsSinceLastSeen > constants::APPROACH_MARKER_LOST_GIVE_UP_TIME + 5.0)
152 {
153 m_bHasLastGeolocatedPosition = false;
154 }
155
156 std::string szCameraOrigin = "Unknown/None";
157 std::string szTagModelSource = "None";
158 double dCurrentTagYaw = 0.0;
159 double dCurrentTagConf = 0.0;
160
161 // 3. Update tracking states.
162 if (!bMarkerDetected)
163 {
164 // Marker unseen.
165 if (dSecondsSinceLastSeen > constants::APPROACH_MARKER_LOST_GIVE_UP_TIME)
166 {
167 LOG_WARNING(logging::g_qSharedLogger,
168 "ApproachingMarkerState: Tag has been unseen for {:.2f}s (Threshold: {:.2f}s). Giving up and triggering MarkerUnseen.",
169 dSecondsSinceLastSeen,
170 constants::APPROACH_MARKER_LOST_GIVE_UP_TIME);
171 globals::g_pStateMachineHandler->HandleEvent(Event::eMarkerUnseen);
172 return;
173 }
174
175 if (!m_bAlreadyPrintedLost)
176 {
177 m_bAlreadyPrintedLost = true;
178 LOG_WARNING(logging::g_qSharedLogger, "ApproachingMarkerState: Tracking lost! No valid markers/tags detected across any camera.");
179 }
180
181 // Fallback 1: Drive to last known geolocated position if available.
182 if (m_bHasLastGeolocatedPosition)
183 {
184 geoops::GeoMeasurement stLastMeasurement =
185 geoops::CalculateGeoMeasurement(stCurrentRoverPose.GetUTMCoordinate(), m_stLastGeolocatedPosition.GetUTMCoordinate());
186 m_dHeadingSetPoint = stLastMeasurement.dStartRelativeBearing;
187 m_dDistanceFromTag = stLastMeasurement.dDistanceMeters;
188
189 if (!m_bAlreadyPrintedVisualLostFallback)
190 {
191 LOG_NOTICE(logging::g_qSharedLogger,
192 "ApproachingMarkerState: [FALLBACK 1] Visual lost. Driving to last known geolocated UTM: [{:.2f}E, {:.2f}N]. Current Dist: {:.2f}m, "
193 "Target Bearing: {:.2f} degrees, Reverse: {}",
194 m_stLastGeolocatedPosition.GetUTMCoordinate().dEasting,
195 m_stLastGeolocatedPosition.GetUTMCoordinate().dNorthing,
196 m_dDistanceFromTag,
197 m_dHeadingSetPoint,
198 m_bDriveBackwards);
199 m_bAlreadyPrintedVisualLostFallback = true;
200 }
201 }
202 // Fallback 2: Coast along last known heading (Handles 0.0 distance depth dropouts).
203 else if (m_bHasSeenTarget)
204 {
205 if (!m_bAlreadyPrintedVisualLostFallback)
206 {
207 LOG_NOTICE(
208 logging::g_qSharedLogger,
209 "ApproachingMarkerState: [FALLBACK 2] Visual lost & no geolocation history. Coasting along last known heading. Target Bearing: {:.2f} degrees, "
210 "Reverse: {}",
211 m_dHeadingSetPoint,
212 m_bDriveBackwards);
213 m_bAlreadyPrintedVisualLostFallback = true;
214 }
215 }
216 // Wait in place: We have never seen the marker.
217 else
218 {
219 globals::g_pDriveBoard->SendStop();
220 return;
221 }
222 }
223 else
224 {
225 // Marker detected.
226 if (m_bAlreadyPrintedLost)
227 {
228 LOG_NOTICE(logging::g_qSharedLogger, "ApproachingMarkerState: Tracking regained! Target marker re-acquired.");
229 }
230
231 // Reset temporal trackers.
232 m_tmLastSeenTime = tmCurrentTime;
233 m_bAlreadyPrintedLost = false;
234 m_bAlreadyPrintedVisualLostFallback = false;
235 m_bHasSeenTarget = true;
236
237 std::shared_ptr<TagDetector> pFrontDetector = globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eHeadMainCam);
238 std::shared_ptr<TagDetector> pRearDetector = globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eRearCam);
239
240 // Handle specific tag logic tracking.
241 if (stBestArucoTag.nID != -1)
242 {
243 szTagModelSource = "OpenCV ArUco (ID: " + std::to_string(stBestArucoTag.nID) + ")";
244 dCurrentTagYaw = stBestArucoTag.dYawAngle;
245 dCurrentTagConf = stBestArucoTag.dConfidence;
246
247 if (pFrontDetector != nullptr && stBestArucoTag.szDetectorUUID == pFrontDetector->GetThreadUUID())
248 {
249 m_bDriveBackwards = false;
250 szCameraOrigin = "Head Main Camera";
251 }
252 else if (pRearDetector != nullptr && stBestArucoTag.szDetectorUUID == pRearDetector->GetThreadUUID())
253 {
254 m_bDriveBackwards = true;
255 szCameraOrigin = "Rear Camera";
256 }
257 else
258 {
259 szCameraOrigin = "Unknown Camera";
260 }
261
262 m_dDistanceFromTag = stBestArucoTag.dStraightLineDistance;
263
264 // Require distance to be greater than 0.0 to use Geolocation absolute tracking.
265 if (stBestArucoTag.stGeolocatedPosition.eType != geoops::WaypointType::eUNKNOWN && m_dDistanceFromTag > 0.0)
266 {
267 geoops::GeoMeasurement stTagMeasurement =
268 geoops::CalculateGeoMeasurement(stCurrentRoverPose.GetUTMCoordinate(), stBestArucoTag.stGeolocatedPosition.GetUTMCoordinate());
269 m_dHeadingSetPoint = stTagMeasurement.dStartRelativeBearing;
270 m_stLastGeolocatedPosition = stBestArucoTag.stGeolocatedPosition;
271 m_bHasLastGeolocatedPosition = true;
272 }
273 else
274 {
275 // Fallback to pure relative tracking (Current Heading + Yaw Angle).
276 double dVisionYawOffset = stBestArucoTag.dYawAngle;
277 if (m_bDriveBackwards)
278 {
279 dVisionYawOffset += 180.0;
280 }
281 m_dHeadingSetPoint = numops::InputAngleModulus(dVisionYawOffset + stCurrentRoverPose.GetCompassHeading(), 0.0, 360.0);
282 }
283 }
284 else if (stBestTorchTag.dConfidence != 0.0)
285 {
286 szTagModelSource = "ML Torch Model";
287 dCurrentTagYaw = stBestTorchTag.dYawAngle;
288 dCurrentTagConf = stBestTorchTag.dConfidence;
289
290 if (pFrontDetector != nullptr && stBestTorchTag.szDetectorUUID == pFrontDetector->GetThreadUUID())
291 {
292 m_bDriveBackwards = false;
293 szCameraOrigin = "Head Main Camera";
294 }
295 else if (pRearDetector != nullptr && stBestTorchTag.szDetectorUUID == pRearDetector->GetThreadUUID())
296 {
297 m_bDriveBackwards = true;
298 szCameraOrigin = "Rear Camera";
299 }
300 else
301 {
302 szCameraOrigin = "Unknown Camera";
303 }
304
305 m_dDistanceFromTag = stBestTorchTag.dStraightLineDistance;
306
307 // Require distance to be greater than 0.0 to use Geolocation absolute tracking.
308 if (stBestTorchTag.stGeolocatedPosition.eType != geoops::WaypointType::eUNKNOWN && m_dDistanceFromTag > 0.0)
309 {
310 geoops::GeoMeasurement stTagMeasurement =
311 geoops::CalculateGeoMeasurement(stCurrentRoverPose.GetUTMCoordinate(), stBestTorchTag.stGeolocatedPosition.GetUTMCoordinate());
312 m_dHeadingSetPoint = stTagMeasurement.dStartRelativeBearing;
313 m_stLastGeolocatedPosition = stBestTorchTag.stGeolocatedPosition;
314 m_bHasLastGeolocatedPosition = true;
315 }
316 else
317 {
318 // Fallback to pure relative tracking (Current Heading + Yaw Angle).
319 double dVisionYawOffset = stBestTorchTag.dYawAngle;
320 if (m_bDriveBackwards)
321 {
322 dVisionYawOffset += 180.0;
323 }
324 m_dHeadingSetPoint = numops::InputAngleModulus(dVisionYawOffset + stCurrentRoverPose.GetCompassHeading(), 0.0, 360.0);
325 }
326 }
327 }
328
329 // 4. Execute Move Commands.
330 diffdrive::DrivePowers stDrivePowers = globals::g_pDriveBoard->CalculateMove(constants::APPROACH_MARKER_MOTOR_POWER,
331 m_dHeadingSetPoint,
332 stCurrentRoverPose.GetCompassHeading(),
333 diffdrive::DifferentialControlMethod::eArcadeDrive,
334 m_bDriveBackwards, // Reverse control flag.
335 false,
336 false,
337 false);
338 globals::g_pDriveBoard->SendDrive(stDrivePowers);
339
340 // 5. Output periodic logging (1Hz).
341 if (std::chrono::duration_cast<std::chrono::seconds>(tmCurrentTime - m_tmLastLogTime).count() >= 1)
342 {
343 m_tmLastLogTime = tmCurrentTime;
344
345 if (bMarkerDetected)
346 {
347 std::string szTrackingType = (m_bHasLastGeolocatedPosition && m_dDistanceFromTag > 0.0) ? "Absolute (GPS Geolocation)" : "Relative (Vision Yaw Angle)";
348
349 LOG_NOTICE(logging::g_qSharedLogger,
350 "ApproachingMarkerState Status:\n"
351 " >> Detection : Source: {}, Camera: {}\n"
352 " >> Target : Conf: {:.2f}%, Dist: {:.2f}m, Yaw: {:.2f} degrees\n"
353 " >> Tracking : Mode: {}, Reverse: {}\n"
354 " >> Navigation : Curr Hdg: {:.2f} degrees, Tgt Hdg: {:.2f} degrees",
355 szTagModelSource,
356 szCameraOrigin,
357 dCurrentTagConf * 100.0,
358 m_dDistanceFromTag,
359 dCurrentTagYaw,
360 szTrackingType,
361 m_bDriveBackwards ? "TRUE" : "FALSE",
362 stCurrentRoverPose.GetCompassHeading(),
363 m_dHeadingSetPoint);
364 }
365 else
366 {
367 LOG_NOTICE(logging::g_qSharedLogger,
368 "ApproachingMarkerState Status: Marker not visible. Executing fallback logic. Target Hdg: {:.2f} degrees, Reverse: {}, Est. Dist: {:.2f}m",
369 m_dHeadingSetPoint,
370 m_bDriveBackwards,
371 m_dDistanceFromTag);
372 }
373 }
374
375 // 6. Check if target is reached.
376 if (m_dDistanceFromTag != 0.0 && m_dDistanceFromTag < constants::APPROACH_MARKER_PROXIMITY_THRESHOLD)
377 {
378 LOG_NOTICE(logging::g_qSharedLogger,
379 "ApproachingMarkerState: SUCCESS! Rover has reached the target marker! (Distance: {:.2f}m < Threshold: {:.2f}m)",
380 m_dDistanceFromTag,
381 constants::APPROACH_MARKER_PROXIMITY_THRESHOLD);
382
383 globals::g_pStateMachineHandler->HandleEvent(Event::eReachedMarker, true);
384 return;
385 }
386
387 // 7. Check if the rover is stuck.
388 if (constants::APPROACH_MARKER_ENABLE_STUCK_DETECT &&
389 m_StuckDetector.CheckIfStuck(globals::g_pStateMachineHandler->SmartRetrieveVelocity(),
390 globals::g_pStateMachineHandler->SmartRetrieveAngularVelocity(),
391 constants::APPROACH_MARKER_STUCK_CHECK_VEL_THRESH * globals::g_pDriveBoard->GetMaxDriveEffort(),
392 constants::APPROACH_MARKER_STUCK_CHECK_ROT_THRESH))
393 {
394 LOG_WARNING(logging::g_qSharedLogger,
395 "ApproachingMarkerState: Rover has become stuck! Triggering Stuck event. Curr Vel: {:.2f}, Ang Vel: {:.2f}",
396 globals::g_pStateMachineHandler->SmartRetrieveVelocity(),
397 globals::g_pStateMachineHandler->SmartRetrieveAngularVelocity());
398 globals::g_pStateMachineHandler->HandleEvent(Event::eStuck, true);
399 return;
400 }
401 }
void SendDrive(const diffdrive::DrivePowers &stDrivePowers, const bool bEnableVariableDriveEffort=true)
Sets the left and right drive powers of the drive board.
Definition DriveBoard.cpp:166
diffdrive::DrivePowers CalculateMove(const double dGoalSpeed, const double dGoalHeading, const double dActualHeading, const diffdrive::DifferentialControlMethod eKinematicsMethod=diffdrive::DifferentialControlMethod::eArcadeDrive, const bool bDriveBackwards=false, const bool bAlwaysProgressForward=false, const bool bSquareControlInput=false, const bool bCurvatureDriveAllowTurningWhileStopped=true)
This method determines drive powers to make the Rover drive towards a given heading at a given speed.
Definition DriveBoard.cpp:89
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
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:285
bool CheckIfStuck(double dCurrentVelocity, double dCurrentAngularVelocity, double dVelocityThreshold=0.1, double dAngularVelocityThreshold=0.1)
Checks if the rover meets stuck criteria based in the given parameters.
Definition StuckDetection.hpp:96
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
constexpr T InputAngleModulus(T tValue, T tMinValue, T tMaxValue)
Calculates the modulus of an input angle.
Definition NumberOperations.hpp:162
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:100
This struct is used to store the left and right drive powers for the robot. Storing these values in a...
Definition DifferentialDrive.hpp:73
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
double GetCompassHeading() const
Accessor for the Compass Heading private member.
Definition GeospatialOperations.hpp:787
const geoops::UTMCoordinate & GetUTMCoordinate() const
Accessor for the geoops::UTMCoordinate member variable.
Definition GeospatialOperations.hpp:767
const geoops::UTMCoordinate & GetUTMCoordinate() const
Accessor for the geoops::UTMCoordinate member variable.
Definition GeospatialOperations.hpp:508
Represents a single ArUco tag.
Definition TagDetectionUtilty.hpp:57
Here is the call graph for this function:

◆ TriggerEvent()

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

413 {
414 // Create instance variables.
415 States eNextState = States::eApproachingMarker;
416 bool bCompleteStateExit = true;
417
418 switch (eEvent)
419 {
420 case Event::eReachedMarker:
421 {
422 // Submit logger message.
423 LOG_INFO(logging::g_qSharedLogger, "ApproachingMarkerState: Handling ReachedMarker event.");
424
425 if (constants::APPROACH_MARKER_VERIFY_POSITION)
426 {
427 eNextState = States::eVerifyingMarker;
428 }
429 else
430 {
431 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eReachedGoal);
432 globals::g_pWaypointHandler->PopNextWaypoint();
433 globals::g_pStateMachineHandler->ClearSavedStates();
434 LOG_NOTICE(logging::g_qSharedLogger, "ApproachingMarkerState: Cleared old search pattern state and approaching marker state from saved states.");
435 eNextState = States::eIdle;
436 }
437 break;
438 }
439 case Event::eStart:
440 {
441 // Submit logger message.
442 LOG_INFO(logging::g_qSharedLogger, "ApproachingMarkerState: Handling Start event.");
443 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
444 break;
445 }
446 case Event::eMarkerUnseen:
447 {
448 // Submit logger message.
449 LOG_INFO(logging::g_qSharedLogger, "ApproachingMarkerState: Handling MarkerUnseen event.");
450 // Change states.
451 eNextState = m_eTriggeringState;
452 break;
453 }
454 case Event::eAbort:
455 {
456 // Submit logger message.
457 LOG_INFO(logging::g_qSharedLogger, "ApproachingMarkerState: Handling Abort event.");
458 // Send multimedia command to update state display.
459 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eOff);
460 // Change state.
461 eNextState = States::eIdle;
462 break;
463 }
464 default:
465 {
466 LOG_WARNING(logging::g_qSharedLogger, "ApproachingMarkerState: Handling unknown event ({}), defaulting to Idle.", static_cast<int>(eEvent));
467 eNextState = States::eIdle;
468 break;
469 }
470 }
471
472 if (eNextState != States::eApproachingMarker)
473 {
474 LOG_INFO(logging::g_qSharedLogger, "ApproachingMarkerState: Transitioning to {} State.", StateToString(eNextState));
475
476 // Exit the current state.
477 if (bCompleteStateExit)
478 {
479 Exit();
480 }
481 }
482
483 return eNextState;
484 }
void SendLightingState(MultimediaBoardLightingState eState)
Sends a predetermined color pattern to board.
Definition MultimediaBoard.cpp:55
void ClearSavedStates()
Clear all saved states.
Definition StateMachineHandler.cpp:311
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 ApproachingMarkerState.cpp:77
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: