|
43 | 43 | #include <Util.h>
|
44 | 44 | #include "StartupState.h"
|
45 | 45 | #include "IdleState.h"
|
| 46 | +#include "DrivingState.h" |
46 | 47 |
|
47 | 48 | /******************************************************************************
|
48 | 49 | * Compiler Switches
|
@@ -171,12 +172,6 @@ void App::setup()
|
171 | 172 | }
|
172 | 173 | else
|
173 | 174 | {
|
174 |
| - /* Setup longitudinal controller. */ |
175 |
| - LongitudinalController::MotorSetpointCallback motorSetpointCallback = [this](const int16_t& topCenterSpeed) |
176 |
| - { return this->motorSetpointCallback(topCenterSpeed); }; |
177 |
| - |
178 |
| - m_longitudinalController.setMotorSetpointCallback(motorSetpointCallback); |
179 |
| - |
180 | 175 | /* Initialize timers. */
|
181 | 176 | m_sendWaypointTimer.start(SEND_WAYPOINT_TIMER_INTERVAL);
|
182 | 177 | m_commandTimer.start(SEND_COMMANDS_TIMER_INTERVAL);
|
@@ -220,62 +215,16 @@ void App::loop()
|
220 | 215 | /* Process V2V Communication */
|
221 | 216 | m_v2vClient.process();
|
222 | 217 |
|
223 |
| - /* Process Longitudinal Controller */ |
224 |
| - m_longitudinalController.process(); |
225 |
| - |
226 | 218 | /* Process System State Machine */
|
227 | 219 | m_systemStateMachine.process();
|
228 | 220 |
|
229 | 221 | /* Process periodic tasks. */
|
230 | 222 | processPeriodicTasks();
|
231 | 223 | }
|
232 | 224 |
|
233 |
| -void App::currentVehicleChannelCallback(const VehicleData& vehicleData) |
234 |
| -{ |
235 |
| - m_latestVehicleData = Waypoint(vehicleData.xPos, vehicleData.yPos, vehicleData.orientation, vehicleData.left, |
236 |
| - vehicleData.right, vehicleData.center); |
237 |
| - |
238 |
| - // latestVehicleData.debugPrint(); |
239 |
| - |
240 |
| - m_longitudinalController.calculateTopMotorSpeed(m_latestVehicleData); |
241 |
| -} |
242 |
| - |
243 |
| -bool App::motorSetpointCallback(const int16_t topCenterSpeed) |
| 225 | +void App::setLatestVehicleData(const Waypoint& waypoint) |
244 | 226 | {
|
245 |
| - SpeedData payload; |
246 |
| - payload.center = topCenterSpeed; |
247 |
| - |
248 |
| - return m_smpServer.sendData(m_serialMuxProtChannelIdMotorSpeeds, &payload, sizeof(payload)); |
249 |
| -} |
250 |
| - |
251 |
| -void App::release() |
252 |
| -{ |
253 |
| - Command payload; |
254 |
| - payload.commandId = RemoteControl::CMD_ID_START_DRIVING; |
255 |
| - |
256 |
| - /* Release robot. */ |
257 |
| - if (false == m_longitudinalController.release()) |
258 |
| - { |
259 |
| - LOG_WARNING("Robot could not be released."); |
260 |
| - } |
261 |
| - else if (false == m_smpServer.sendData(m_serialMuxProtChannelIdRemoteCtrl, &payload, sizeof(payload))) |
262 |
| - { |
263 |
| - LOG_WARNING("Failed to send release command to RU."); |
264 |
| - } |
265 |
| - else |
266 |
| - { |
267 |
| - LOG_INFO("Robot released."); |
268 |
| - } |
269 |
| -} |
270 |
| - |
271 |
| -void App::setMaxMotorSpeed(const int16_t maxMotorSpeed) |
272 |
| -{ |
273 |
| - m_longitudinalController.setMaxMotorSpeed(maxMotorSpeed); |
274 |
| -} |
275 |
| - |
276 |
| -void App::setLastFollowerFeedback(const Waypoint& feedback) |
277 |
| -{ |
278 |
| - m_longitudinalController.setLastFollowerFeedback(feedback); |
| 227 | + m_latestVehicleData = waypoint; |
279 | 228 | }
|
280 | 229 |
|
281 | 230 | /******************************************************************************
|
@@ -329,20 +278,19 @@ bool App::setupMqttClient()
|
329 | 278 | }
|
330 | 279 | else
|
331 | 280 | {
|
332 |
| - isSuccessful = |
333 |
| - m_mqttClient.subscribe(TOPIC_NAME_RELEASE, true, [this](const String& payload) { this->release(); }); |
334 |
| - |
335 |
| - isSuccessful &= m_mqttClient.subscribe("platoons/0/vehicles/0/feedback", false, |
336 |
| - [this](const String& payload) |
337 |
| - { |
338 |
| - Waypoint* waypoint = Waypoint::deserialize(payload); |
339 |
| - |
340 |
| - if (nullptr != waypoint) |
341 |
| - { |
342 |
| - this->setLastFollowerFeedback(*waypoint); |
343 |
| - delete waypoint; |
344 |
| - } |
345 |
| - }); |
| 281 | + isSuccessful = m_mqttClient.subscribe( |
| 282 | + TOPIC_NAME_RELEASE, true, [this](const String& payload) { IdleState::getInstance().requestRelease(); }); |
| 283 | + |
| 284 | + isSuccessful &= |
| 285 | + m_mqttClient.subscribe("platoons/0/vehicles/0/feedback", false, |
| 286 | + [this](const String& payload) |
| 287 | + { |
| 288 | + Waypoint* waypoint = Waypoint::deserialize(payload); |
| 289 | + VehicleData feedback{waypoint->xPos, waypoint->yPos, waypoint->orientation, |
| 290 | + waypoint->left, waypoint->right, waypoint->center}; |
| 291 | + |
| 292 | + DrivingState::getInstance().setLastFollowerFeedback(feedback); |
| 293 | + }); |
346 | 294 | }
|
347 | 295 |
|
348 | 296 | return isSuccessful;
|
@@ -441,7 +389,7 @@ void App_cmdRspChannelCallback(const uint8_t* payload, const uint8_t payloadSize
|
441 | 389 | else if (RemoteControl::CMD_ID_GET_MAX_SPEED == cmdRsp->commandId)
|
442 | 390 | {
|
443 | 391 | LOG_DEBUG("Max Speed: %d", cmdRsp->maxMotorSpeed);
|
444 |
| - application->setMaxMotorSpeed(cmdRsp->maxMotorSpeed); |
| 392 | + DrivingState::getInstance().setMaxMotorSpeed(cmdRsp->maxMotorSpeed); |
445 | 393 | StartupState::getInstance().notifyCommandProcessed();
|
446 | 394 | }
|
447 | 395 | else if (RemoteControl::CMD_ID_SET_INIT_POS == cmdRsp->commandId)
|
@@ -477,7 +425,11 @@ void App_currentVehicleChannelCallback(const uint8_t* payload, const uint8_t pay
|
477 | 425 | {
|
478 | 426 | const VehicleData* currentVehicleData = reinterpret_cast<const VehicleData*>(payload);
|
479 | 427 | App* application = reinterpret_cast<App*>(userData);
|
480 |
| - application->currentVehicleChannelCallback(*currentVehicleData); |
| 428 | + Waypoint dataAsWaypoint(currentVehicleData->xPos, currentVehicleData->yPos, currentVehicleData->orientation, |
| 429 | + currentVehicleData->left, currentVehicleData->right, currentVehicleData->center); |
| 430 | + |
| 431 | + application->setLatestVehicleData(dataAsWaypoint); |
| 432 | + DrivingState::getInstance().setVehicleData(*currentVehicleData); |
481 | 433 | }
|
482 | 434 | else
|
483 | 435 | {
|
|
0 commit comments