Skip to content

Commit d9f0f28

Browse files
committed
fix(APPRemoteControl): add ROBOT_SET channel and fix initial pose handling
- Create ROBOT_SET SMP channel so robot speed setpoints (linear + angular) can be sent to RU - Guard initial pose send in loop() with isSynced() to avoid spinning before SMP sync is established - Allow CMD_ID_SET_INIT_POS from MQTT when X, Y and HEADING fields are present; remove misleading "not supported" rejection
1 parent 55c028e commit d9f0f28

2 files changed

Lines changed: 35 additions & 10 deletions

File tree

lib/APPRemoteControl/src/App.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void App::loop()
178178
/* Process SerialMuxProt. */
179179
m_smpServer.process(millis());
180180

181-
if (false == m_initialDataSent)
181+
if ((false == m_initialDataSent) && (true == m_smpServer.isSynced()))
182182
{
183183
SettingsHandler& settings = SettingsHandler::getInstance();
184184
Command cmd = {SMPChannelPayload::CMD_ID_SET_INIT_POS, settings.getInitialXPosition(),
@@ -189,6 +189,10 @@ void App::loop()
189189
LOG_DEBUG("Initial vehicle data sent.");
190190
m_initialDataSent = true;
191191
}
192+
else
193+
{
194+
LOG_WARNING("Failed to send initial vehicle data.");
195+
}
192196
}
193197

194198
if ((true == m_statusTimer.isTimeout()) && (true == m_smpServer.isSynced()))
@@ -231,14 +235,16 @@ bool App::setupSerialMuxProtServer()
231235
m_serialMuxProtChannelIdRemoteCtrl = m_smpServer.createChannel(COMMAND_CHANNEL_NAME, COMMAND_CHANNEL_DLC);
232236
m_serialMuxProtChannelIdMotorSpeeds =
233237
m_smpServer.createChannel(MOTOR_SPEED_SETPOINT_CHANNEL_NAME, MOTOR_SPEED_SETPOINT_CHANNEL_DLC);
238+
m_serialMuxProtChannelIdRobotSpeeds =
239+
m_smpServer.createChannel(ROBOT_SPEED_SETPOINT_CHANNEL_NAME, ROBOT_SPEED_SETPOINT_CHANNEL_DLC);
234240
m_serialMuxProtChannelIdStatus = m_smpServer.createChannel(STATUS_CHANNEL_NAME, STATUS_CHANNEL_DLC);
235241

236242
m_smpServer.subscribeToChannel(COMMAND_RESPONSE_CHANNEL_NAME, App_cmdRspChannelCallback);
237243
m_smpServer.subscribeToChannel(LINE_SENSOR_CHANNEL_NAME, App_lineSensorChannelCallback);
238244
m_smpServer.subscribeToChannel(CURRENT_VEHICLE_DATA_CHANNEL_NAME, App_currentVehicleChannelCallback);
239245

240246
if ((0U == m_serialMuxProtChannelIdRemoteCtrl) || (0U == m_serialMuxProtChannelIdMotorSpeeds) ||
241-
(0U == m_serialMuxProtChannelIdStatus))
247+
(0U == m_serialMuxProtChannelIdRobotSpeeds) || (0U == m_serialMuxProtChannelIdStatus))
242248
{
243249
LOG_ERROR("Failed to create SerialMuxProt channels.");
244250
}
@@ -278,13 +284,13 @@ bool App::setupMqtt(const String& clientId, const String& brokerAddr, uint16_t b
278284
else if (false == m_mqttClient.subscribe(TOPIC_NAME_CMD, true,
279285
[this](const String& payload) { cmdTopicCallback(payload); }))
280286
{
281-
LOG_FATAL("Could not subcribe to MQTT topic: %s.", TOPIC_NAME_CMD);
287+
LOG_FATAL("Could not subscribe to MQTT topic: %s.", TOPIC_NAME_CMD);
282288
}
283289
/* Subscribe to Motor Speeds Topic. */
284290
else if (false == m_mqttClient.subscribe(TOPIC_NAME_MOTOR_SPEEDS, true,
285291
[this](const String& payload) { motorSpeedsTopicCallback(payload); }))
286292
{
287-
LOG_FATAL("Could not subcribe to MQTT topic: %s.", TOPIC_NAME_MOTOR_SPEEDS);
293+
LOG_FATAL("Could not subscribe to MQTT topic: %s.", TOPIC_NAME_MOTOR_SPEEDS);
288294
}
289295
else
290296
{
@@ -341,10 +347,25 @@ void App::cmdTopicCallback(const String& payload)
341347
break;
342348

343349
case 6U:
344-
cmd.commandId = SMPChannelPayload::CmdId::CMD_ID_SET_INIT_POS;
345-
LOG_WARNING("Setting initial position is not supported.");
346-
isValid = false;
350+
{
351+
JsonVariantConst xPos = jsonPayload["X"];
352+
JsonVariantConst yPos = jsonPayload["Y"];
353+
JsonVariantConst heading = jsonPayload["HEADING"];
354+
355+
if (xPos.isNull() || yPos.isNull() || heading.isNull())
356+
{
357+
LOG_WARNING("CMD_ID_SET_INIT_POS requires X, Y and HEADING fields.");
358+
isValid = false;
359+
}
360+
else
361+
{
362+
cmd.commandId = SMPChannelPayload::CmdId::CMD_ID_SET_INIT_POS;
363+
cmd.xPos = xPos.as<int32_t>();
364+
cmd.yPos = yPos.as<int32_t>();
365+
cmd.orientation = heading.as<int32_t>();
366+
}
347367
break;
368+
}
348369

349370
default:
350371
isValid = false;

lib/APPRemoteControl/src/App.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class App
7070
m_smpServer(Board::getInstance().getRobot().getStream()),
7171
m_serialMuxProtChannelIdRemoteCtrl(0U),
7272
m_serialMuxProtChannelIdMotorSpeeds(0U),
73+
m_serialMuxProtChannelIdRobotSpeeds(0U),
7374
m_serialMuxProtChannelIdStatus(0U),
7475
m_mqttClient(),
7576
m_initialDataSent(false),
@@ -109,13 +110,16 @@ class App
109110
/** MQTT topic name for receiving motor speeds. */
110111
static const char* TOPIC_NAME_MOTOR_SPEEDS;
111112

112-
/** SerialMuxProt Channel id for sending remote control commands. */
113+
/** SerialMuxProt Channel ID for sending remote control commands. */
113114
uint8_t m_serialMuxProtChannelIdRemoteCtrl;
114115

115-
/** SerialMuxProt Channel id for sending motor speeds. */
116+
/** SerialMuxProt Channel ID for sending motor speeds. */
116117
uint8_t m_serialMuxProtChannelIdMotorSpeeds;
117118

118-
/** SerialMuxProt Channel id for sending system status. */
119+
/** SerialMuxProt Channel ID for sending robot speed setpoints (linear + angular). */
120+
uint8_t m_serialMuxProtChannelIdRobotSpeeds;
121+
122+
/** SerialMuxProt Channel ID for sending system status. */
119123
uint8_t m_serialMuxProtChannelIdStatus;
120124

121125
/**

0 commit comments

Comments
 (0)