Skip to content

Commit

Permalink
Added current and initial vehicle data channels
Browse files Browse the repository at this point in the history
  • Loading branch information
gabryelreyes committed Jan 16, 2024
1 parent 098a9c0 commit fc285f8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
42 changes: 42 additions & 0 deletions lib/RemoteControl/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

static void App_cmdRspChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);
static void App_lineSensorChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);
static void App_currentVehicleChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);

/******************************************************************************
* Local Variables
Expand Down Expand Up @@ -161,6 +162,9 @@ void App::setup()
m_smpServer.createChannel(SPEED_SETPOINT_CHANNEL_NAME, SPEED_SETPOINT_CHANNEL_DLC);
m_smpServer.subscribeToChannel(COMMAND_RESPONSE_CHANNEL_NAME, App_cmdRspChannelCallback);
m_smpServer.subscribeToChannel(LINE_SENSOR_CHANNEL_NAME, App_lineSensorChannelCallback);
m_smpServer.subscribeToChannel(CURRENT_VEHICLE_DATA_CHANNEL_NAME, App_currentVehicleChannelCallback);
m_serialMuxProtChannelInitialVehicleData =
m_smpServer.createChannel(INITIAL_VEHICLE_DATA_CHANNEL_NAME, INITIAL_VEHICLE_DATA_CHANNEL_DLC);

if (false == m_mqttClient.init())
{
Expand Down Expand Up @@ -223,6 +227,18 @@ void App::loop()

/* Process SerialMuxProt. */
m_smpServer.process(millis());

if (false == m_initialDataSent)
{
VehicleData initialVehicleData = {.xPos = 0, .yPos = 0, .orientation = 0, .left = 0, .right = 0, .center = 0};

if (true == m_smpServer.sendData(m_serialMuxProtChannelInitialVehicleData, &initialVehicleData,
sizeof(initialVehicleData)))
{
LOG_DEBUG("Initial vehicle data sent.");
m_initialDataSent = true;
}
}
}

/******************************************************************************
Expand Down Expand Up @@ -363,3 +379,29 @@ void App_lineSensorChannelCallback(const uint8_t* payload, const uint8_t payload
UTIL_NOT_USED(payloadSize);
UTIL_NOT_USED(userData);
}

/**
* Receives current position and heading of the robot over SerialMuxProt channel.
*
* @param[in] payload Current vehicle data. Two coordinates, one orientation and two motor speeds.
* @param[in] payloadSize Size of two coordinates, one orientation and two motor speeds.
* @param[in] userData Instance of App class.
*/
void App_currentVehicleChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData)
{
UTIL_NOT_USED(userData);

if ((nullptr != payload) && (CURRENT_VEHICLE_DATA_CHANNEL_DLC == payloadSize))
{
const VehicleData* currentVehicleData = reinterpret_cast<const VehicleData*>(payload);

LOG_DEBUG("X: %d Y: %d Heading: %d Left: %d Right: %d Center: %d", currentVehicleData->xPos,
currentVehicleData->yPos, currentVehicleData->orientation, currentVehicleData->left,
currentVehicleData->right, currentVehicleData->center);
}
else
{
LOG_WARNING("%s: Invalid payload size. Expected: %u Received: %u", CURRENT_VEHICLE_DATA_CHANNEL_NAME,
CURRENT_VEHICLE_DATA_CHANNEL_DLC, payloadSize);
}
}
16 changes: 12 additions & 4 deletions lib/RemoteControl/src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ class App
* Construct the Remote Control application.
*/
App() :
m_smpServer(Board::getInstance().getDevice().getStream()),
m_smpServer(Board::getInstance().getDevice().getStream(), this),
m_serialMuxProtChannelIdRemoteCtrl(0U),
m_serialMuxProtChannelIdMotorSpeeds(0U),
m_mqttClient()
m_serialMuxProtChannelInitialVehicleData(0U),
m_mqttClient(),
m_initialDataSent(false)
{
}

Expand Down Expand Up @@ -102,12 +104,15 @@ class App
/** MQTT topic name for receiving motor speeds. */
static const char* TOPIC_NAME_MOTOR_SPEEDS;

/** SerialMuxProt Channel id sending remote control commands. */
/** SerialMuxProt Channel id for sending remote control commands. */
uint8_t m_serialMuxProtChannelIdRemoteCtrl;

/** SerialMuxProt Channel id sending sending motor speeds. */
/** SerialMuxProt Channel id for sending motor speeds. */
uint8_t m_serialMuxProtChannelIdMotorSpeeds;

/** SerialMuxProt Channel id for sending initial position data. */
uint8_t m_serialMuxProtChannelInitialVehicleData;

/**
* SerialMuxProt Server Instance
*
Expand All @@ -120,6 +125,9 @@ class App
*/
MqttClient m_mqttClient;

/** Flag for setting initial data through SMP. */
bool m_initialDataSent;

private:
/**
* Handler of fatal errors in the Application.
Expand Down

0 comments on commit fc285f8

Please sign in to comment.