Run the state machine. Returns the next state.
177 {
178
179 LOG_DEBUG(logging::g_qSharedLogger, "SearchPatternState: Running state-specific behavior.");
180
181
182 if (m_bWasStuck)
183 {
184
185 m_vSearchPath =
186 (m_nSearchPathIdx == 0) ? globals::g_pWaypointHandler->RetrievePath(
"RevSpiralPath") : globals::g_pWaypointHandler->
RetrievePath(
"unstuckPath");
187
188 std::vector<geoops::Waypoint> vRemainderOfSpiralPath = globals::g_pWaypointHandler->
RetrievePath(
"unstuckPath");
189
190
191 globals::g_pWaypointHandler->
StorePath(
"GeoPlannerPath", vRemainderOfSpiralPath);
192 m_pPursuitController->SetReferencePath(vRemainderOfSpiralPath);
193
194 m_bWasStuck = false;
195 }
196
197
199
200
201
202
203
204
205
206
207
208
209
211
213
214
215 if (m_stSearchPatternCenter.eType == geoops::WaypointType::eTagWaypoint)
216 {
217
219
221
222 if (stBestArucoTag.nID != -1 || stBestTorchTag.dConfidence != 0.0)
223 {
224
225 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target marker!");
226
227
228 globals::g_pStateMachineHandler->
HandleEvent(Event::eMarkerSeen,
true);
229
230 return;
231 }
232 }
233
235
237
238
239
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
245
247
248 if (stBestTorchObject.dConfidence != 0.0)
249 {
250
251 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target object!");
252
253
254 globals::g_pStateMachineHandler->
HandleEvent(Event::eObjectSeen,
true);
255
256 return;
257 }
258 }
259
261
263
264
265
267
269
270
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
277 LOG_WARNING(logging::g_qSharedLogger, "SearchPattern: Rover has become stuck!");
278
279 globals::g_pWaypointHandler->
StorePath(
"stuckPath", m_vSearchPath);
280 m_bWasStuck = true;
281
282 globals::g_pStateMachineHandler->
HandleEvent(Event::eStuck,
true);
283
284 return;
285 }
286
288
290
291
292 if (m_vSearchPath.empty())
293 {
294
295 LOG_WARNING(logging::g_qSharedLogger, "SearchPatternState: Search path is empty, aborting search.");
296
297 globals::g_pStateMachineHandler->
HandleEvent(Event::eAbort);
298 return;
299 }
300
301
304 double dCompletionRadius = constants::SEARCH_WAYPOINT_PROXIMITY;
305 bool bReachedFinalTarget = stRelToFinalTarget.dDistanceMeters <= dCompletionRadius;
306
307
308 if (bReachedFinalTarget)
309 {
310 globals::g_pStateMachineHandler->
HandleEvent(Event::eSearchFailed);
311 return;
312 }
313
314
315
317
319 stDriveVector.dThetaHeading,
321 diffdrive::DifferentialControlMethod::eArcadeDrive);
322
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