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

The SearchPatternState class implements the Search Pattern state for the Autonomy State Machine. More...

#include <SearchPatternState.h>

Inheritance diagram for statemachine::SearchPatternState:
Collaboration diagram for statemachine::SearchPatternState:

Public Member Functions

std::vector< geoops::WaypointGeoPlanSearchPattern (const std::vector< geoops::Waypoint > &skeltonPath)
 This method takes in a skeleton path of waypoints and uses the GeoPlanner to create a new path that weaves through the skeleton path while avoiding obstacles.
 
void RemoveRedZonePoints (std::vector< geoops::Waypoint > &skeltonPath)
 This method takes in a skeleton path of waypoints and removes any waypoints that are in red zones (obstacles) based on LiDAR data.
 
 SearchPatternState ()
 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 Types

enum class  SearchPatternType { eSpiral , eSnake , eZigZag , END }
 

Private Attributes

bool m_bWasStuck
 
bool m_bInitialized
 
geoops::Waypoint m_stSearchPatternCenter
 
std::vector< std::shared_ptr< TagDetector > > m_vTagDetectors
 
std::vector< std::shared_ptr< ObjectDetector > > m_vObjectDetectors
 
std::vector< geoops::Waypointm_vSearchPath
 
int m_nSearchPathIdx
 
SearchPatternType m_eCurrentSearchPatternType
 
statemachine::TimeIntervalBasedStuckDetector m_StuckDetector
 
std::unique_ptr< controllers::PurePursuitControllerm_pPursuitController
 

Detailed Description

The SearchPatternState class implements the Search Pattern state for the Autonomy State Machine.

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

Member Enumeration Documentation

◆ SearchPatternType

enum class statemachine::SearchPatternState::SearchPatternType
strongprivate
50 {
51 eSpiral,
52 eSnake,
53 eZigZag,
54 END
55 };

Constructor & Destructor Documentation

◆ SearchPatternState()

statemachine::SearchPatternState::SearchPatternState ( )

Construct a new State object.

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
152 : State(States::eSearchPattern)
153 {
154 // Submit logger message.
155 LOG_INFO(logging::g_qConsoleLogger, "Entering State: {}", ToString());
156
157 // Initialize member variables.
158 m_bInitialized = false;
159 m_StuckDetector = statemachine::TimeIntervalBasedStuckDetector(constants::SEARCH_STUCK_CHECK_ATTEMPTS, constants::SEARCH_STUCK_CHECK_INTERVAL);
160 m_pPursuitController = std::make_unique<controllers::PurePursuitController>();
161
162 // Start state.
163 if (!m_bInitialized)
164 {
165 Start();
166 m_bInitialized = true;
167 }
168 }
void Start() override
This method is called when the state is first started. It is used to initialize the state.
Definition SearchPatternState.cpp:35
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::SearchPatternState::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.

36 {
37 // Schedule the next run of the state's logic
38 LOG_INFO(logging::g_qSharedLogger, "SearchPatternState: Scheduling next run of state logic.");
39
40 // Initialize member variables.
41 m_bWasStuck = false;
42 m_eCurrentSearchPatternType = SearchPatternType::eSpiral;
43 m_nSearchPathIdx = 0;
44 m_stSearchPatternCenter = globals::g_pWaypointHandler->PeekNextWaypoint();
45
46 // Get the current rover pose.
47 geoops::RoverPose stCurrentRoverPose = globals::g_pStateMachineHandler->SmartRetrieveRoverPose();
48
49 // Calculate the search path.
50 m_vSearchPath = searchpattern::CalculateSpiralPatternWaypoints(m_stSearchPatternCenter.GetGPSCoordinate(),
51 constants::SEARCH_ANGULAR_STEP_DEGREES,
52 m_stSearchPatternCenter.dRadius,
53 // m_stSearchPatternCenter.dRadius,
54 stCurrentRoverPose.GetCompassHeading(),
55 constants::SEARCH_SPIRAL_SPACING);
56 RemoveRedZonePoints(m_vSearchPath);
57 m_vSearchPath = GeoPlanSearchPattern(m_vSearchPath);
58
59 // Plot the search path in the visualizer.
60 globals::g_pWaypointHandler->StorePath("GeoPlannerPath", m_vSearchPath);
61
62 // Set the path of the pure pursuit controller.
63 m_pPursuitController->SetReferencePath(m_vSearchPath);
64 m_pPursuitController->SetLookaheadIndex(5);
65
66 m_vTagDetectors = {globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eHeadMainCam),
67 globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eRearCam)};
68 m_vObjectDetectors = {globals::g_pObjectDetectionHandler->GetObjectDetector(ObjectDetectionHandler::ObjectDetectors::eHeadMainCam),
69 globals::g_pObjectDetectionHandler->GetObjectDetector(ObjectDetectionHandler::ObjectDetectors::eRearCam)};
70 }
std::shared_ptr< ObjectDetector > GetObjectDetector(ObjectDetectors eDetectorName)
Accessor for ObjectDetector detectors.
Definition ObjectDetectionHandler.cpp:153
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
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
void StorePath(const std::string &szPathName, const std::vector< geoops::Waypoint > &vWaypointPath)
Store a path in the WaypointHandler.
Definition WaypointHandler.cpp:120
void RemoveRedZonePoints(std::vector< geoops::Waypoint > &skeltonPath)
This method takes in a skeleton path of waypoints and removes any waypoints that are in red zones (ob...
Definition SearchPatternState.cpp:97
std::vector< geoops::Waypoint > GeoPlanSearchPattern(const std::vector< geoops::Waypoint > &skeltonPath)
This method takes in a skeleton path of waypoints and uses the GeoPlanner to create a new path that w...
Definition SearchPatternState.cpp:132
std::vector< geoops::Waypoint > CalculateSpiralPatternWaypoints(const geoops::Waypoint &stStartingPoint, const double dAngularStepDegrees=57, const double dMaxRadius=25, const double dStartingHeadingDegrees=0, const double dStartSpacing=1)
Perform a spiral search pattern starting from a given point.
Definition SearchPattern.hpp:49
This struct is used by the WaypointHandler to provide an easy way to store all pose data about the ro...
Definition GeospatialOperations.hpp:708
double GetCompassHeading() const
Accessor for the Compass Heading private member.
Definition GeospatialOperations.hpp:787
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::SearchPatternState::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.

81 {
82 // Clean up the state before exiting
83 LOG_INFO(logging::g_qSharedLogger, "SearchPatternState: Exiting state.");
84
85 // Stop drive.
86 globals::g_pDriveBoard->SendStop();
87 }
void SendStop()
Stop the drivetrain of the Rover.
Definition DriveBoard.cpp:246
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GeoPlanSearchPattern()

std::vector< geoops::Waypoint > statemachine::SearchPatternState::GeoPlanSearchPattern ( const std::vector< geoops::Waypoint > &  vSkeletonPath)

This method takes in a skeleton path of waypoints and uses the GeoPlanner to create a new path that weaves through the skeleton path while avoiding obstacles.

Parameters
vSkeletonPath- The input skeleton path of waypoints that the search pattern should weave through.
Returns
std::vector<geoops::Waypoint> - The new path generated by the GeoPlanner that weaves through the skeleton path while avoiding obstacles.
Author
Hunter LeRette (hrlnp.nosp@m.c@ms.nosp@m.t.edu), Jordan Hoover (jh69n.nosp@m.@mst.nosp@m..edu), Aiden Buter (ab9hm.nosp@m.@mst.nosp@m..edu)
Date
2026-05-17
133 {
134 std::vector<geoops::Waypoint> m_vSearchPath;
135 for (long unsigned int nI = 0; nI < vSkeletonPath.size() - 1; nI++)
136 {
137 std::vector<geoops::Waypoint> vNewPoints =
138 globals::g_pGeoPlanner->PlanPath(globals::g_pLiDARHandler, vSkeletonPath[nI].GetUTMCoordinate(), vSkeletonPath[nI + 1].GetUTMCoordinate());
139 m_vSearchPath.insert(m_vSearchPath.end(), vNewPoints.begin(), vNewPoints.end());
140 }
141
142 return m_vSearchPath;
143 }
std::vector< geoops::Waypoint > PlanPath(LiDARHandler *pLiDARHandler, const geoops::UTMCoordinate &stStart, const geoops::UTMCoordinate &stEnd, double dSearchRadius=3.0, double dMaxSearchTimeSeconds=120.0, double dCorridorPadding=100.0)
Plan an optimal trajectory path from the start UTM to the end UTM coordinate utilizing a 2....
Definition GeoPlanner.cpp:116
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveRedZonePoints()

void statemachine::SearchPatternState::RemoveRedZonePoints ( std::vector< geoops::Waypoint > &  vSkeletonPath)

This method takes in a skeleton path of waypoints and removes any waypoints that are in red zones (obstacles) based on LiDAR data.

Parameters
vSkeletonPath- The input skeleton path of waypoints that the search pattern should weave through.
Author
Hunter LeRette (hrlnp.nosp@m.c@ms.nosp@m.t.edu), Jordan Hoover (jh69n.nosp@m.@mst.nosp@m..edu), Aiden Buter (ab9hm.nosp@m.@mst.nosp@m..edu)
Date
2026-05-17
98 {
99 for (long unsigned int i = 0; i < vSkeletonPath.size();)
100 {
101 int nTileX = static_cast<int>(std::floor(vSkeletonPath[i].GetUTMCoordinate().dEasting / 5.0));
102 int nTileY = static_cast<int>(std::floor(vSkeletonPath[i].GetUTMCoordinate().dNorthing / 5.0));
104 stFilter.dEasting = (nTileX + 0.5) * 5.0; // Center of the tile in easting.
105 stFilter.dNorthing = (nTileY + 0.5) * 5.0; // Center of the tile in northing.
106 stFilter.dRadius = std::sqrt(2) * (5.0 / 2.0); // Radius to cover the entire tile
107 stFilter.dTraversalScore = LiDARHandler::PointFilter::Range<double>{0.5, 1.0}; // Only load points with sufficient traversal
108
109 std::vector<LiDARHandler::PointRow> vLidarData = globals::g_pLiDARHandler->GetLiDARData(stFilter);
110
111 if (vLidarData.empty())
112 {
113 vSkeletonPath.erase(vSkeletonPath.begin() + static_cast<long int>(i));
114 }
115 else
116 {
117 ++i;
118 }
119 }
120 }
std::vector< PointRow > GetLiDARData(const PointFilter &stPointFilter)
Retrieves LiDAR data points from DuckDB based on the specified filter.
Definition LiDARHandler.cpp:136
Definition LiDARHandler.h:89
Struct for filtering LiDAR points during queries.
Definition LiDARHandler.h:79
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Run()

void statemachine::SearchPatternState::Run ( )
overridevirtual

Run the state machine. Returns the next state.

Author
Jason Pittman (jspen.nosp@m.cerp.nosp@m.ittma.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-01-17

Implements statemachine::State.

177 {
178 // Submit logger message.
179 LOG_DEBUG(logging::g_qSharedLogger, "SearchPatternState: Running state-specific behavior.");
180
181 // If search was previously stuck, then re-path plan stuck area
182 if (m_bWasStuck)
183 {
184 // Retrieve modified path from stuck. If in the first spiral, grab the reverse spiral so that the path isn't incomplete
185 m_vSearchPath =
186 (m_nSearchPathIdx == 0) ? globals::g_pWaypointHandler->RetrievePath("RevSpiralPath") : globals::g_pWaypointHandler->RetrievePath("unstuckPath");
187 // Culled Spiral path
188 std::vector<geoops::Waypoint> vRemainderOfSpiralPath = globals::g_pWaypointHandler->RetrievePath("unstuckPath");
189
190 // Update visualizer and pure pursuit
191 globals::g_pWaypointHandler->StorePath("GeoPlannerPath", vRemainderOfSpiralPath);
192 m_pPursuitController->SetReferencePath(vRemainderOfSpiralPath);
193
194 m_bWasStuck = false;
195 }
196
197 // Get the current rover pose.
198 geoops::RoverPose stCurrentRoverPose = globals::g_pStateMachineHandler->SmartRetrieveRoverPose();
199
200 /*
201 The overall flow of this state is as follows.
202 1. Is there a tag -> MarkerSeen
203 2. Is there an object -> ObjectSeen
204 3. Is there an obstacle -> TBD
205 4. Is the rover stuck -> Stuck
206 5. Is the search pattern complete -> Abort
207 6. Follow the search pattern.
208 */
209
211 /* --- Detect Tags --- */
213
214 // In order to even care about any tags we see, the goal waypoint needs to be of type MARKER and we need to be within the search radius of the MARKER waypoint.
215 if (m_stSearchPatternCenter.eType == geoops::WaypointType::eTagWaypoint)
216 {
217 // Create instance variables.
218 tagdetectutils::ArucoTag stBestArucoTag, stBestTorchTag;
219 // Identify target marker.
220 statemachine::IdentifyTargetMarker(m_vTagDetectors, stBestArucoTag, stBestTorchTag, m_stSearchPatternCenter.nID);
221 // Check if either tag type is seen.
222 if (stBestArucoTag.nID != -1 || stBestTorchTag.dConfidence != 0.0)
223 {
224 // Submit logger message.
225 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target marker!");
226
227 // Handle state transition and save the current search pattern state.
228 globals::g_pStateMachineHandler->HandleEvent(Event::eMarkerSeen, true);
229 // Don't execute the rest of the state.
230 return;
231 }
232 }
233
235 /* --- Detect Objects --- */
237
238 // In order to even care about any objects we see, the goal waypoint needs to be of an object type and we need to be within the search radius of the object
239 // waypoint.
240 if (m_stSearchPatternCenter.eType == geoops::WaypointType::eObjectWaypoint || m_stSearchPatternCenter.eType == geoops::WaypointType::eMalletWaypoint ||
241 m_stSearchPatternCenter.eType == geoops::WaypointType::eWaterBottleWaypoint || m_stSearchPatternCenter.eType == geoops::WaypointType::eRockPickWaypoint)
242 {
243 // Create instance variables.
244 objectdetectutils::Object stBestTorchObject;
245 // Identify target object.
246 statemachine::IdentifyTargetObject(m_vObjectDetectors, stBestTorchObject, m_stSearchPatternCenter.eType);
247 // Check if either tag type is seen.
248 if (stBestTorchObject.dConfidence != 0.0)
249 {
250 // Submit logger message.
251 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target object!");
252
253 // Handle state transition and save the current search pattern state.
254 globals::g_pStateMachineHandler->HandleEvent(Event::eObjectSeen, true);
255 // Don't execute the rest of the state.
256 return;
257 }
258 }
259
261 /* --- Detect Obstacles --- */
263
264 // TODO: Add obstacle detection to SearchPattern state
265
267 /* --- Check if the rover is stuck --- */
269
270 // Check if stuck.
271 if (constants::SEARCH_ENABLE_STUCK_DETECT && m_StuckDetector.CheckIfStuck(globals::g_pStateMachineHandler->SmartRetrieveVelocity(),
272 globals::g_pStateMachineHandler->SmartRetrieveAngularVelocity(),
273 constants::SEARCH_STUCK_CHECK_VEL_THRESH * globals::g_pDriveBoard->GetMaxDriveEffort(),
274 constants::SEARCH_STUCK_CHECK_ROT_THRESH))
275 {
276 // Submit logger message.
277 LOG_WARNING(logging::g_qSharedLogger, "SearchPattern: Rover has become stuck!");
278 // Save rover path for modification in stuck state
279 globals::g_pWaypointHandler->StorePath("stuckPath", m_vSearchPath);
280 m_bWasStuck = true;
281 // Handle state transition and save the current search pattern state.
282 globals::g_pStateMachineHandler->HandleEvent(Event::eStuck, true);
283 // Don't execute the rest of the state.
284 return;
285 }
286
288 /* --- Follow Search Pattern --- */
290
291 // Check if the search path is empty.
292 if (m_vSearchPath.empty())
293 {
294 // Submit logger message.
295 LOG_WARNING(logging::g_qSharedLogger, "SearchPatternState: Search path is empty, aborting search.");
296 // Handle state transition.
297 globals::g_pStateMachineHandler->HandleEvent(Event::eAbort);
298 return;
299 }
300
301 // Have we reached the final waypoint of the search pattern?
302 geoops::GPSCoordinate stFinalTargetGPS = m_vSearchPath.back().GetGPSCoordinate();
303 geoops::GeoMeasurement stRelToFinalTarget = geoops::CalculateGeoMeasurement(stCurrentRoverPose.GetGPSCoordinate(), stFinalTargetGPS);
304 double dCompletionRadius = constants::SEARCH_WAYPOINT_PROXIMITY;
305 bool bReachedFinalTarget = stRelToFinalTarget.dDistanceMeters <= dCompletionRadius;
306
307 // If the entire search pattern has been completed without seeing tags or objects, try different search pattern.
308 if (bReachedFinalTarget)
309 {
310 globals::g_pStateMachineHandler->HandleEvent(Event::eSearchFailed);
311 return;
312 }
313
314 // NOTE: Optional - Uncomment the above code and comment out the below code to use pure pursuit control to navigate to the goal waypoint.
315 // Use pure pursuit to calculate drive move/powers.
316 controllers::PurePursuitController::DriveVector stDriveVector = m_pPursuitController->Calculate(stCurrentRoverPose, constants::SEARCH_MOTOR_POWER);
317 // Calculate move from goal heading and desired speed.
318 diffdrive::DrivePowers stDriveSpeeds = globals::g_pDriveBoard->CalculateMove(stDriveVector.dVelocity,
319 stDriveVector.dThetaHeading,
320 stCurrentRoverPose.GetCompassHeading(),
321 diffdrive::DifferentialControlMethod::eArcadeDrive);
322 // Send drive powers over RoveComm.
323 globals::g_pDriveBoard->SendDrive(stDriveSpeeds);
324
325 return;
326 }
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 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
const std::vector< geoops::Waypoint > RetrievePath(const std::string &szPathName)
Retrieve an immutable reference to the path at the given path name/key.
Definition WaypointHandler.cpp:600
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
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
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:101
The struct for the drive vector that includes heading and velocity.
Definition PurePursuitController.h:55
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 stores/contains information about a GPS data.
Definition GeospatialOperations.hpp:100
This struct is used to store the distance, arc length, and relative bearing for a calculated geodesic...
Definition GeospatialOperations.hpp:83
const geoops::GPSCoordinate & GetGPSCoordinate() const
Accessor for the geoops::GPSCoordinate member variable.
Definition GeospatialOperations.hpp:756
Represents a single detected object.
Definition ObjectDetectionUtility.hpp:73
Represents a single ArUco tag.
Definition TagDetectionUtilty.hpp:57
Here is the call graph for this function:

◆ TriggerEvent()

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

338 {
339 // Create instance variables.
340 States eNextState = States::eSearchPattern;
341 bool bCompleteStateExit = true;
342
343 switch (eEvent)
344 {
345 case Event::eMarkerSeen:
346 {
347 // Submit logger message.
348 LOG_INFO(logging::g_qSharedLogger, "SearchPatternState: Handling MarkerSeen event.");
349 // Change states.
350 eNextState = States::eApproachingMarker;
351 break;
352 }
353 case Event::eObjectSeen:
354 {
355 // Submit logger message.
356 LOG_INFO(logging::g_qSharedLogger, "SearchPatternState: Handling ObjectSeen event.");
357 // Change state.
358 eNextState = States::eApproachingObject;
359 break;
360 }
361 case Event::eStart:
362 {
363 // Submit logger message
364 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Handling Start event.");
365 // Send multimedia command to update state display.
366 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eAutonomy);
367 break;
368 }
369 case Event::eSearchFailed:
370 {
371 // Submit logger message.
372 LOG_INFO(logging::g_qSharedLogger, "SearchPatternState: Handling SearchFailed event.");
373 // Stop drive.
374 globals::g_pDriveBoard->SendStop();
375
376 // Regenerate a new search pattern.
377 switch (m_eCurrentSearchPatternType)
378 {
379 // Check which pattern to do next.
380 case SearchPatternType::eSpiral:
381 {
382 // Submit logger message.
383 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Spiral search pattern failed, trying reverse spiral...");
384
385 // Reset index counter.
386 m_nSearchPathIdx = 0;
387 // Update current search pattern
388 m_eCurrentSearchPatternType = SearchPatternType::END;
389
390 // Reverse the previous path.
391 std::reverse(m_vSearchPath.begin(), m_vSearchPath.end());
392
393 // Plot the search path in the visualizer.
394 globals::g_pWaypointHandler->StorePath("GeoPlannerPath", m_vSearchPath);
395 // Set the path of the pure pursuit controller.
396 m_pPursuitController->SetReferencePath(m_vSearchPath);
397 break;
398 }
399 case SearchPatternType::END:
400 {
401 // Submit logger message.
402 LOG_WARNING(logging::g_qSharedLogger, "SearchPatternState: All patterns failed to find anything, giving up...");
403 // Pop old waypoint out of queue.
404 globals::g_pWaypointHandler->PopNextWaypoint();
405 // Change states.
406 eNextState = States::eIdle;
407 break;
408 }
409 default:
410 {
411 // Change states.
412 eNextState = States::eIdle;
413 break;
414 }
415 }
416 break;
417 }
418 case Event::eAbort:
419 {
420 // Submit logger message.
421 LOG_INFO(logging::g_qSharedLogger, "SearchPatternState: Handling Abort event.");
422 // Send multimedia command to update state display.
423 globals::g_pMultimediaBoard->SendLightingState(MultimediaBoard::MultimediaBoardLightingState::eOff);
424 // Stop drive.
425 globals::g_pDriveBoard->SendStop();
426 // Change state.
427 eNextState = States::eIdle;
428 break;
429 }
430 case Event::eStuck:
431 {
432 LOG_INFO(logging::g_qSharedLogger, "SearchPatternState: Handling Stuck event.");
433 eNextState = States::eStuck;
434 break;
435 }
436 default:
437 {
438 LOG_WARNING(logging::g_qSharedLogger, "SearchPatternState: Handling unknown event.");
439 eNextState = States::eIdle;
440 break;
441 }
442 }
443
444 if (eNextState != States::eSearchPattern)
445 {
446 LOG_INFO(logging::g_qSharedLogger, "SearchPatternState: Transitioning to {} State.", StateToString(eNextState));
447
448 // Exit the current state
449 if (bCompleteStateExit)
450 {
451 Exit();
452 }
453 }
454
455 return eNextState;
456 }
void SendLightingState(MultimediaBoardLightingState eState)
Sends a predetermined color pattern to board.
Definition MultimediaBoard.cpp:55
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 SearchPatternState.cpp:80
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: