Run the state machine. Returns the next state.
121 {
122
123 LOG_DEBUG(logging::g_qSharedLogger, "SearchPatternState: Running state-specific behavior.");
124
125
127
128
129 m_pRoverPathPlot->AddPathPoint(stCurrentRoverPose.
GetUTMCoordinate(),
"RoverPath");
130
131
132
133
134
135
136
137
138
139
140
142
144
145
146 if (m_stSearchPatternCenter.eType == geoops::WaypointType::eTagWaypoint)
147 {
148
150
152
153 if (stBestArucoTag.nID != -1 || stBestTorchTag.dConfidence != 0.0)
154 {
155
156 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target marker!");
157
158
159 if (stBestArucoTag.nID != -1 && stBestArucoTag.stGeolocatedPosition.eType == geoops::WaypointType::eTagWaypoint)
160 {
161
162 m_pRoverPathPlot->AddDot(stBestArucoTag.stGeolocatedPosition.
GetUTMCoordinate(),
"DetectedTags");
163 }
164
165 if (stBestTorchTag.dConfidence != 0.0 && stBestTorchTag.stGeolocatedPosition.eType == geoops::WaypointType::eTagWaypoint)
166 {
167
168 m_pRoverPathPlot->AddDot(stBestTorchTag.stGeolocatedPosition.
GetUTMCoordinate(),
"DetectedTags");
169 }
170
171
172 globals::g_pStateMachineHandler->
HandleEvent(Event::eMarkerSeen,
true);
173
174 return;
175 }
176 }
177
179
181
182
183
184 if (m_stSearchPatternCenter.eType == geoops::WaypointType::eObjectWaypoint || m_stSearchPatternCenter.eType == geoops::WaypointType::eMalletWaypoint ||
185 m_stSearchPatternCenter.eType == geoops::WaypointType::eWaterBottleWaypoint || m_stSearchPatternCenter.eType == geoops::WaypointType::eRockPickWaypoint)
186 {
187
189
191
192 if (stBestTorchObject.dConfidence != 0.0)
193 {
194
195 LOG_NOTICE(logging::g_qSharedLogger, "SearchPatternState: Rover has seen a target object!");
196
197
198 if (stBestTorchObject.dConfidence != 0.0 && stBestTorchObject.stGeolocatedPosition.eType == geoops::WaypointType::eObjectWaypoint)
199 {
200
201 m_pRoverPathPlot->AddDot(stBestTorchObject.stGeolocatedPosition.
GetUTMCoordinate(),
"DetectedObjects");
202 }
203
204
205 globals::g_pStateMachineHandler->
HandleEvent(Event::eObjectSeen,
true);
206
207 return;
208 }
209 }
210
212
214
215
216
218
220
221
222 if (constants::SEARCH_ENABLE_STUCK_DETECT &&
223 m_StuckDetector.
CheckIfStuck(globals::g_pStateMachineHandler->SmartRetrieveVelocity(), globals::g_pStateMachineHandler->SmartRetrieveAngularVelocity()))
224 {
225
226 LOG_WARNING(logging::g_qSharedLogger, "SearchPattern: Rover has become stuck!");
227
228 m_nSearchPathIdx += 1;
229
230 if (m_nSearchPathIdx >= int(m_vSearchPath.size()))
231 {
232 m_nSearchPathIdx = m_vSearchPath.size() - 1;
233 }
234
235 globals::g_pStateMachineHandler->
HandleEvent(Event::eStuck,
true);
236
237 return;
238 }
239
241
243
244
245 if (m_vSearchPath.empty())
246 {
247
248 LOG_WARNING(logging::g_qSharedLogger, "SearchPatternState: Search path is empty, aborting search.");
249
250 globals::g_pStateMachineHandler->
HandleEvent(Event::eAbort);
251 return;
252 }
253
254
257 bool bReachedTarget = stCurrRelToTarget.dDistanceMeters <= constants::SEARCH_WAYPOINT_PROXIMITY;
258
259
260 if (bReachedTarget && m_nSearchPathIdx >= int(m_vSearchPath.size() - 1))
261 {
262 globals::g_pStateMachineHandler->
HandleEvent(Event::eSearchFailed);
263 return;
264 }
265
266 else if (bReachedTarget)
267 {
268 ++m_nSearchPathIdx;
269 stCurrTargetGPS = m_vSearchPath[m_nSearchPathIdx].GetGPSCoordinate();
271 }
272
273
275 stCurrRelToTarget.dStartRelativeBearing,
277 diffdrive::DifferentialControlMethod::eArcadeDrive);
278
279
280 globals::g_pDriveBoard->
SendDrive(stDrivePowers);
281
282 return;
283 }
void SendDrive(const diffdrive::DrivePowers &stDrivePowers, const bool bEnableVariableDriveEffort=true)
Sets the left and right drive powers of the drive board.
Definition DriveBoard.cpp:118
diffdrive::DrivePowers CalculateMove(const double dGoalSpeed, const double dGoalHeading, const double dActualHeading, const diffdrive::DifferentialControlMethod eKinematicsMethod=diffdrive::DifferentialControlMethod::eArcadeDrive, const bool bAlwaysProgressForward=false)
This method determines drive powers to make the Rover drive towards a given heading at a given speed.
Definition DriveBoard.cpp:88
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:353
bool CheckIfStuck(double dCurrentVelocity, double dCurrentAngularVelocity)
Checks if the rover meets stuck criteria based in the given parameters.
Definition StuckDetection.hpp:105
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:91
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:90
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
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 detected object. Combines attributes from TorchObject and TensorflowObject struct...
Definition ObjectDetectionUtility.hpp:74
Represents a single ArUco tag. Combines attributes from TorchTag, TensorflowTag, and the original Aru...
Definition TagDetectionUtilty.hpp:59