Run the state machine. Returns the next state.
95 {
96
97 LOG_DEBUG(logging::g_qSharedLogger, "ApproachingMarkerState: Running state-specific behavior.");
98
99
100 bool bDetectedTagAR = false;
101 bool bDetectedTagTF = false;
102
103
105
106
107 if (!m_bDetected && m_nNumDetectionAttempts < constants::APPROACH_MARKER_DETECT_ATTEMPTS_LIMIT)
108 {
109
110
112 if (bDetectedTagAR)
113 {
114
115 m_nTargetTagID = m_stTargetTagAR.nID;
116 m_bDetected = true;
117 m_nNumDetectionAttempts = 0;
118 }
119 else
120 {
121
123 if (bDetectedTagTF)
124 {
125
126
127
128 m_bDetected = true;
129 m_nNumDetectionAttempts = 0;
130 }
131 }
132
133
134 if (!m_bDetected)
135 {
136 ++m_nNumDetectionAttempts;
137 }
138
139 return;
140 }
141
142 else if (!m_bDetected)
143 {
144
145 globals::g_pStateMachineHandler->
HandleEvent(Event::eMarkerUnseen);
146 return;
147 }
148
149
151
152
153
154
155
156
157
158
159 if (!bDetectedTagAR && !bDetectedTagTF)
160 {
161 ++m_nNumDetectionAttempts;
162 }
163
164 else
165 {
166 m_nNumDetectionAttempts = 0;
167 }
168
169
170
171 if (m_nNumDetectionAttempts >= constants::APPROACH_MARKER_DETECT_ATTEMPTS_LIMIT)
172 {
173 globals::g_pStateMachineHandler->
HandleEvent(Event::eMarkerUnseen);
174 return;
175 }
176
177
179
180
181 double dTargetHeading;
182 double dTargetDistance;
183
184 if (bDetectedTagAR)
185 {
186 dTargetHeading = numops::InputAngleModulus<double>(dCurrHeading + m_stTargetTagAR.dYawAngle, 0, 360);
187 dTargetDistance = m_stTargetTagAR.dStraightLineDistance;
188 }
189 else if (bDetectedTagTF)
190 {
191 dTargetHeading = numops::InputAngleModulus<double>(dCurrHeading + m_stTargetTagTF.dYawAngle, 0, 360);
192 dTargetDistance = m_stTargetTagTF.dStraightLineDistance;
193 }
194
195 else
196 {
197 dTargetHeading = m_dLastTargetHeading;
198 dTargetDistance = m_dLastTargetDistance;
199 }
200
201 m_dLastTargetHeading = dTargetHeading;
202 m_dLastTargetDistance = dTargetDistance;
203
204
205 static bool bAlreadyPrinted = false;
206 if ((std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count() % 5) == 0 && !bAlreadyPrinted)
207 {
208
209 LOG_INFO(logging::g_qSharedLogger,
210 "ApproachingMarkerState: Rover is {} meters from the marker. Minimum Distance is {}.",
211 dTargetDistance,
212 constants::APPROACH_MARKER_PROXIMITY_THRESHOLD);
213
214 bAlreadyPrinted = true;
215 }
216 else if ((std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count() % 5) != 0 && bAlreadyPrinted)
217 {
218
219 bAlreadyPrinted = false;
220 }
221
222
223 if (dTargetDistance < constants::APPROACH_MARKER_PROXIMITY_THRESHOLD)
224 {
225 globals::g_pStateMachineHandler->
HandleEvent(Event::eReachedMarker);
226 return;
227 }
228
229
231 dTargetHeading,
232 dCurrHeading,
233 diffdrive::DifferentialControlMethod::eArcadeDrive);
234 globals::g_pDriveBoard->
SendDrive(stDrivePowers);
235
236 return;
237 }
diffdrive::DrivePowers CalculateMove(const double dGoalSpeed, const double dGoalHeading, const double dActualHeading, const diffdrive::DifferentialControlMethod eKinematicsMethod)
This method determines drive powers to make the Rover drive towards a given heading at a given speed.
Definition DriveBoard.cpp:92
void SendDrive(diffdrive::DrivePowers &stDrivePowers)
Sets the left and right drive powers of the drive board.
Definition DriveBoard.cpp:120
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:337
geoops::RoverPose SmartRetrieveRoverPose(bool bVIOTracking=false)
Retrieve the rover's current position and heading. Automatically picks between getting the position/h...
Definition WaypointHandler.cpp:738
bool IdentifyTargetArucoMarker(arucotag::ArucoTag &stTarget)
Identify a target marker in the rover's vision, using OpenCV detection.
Definition ApproachingMarkerState.cpp:332
bool IdentifyTargetTensorflowMarker(tensorflowtag::TensorflowTag &stTarget)
Identify a target marker in the rover's vision, using Tensorflow detection.
Definition ApproachingMarkerState.cpp:390
bool FindArucoTagByID(int nID, arucotag::ArucoTag &stIdentifiedArucoTag, const std::vector< TagDetector * > &vTagDetectors)
Find a tag in the rover's vision with the specified ID, using OpenCV detection.
Definition TagDetectionUtilty.hpp:133
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 is used by the WaypointHandler to provide an easy way to store all pose data about the ro...
Definition GeospatialOperations.hpp:674
double GetCompassHeading() const
Accessor for the Compass Heading private member.
Definition GeospatialOperations.hpp:743