Run the state machine. Returns the next state.
195 {
196
197 LOG_DEBUG(logging::g_qSharedLogger, "SearchPatternState: Running state-specific behavior.");
198
199
200 if (m_bWasStuck)
201 {
202
203 m_vSearchPath = globals::g_pWaypointHandler->
RetrievePath(
"GeoPlannerPath");
204
205
206 m_pPursuitController->SetReferencePath(m_vSearchPath);
207
208 m_bWasStuck = false;
209 }
210
211
213
214
215
216
217
218
219
220
221
222
223
225
227
228
229 if (m_stSearchPatternCenter.eType == geoops::WaypointType::eTagWaypoint)
230 {
231
233
235
236 if (stBestArucoTag.nID != -1 || stBestTorchTag.dConfidence != 0.0)
237 {
238
239 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target marker!");
240
241
242 globals::g_pStateMachineHandler->
HandleEvent(Event::eMarkerSeen,
true);
243
244 return;
245 }
246 }
247
249
251
252
253
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
259
261
262 if (stBestTorchObject.dConfidence != 0.0)
263 {
264
265 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target object!");
266
267
268 globals::g_pStateMachineHandler->
HandleEvent(Event::eObjectSeen,
true);
269
270 return;
271 }
272 }
273
275
277
278
279
281
283
284
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
291 LOG_WARNING(logging::g_qSharedLogger, "SearchPattern: Rover has become stuck!");
292 m_bWasStuck = true;
293
294 globals::g_pStateMachineHandler->
HandleEvent(Event::eStuck,
true);
295
296 return;
297 }
298
300
302
303
304 if (m_vSearchPath.size() < 2)
305 {
306
307 LOG_WARNING(logging::g_qSharedLogger, "SearchPatternState: Search path has fewer than 2 points, aborting search.");
308
309 globals::g_pStateMachineHandler->
HandleEvent(Event::eAbort);
310 return;
311 }
312
313
316 double dCompletionRadius = constants::SEARCH_WAYPOINT_PROXIMITY;
317 bool bReachedFinalTarget = stRelToFinalTarget.dDistanceMeters <= dCompletionRadius;
318
319
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
327
329
331 stDriveVector.dThetaHeading,
333 diffdrive::DifferentialControlMethod::eArcadeDrive);
334
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