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::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 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::Waypoint > m_vSearchPath
 
int m_nSearchPathIdx
 
SearchPatternType m_eCurrentSearchPatternType
 
statemachine::TimeIntervalBasedStuckDetector m_StuckDetector
 
std::unique_ptr< controllers::PurePursuitController > m_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
170 : State(States::eSearchPattern)
171 {
172 // Submit logger message.
173 LOG_INFO(logging::g_qConsoleLogger, "Entering State: {}", ToString());
174
175 // Initialize member variables.
176 m_bInitialized = false;
177 m_StuckDetector = statemachine::TimeIntervalBasedStuckDetector(constants::SEARCH_STUCK_CHECK_ATTEMPTS, constants::SEARCH_STUCK_CHECK_INTERVAL);
178 m_pPursuitController = std::make_unique<controllers::PurePursuitController>();
179
180 // Start state.
181 if (!m_bInitialized)
182 {
183 Start();
184 m_bInitialized = true;
185 }
186 }
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 std::vector<geoops::Waypoint> vSpiralPath = searchpattern::CalculateSpiralPatternWaypoints(m_stSearchPatternCenter.GetGPSCoordinate(),
51 constants::SEARCH_ANGULAR_STEP_DEGREES,
52 m_stSearchPatternCenter.dRadius,
53 stCurrentRoverPose.GetCompassHeading(),
54 constants::SEARCH_SPIRAL_SPACING);
55 RemoveRedZonePoints(vSpiralPath);
56 std::vector<geoops::Waypoint> vGeoPlannedPath = GeoPlanSearchPattern(vSpiralPath);
57
58 // Split the path into two halves for forward and reverse navigation.
59 std::vector<geoops::Waypoint> vFirstHalf;
60 std::vector<geoops::Waypoint> vSecondHalf;
61 if (vGeoPlannedPath.size() >= 4)
62 {
63 vFirstHalf = std::vector<geoops::Waypoint>(vGeoPlannedPath.begin(), vGeoPlannedPath.begin() + vGeoPlannedPath.size() / 2);
64 vSecondHalf = std::vector<geoops::Waypoint>(vGeoPlannedPath.begin() + vGeoPlannedPath.size() / 2, vGeoPlannedPath.end());
65 }
66 else if (vGeoPlannedPath.size() >= 2)
67 {
68 vFirstHalf = vGeoPlannedPath;
69 }
70
71 // Plot the search path in the visualizer.
72 globals::g_pWaypointHandler->StorePath("GeoPlannerPath", vFirstHalf);
73 globals::g_pWaypointHandler->StorePath("GeoPlannerPathReverse", vSecondHalf);
74 m_vSearchPath = std::move(vFirstHalf);
75
76 // Set the path of the pure pursuit controller.
77 m_pPursuitController->SetReferencePath(m_vSearchPath);
78 m_pPursuitController->SetLookaheadIndex(5);
79
80 m_vTagDetectors = {globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eHeadMainCam),
81 globals::g_pTagDetectionHandler->GetTagDetector(TagDetectionHandler::TagDetectors::eRearCam)};
82 m_vObjectDetectors = {globals::g_pObjectDetectionHandler->GetObjectDetector(ObjectDetectionHandler::ObjectDetectors::eHeadMainCam),
83 globals::g_pObjectDetectionHandler->GetObjectDetector(ObjectDetectionHandler::ObjectDetectors::eRearCam)};
84 }
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:111
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:146
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.

95 {
96 // Clean up the state before exiting
97 LOG_INFO(logging::g_qSharedLogger, "SearchPatternState: Exiting state.");
98
99 // Stop drive.
100 globals::g_pDriveBoard->SendStop();
101 }
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
147 {
148 std::vector<geoops::Waypoint> vPlannedPath;
149 if (vSkeletonPath.size() < 2)
150 {
151 return vPlannedPath;
152 }
153 for (long unsigned int nI = 0; nI < vSkeletonPath.size() - 1; nI++)
154 {
155 std::vector<geoops::Waypoint> vNewPoints =
156 globals::g_pGeoPlanner->PlanPath(globals::g_pLiDARHandler, vSkeletonPath[nI].GetUTMCoordinate(), vSkeletonPath[nI + 1].GetUTMCoordinate());
157 vPlannedPath.insert(vPlannedPath.end(), vNewPoints.begin(), vNewPoints.end());
158 }
159
160 return vPlannedPath;
161 }
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
112 {
113 for (long unsigned int i = 0; i < vSkeletonPath.size();)
114 {
115 int nTileX = static_cast<int>(std::floor(vSkeletonPath[i].GetUTMCoordinate().dEasting / 5.0));
116 int nTileY = static_cast<int>(std::floor(vSkeletonPath[i].GetUTMCoordinate().dNorthing / 5.0));
118 stFilter.dEasting = (nTileX + 0.5) * 5.0; // Center of the tile in easting.
119 stFilter.dNorthing = (nTileY + 0.5) * 5.0; // Center of the tile in northing.
120 stFilter.dRadius = std::sqrt(2) * (5.0 / 2.0); // Radius to cover the entire tile
121 stFilter.dTraversalScore = LiDARHandler::PointFilter::Range<double>{0.5, 1.0}; // Only load points with sufficient traversal
122
123 std::vector<LiDARHandler::PointRow> vLidarData = globals::g_pLiDARHandler->GetLiDARData(stFilter);
124
125 if (vLidarData.empty())
126 {
127 vSkeletonPath.erase(vSkeletonPath.begin() + static_cast<long int>(i));
128 }
129 else
130 {
131 ++i;
132 }
133 }
134 }
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.

195 {
196 // Submit logger message.
197 LOG_DEBUG(logging::g_qSharedLogger, "SearchPatternState: Running state-specific behavior.");
198
199 // If search was previously stuck, then re-path plan stuck area
200 if (m_bWasStuck)
201 {
202 // Retrieve modified path from stuck.
203 m_vSearchPath = globals::g_pWaypointHandler->RetrievePath("GeoPlannerPath");
204
205 // Update visualizer and pure pursuit
206 m_pPursuitController->SetReferencePath(m_vSearchPath);
207
208 m_bWasStuck = false;
209 }
210
211 // Get the current rover pose.
212 geoops::RoverPose stCurrentRoverPose = globals::g_pStateMachineHandler->SmartRetrieveRoverPose();
213
214 /*
215 The overall flow of this state is as follows.
216 1. Is there a tag -> MarkerSeen
217 2. Is there an object -> ObjectSeen
218 3. Is there an obstacle -> TBD
219 4. Is the rover stuck -> Stuck
220 5. Is the search pattern complete -> Abort
221 6. Follow the search pattern.
222 */
223
225 /* --- Detect Tags --- */
227
228 // 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.
229 if (m_stSearchPatternCenter.eType == geoops::WaypointType::eTagWaypoint)
230 {
231 // Create instance variables.
232 tagdetectutils::ArucoTag stBestArucoTag, stBestTorchTag;
233 // Identify target marker.
234 statemachine::IdentifyTargetMarker(m_vTagDetectors, stBestArucoTag, stBestTorchTag, m_stSearchPatternCenter.nID);
235 // Check if either tag type is seen.
236 if (stBestArucoTag.nID != -1 || stBestTorchTag.dConfidence != 0.0)
237 {
238 // Submit logger message.
239 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target marker!");
240
241 // Handle state transition and save the current search pattern state.
242 globals::g_pStateMachineHandler->HandleEvent(Event::eMarkerSeen, true);
243 // Don't execute the rest of the state.
244 return;
245 }
246 }
247
249 /* --- Detect Objects --- */
251
252 // 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
253 // waypoint.
254 if (m_stSearchPatternCenter.eType == geoops::WaypointType::eObjectWaypoint || m_stSearchPatternCenter.eType == geoops::WaypointType::eMalletWaypoint ||
255 m_stSearchPatternCenter.eType == geoops::WaypointType::eWaterBottleWaypoint || m_stSearchPatternCenter.eType == geoops::WaypointType::eRockPickWaypoint)
256 {
257 // Create instance variables.
258 objectdetectutils::Object stBestTorchObject;
259 // Identify target object.
260 statemachine::IdentifyTargetObject(m_vObjectDetectors, stBestTorchObject, m_stSearchPatternCenter.eType);
261 // Check if either tag type is seen.
262 if (stBestTorchObject.dConfidence != 0.0)
263 {
264 // Submit logger message.
265 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target object!");
266
267 // Handle state transition and save the current search pattern state.
268 globals::g_pStateMachineHandler->HandleEvent(Event::eObjectSeen, true);
269 // Don't execute the rest of the state.
270 return;
271 }
272 }
273
275 /* --- Detect Obstacles --- */
277
278 // TODO: Add obstacle detection to SearchPattern state
279
281 /* --- Check if the rover is stuck --- */
283
284 // Check if stuck.
285 if (constants::SEARCH_ENABLE_STUCK_DETECT && m_StuckDetector.CheckIfStuck(globals::g_pStateMachineHandler->SmartRetrieveVelocity(),
286 globals::g_pStateMachineHandler->SmartRetrieveAngularVelocity(),
287 constants::SEARCH_STUCK_CHECK_VEL_THRESH * globals::g_pDriveBoard->GetMaxDriveEffort(),
288 constants::SEARCH_STUCK_CHECK_ROT_THRESH))
289 {
290 // Submit logger message.
291 LOG_WARNING(logging::g_qSharedLogger, "SearchPattern: Rover has become stuck!");
292 m_bWasStuck = true;
293 // Handle state transition and save the current search pattern state.
294 globals::g_pStateMachineHandler->HandleEvent(Event::eStuck, true);
295 // Don't execute the rest of the state.
296 return;
297 }
298
300 /* --- Follow Search Pattern --- */
302
303 // Check if the search path has enough points to navigate.
304 if (m_vSearchPath.size() < 2)
305 {
306 // Submit logger message.
307 LOG_WARNING(logging::g_qSharedLogger, "SearchPatternState: Search path has fewer than 2 points, aborting search.");
308 // Handle state transition.
309 globals::g_pStateMachineHandler->HandleEvent(Event::eAbort);
310 return;
311 }
312
313 // Have we reached the final waypoint of the search pattern?
314 geoops::GPSCoordinate stFinalTargetGPS = m_vSearchPath.back().GetGPSCoordinate();
315 geoops::GeoMeasurement stRelToFinalTarget = geoops::CalculateGeoMeasurement(stCurrentRoverPose.GetGPSCoordinate(), stFinalTargetGPS);
316 double dCompletionRadius = constants::SEARCH_WAYPOINT_PROXIMITY;
317 bool bReachedFinalTarget = stRelToFinalTarget.dDistanceMeters <= dCompletionRadius;
318
319 // If the entire search pattern has been completed without seeing tags or objects, try different search pattern.
320 if (bReachedFinalTarget && m_pPursuitController->GetReferencePathTargetIndex() > static_cast<int>(m_vSearchPath.size()) - 4)
321 {
322 globals::g_pStateMachineHandler->HandleEvent(Event::eSearchFailed);
323 return;
324 }
325
326 // NOTE: Optional - Uncomment the above code and comment out the below code to use pure pursuit control to navigate to the goal waypoint.
327 // Use pure pursuit to calculate drive move/powers.
328 controllers::PurePursuitController::DriveVector stDriveVector = m_pPursuitController->Calculate(stCurrentRoverPose, constants::SEARCH_MOTOR_POWER);
329 // Calculate move from goal heading and desired speed.
330 diffdrive::DrivePowers stDriveSpeeds = globals::g_pDriveBoard->CalculateMove(stDriveVector.dVelocity,
331 stDriveVector.dThetaHeading,
332 stCurrentRoverPose.GetCompassHeading(),
333 diffdrive::DifferentialControlMethod::eArcadeDrive);
334 // Send drive powers over RoveComm.
335 globals::g_pDriveBoard->SendDrive(stDriveSpeeds);
336
337 return;
338 }
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.

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