Skip to content

Commit a13d324

Browse files
committed
Sending top motor speeds periodically
1 parent 68c6862 commit a13d324

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

lib/ConvoyLeader/src/App.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ void App::setup()
175175
/* Initialize timers. */
176176
m_sendWaypointTimer.start(SEND_WAYPOINT_TIMER_INTERVAL);
177177
m_commandTimer.start(SEND_COMMANDS_TIMER_INTERVAL);
178+
m_motorSpeedTimer.start(SEND_MOTOR_SPEED_TIMER_INTERVAL);
178179

179180
/* Start with startup state. */
180181
m_systemStateMachine.setState(&StartupState::getInstance());
@@ -356,15 +357,31 @@ void App::processPeriodicTasks()
356357
m_commandTimer.restart();
357358
}
358359

359-
if (true == m_sendWaypointTimer.isTimeout())
360+
if ((true == m_sendWaypointTimer.isTimeout()) && (true == m_mqttClient.isConnected()))
360361
{
361362
if (false == m_v2vClient.sendWaypoint(m_latestVehicleData))
362363
{
363364
LOG_WARNING("Waypoint could not be sent.");
364365
}
365-
else
366+
367+
m_sendWaypointTimer.restart();
368+
}
369+
370+
if ((true == m_motorSpeedTimer.isTimeout()) && (true == m_smpServer.isSynced()))
371+
{
372+
int16_t centerSpeed = 0;
373+
374+
if (true == DrivingState::getInstance().getTopMotorSpeed(centerSpeed))
366375
{
367-
m_sendWaypointTimer.restart();
376+
SpeedData payload;
377+
payload.center = centerSpeed;
378+
379+
if (false == m_smpServer.sendData(m_serialMuxProtChannelIdMotorSpeeds, &payload, sizeof(SpeedData)))
380+
{
381+
LOG_WARNING("Failed to send motor speeds to RU.");
382+
}
383+
384+
m_motorSpeedTimer.restart();
368385
}
369386
}
370387
}

lib/ConvoyLeader/src/App.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ class App
7272
m_smpServer(Board::getInstance().getDevice().getStream(), this),
7373
m_mqttClient(),
7474
m_v2vClient(m_mqttClient),
75-
m_sendWaypointTimer()
75+
m_systemStateMachine(),
76+
m_latestVehicleData(),
77+
m_sendWaypointTimer(),
78+
m_commandTimer(),
79+
m_motorSpeedTimer()
7680
{
7781
}
7882

@@ -115,6 +119,9 @@ class App
115119
/** Send commands timer interval in ms. */
116120
static const uint32_t SEND_COMMANDS_TIMER_INTERVAL = 100U;
117121

122+
/** Send motor speed timer interval in ms. */
123+
static const uint32_t SEND_MOTOR_SPEED_TIMER_INTERVAL = 100U;
124+
118125
/** MQTT topic name for birth messages. */
119126
static const char* TOPIC_NAME_BIRTH;
120127

@@ -147,7 +154,9 @@ class App
147154
*/
148155
V2VClient m_v2vClient;
149156

150-
/** The system state machine. */
157+
/**
158+
* The system state machine.
159+
*/
151160
StateMachine m_systemStateMachine;
152161

153162
/**
@@ -165,6 +174,11 @@ class App
165174
*/
166175
SimpleTimer m_commandTimer;
167176

177+
/**
178+
* Timer for sending motor speed to RU.
179+
*/
180+
SimpleTimer m_motorSpeedTimer;
181+
168182
private:
169183
/**
170184
* Handler of fatal errors in the Application.

0 commit comments

Comments
 (0)