Skip to content

Commit

Permalink
Renamed channels and structures to simplify interface to DCS
Browse files Browse the repository at this point in the history
  • Loading branch information
gabryelreyes committed Sep 2, 2024
1 parent bd17b73 commit a29caea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
16 changes: 8 additions & 8 deletions lib/APPRemoteControl/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ bool App::setupSerialMuxProt()

/* Channel subscription. */
m_smpServer.subscribeToChannel(COMMAND_CHANNEL_NAME, App_cmdChannelCallback);
m_smpServer.subscribeToChannel(SPEED_SETPOINT_CHANNEL_NAME, App_motorSpeedSetpointsChannelCallback);
m_smpServer.subscribeToChannel(MOTOR_SPEED_SETPOINT_CHANNEL_NAME, App_motorSpeedSetpointsChannelCallback);
m_smpServer.subscribeToChannel(STATUS_CHANNEL_NAME, App_statusChannelCallback);
m_smpServer.subscribeToChannel(TURTLE_CHANNEL_NAME, App_turtleChannelCallback);
m_smpServer.subscribeToChannel(ROBOT_SPEED_SETPOINT_CHANNEL_NAME, App_turtleChannelCallback);

/* Channel creation. */
m_serialMuxProtChannelIdRemoteCtrlRsp =
Expand Down Expand Up @@ -361,9 +361,9 @@ static void App_cmdChannelCallback(const uint8_t* payload, const uint8_t payload
void App_motorSpeedSetpointsChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData)
{
(void)userData;
if ((nullptr != payload) && (SPEED_SETPOINT_CHANNEL_DLC == payloadSize))
if ((nullptr != payload) && (MOTOR_SPEED_SETPOINT_CHANNEL_DLC == payloadSize))
{
const SpeedData* motorSpeedData = reinterpret_cast<const SpeedData*>(payload);
const MotorSpeed* motorSpeedData = reinterpret_cast<const MotorSpeed*>(payload);
DrivingState::getInstance().setTargetSpeeds(motorSpeedData->left, motorSpeedData->right);
}
}
Expand All @@ -388,16 +388,16 @@ void App_statusChannelCallback(const uint8_t* payload, const uint8_t payloadSize
/**
* Receives Turtle speed setpoints over SerialMuxProt channel.
*
* @param[in] payload Linear and angular speed setpoints in a TurtleSpeed structure.
* @param[in] payloadSize Size of the TurtleSpeed structure.
* @param[in] payload Linear and angular speed setpoints in a RobotSpeed structure.
* @param[in] payloadSize Size of the RobotSpeed structure.
* @param[in] userData Instance of App class.
*/
void App_turtleChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData)
{
(void)userData;
if ((nullptr != payload) && (TURTLE_CHANNEL_DLC == payloadSize))
if ((nullptr != payload) && (ROBOT_SPEED_SETPOINT_CHANNEL_DLC == payloadSize))
{
const TurtleSpeed* turtleSpeedData = reinterpret_cast<const TurtleSpeed*>(payload);
const RobotSpeed* turtleSpeedData = reinterpret_cast<const RobotSpeed*>(payload);
DifferentialDrive& diffDrive = DifferentialDrive::getInstance();
int16_t angularSpeed = static_cast<int16_t>(turtleSpeedData->angular);

Expand Down
43 changes: 21 additions & 22 deletions lib/APPRemoteControl/src/SerialMuxChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@
#define COMMAND_RESPONSE_CHANNEL_DLC (sizeof(CommandResponse))

/** Name of Channel to send Motor Speed Setpoints to. */
#define SPEED_SETPOINT_CHANNEL_NAME "SPEED_SET"
#define MOTOR_SPEED_SETPOINT_CHANNEL_NAME "MOTOR_SET"

/** DLC of Speedometer Channel */
#define SPEED_SETPOINT_CHANNEL_DLC (sizeof(SpeedData))
/** DLC of Motor Speed Setpoint Channel */
#define MOTOR_SPEED_SETPOINT_CHANNEL_DLC (sizeof(MotorSpeed))

/** Name of the Channel to send Robot Speed Setpoints to. */
#define ROBOT_SPEED_SETPOINT_CHANNEL_NAME "ROBOT_SET"

/** DLC of Robot Speed Setpoint Channel */
#define ROBOT_SPEED_SETPOINT_CHANNEL_DLC (sizeof(RobotSpeed))

/** Name of Channel to send Current Vehicle Data to. */
#define CURRENT_VEHICLE_DATA_CHANNEL_NAME "CURR_DATA"
Expand All @@ -82,12 +88,6 @@
/** DLC of Line Sensor Channel */
#define LINE_SENSOR_CHANNEL_DLC (sizeof(LineSensorData))

/** Name of the Channel to send Turtle Speeds. */
#define TURTLE_CHANNEL_NAME "TURTLE"

/** DLC of Turtle Channel */
#define TURTLE_CHANNEL_DLC (sizeof(TurtleSpeed))

/******************************************************************************
* Types and Classes
*****************************************************************************/
Expand Down Expand Up @@ -179,13 +179,19 @@ typedef struct _CommandResponse
};
} __attribute__((packed)) CommandResponse;

/** Struct of the "Speed" channel payload. */
typedef struct _SpeedData
/** Struct of the "Motor Speed Setpoints" channel payload. */
typedef struct _MotorSpeed
{
int32_t left; /**< Left motor speed [mm/s] */
int32_t right; /**< Right motor speed [mm/s] */
} __attribute__((packed)) MotorSpeed;

/** Struct of the "Robot Speed Setpoints" channel payload. */
typedef struct _RobotSpeed
{
int32_t left; /**< Left motor speed [mm/s] */
int32_t right; /**< Right motor speed [mm/s] */
int32_t center; /**< Center motor speed [mm/s] */
} __attribute__((packed)) SpeedData;
int32_t linearCenter; /**< Linear speed of the vehicle center. [mm/s] */
int32_t angular; /**< Angular speed. [mrad/s] */
} __attribute__((packed)) RobotSpeed;

/** Struct of the "Current Vehicle Data" channel payload. */
typedef struct _VehicleData
Expand All @@ -211,13 +217,6 @@ typedef struct _LineSensorData
uint16_t lineSensorData[5U]; /**< Line sensor data [digits] normalized to max 1000 digits. */
} __attribute__((packed)) LineSensorData;

/** Struct of the "Turtle" channel payload. */
typedef struct _TurtleSpeed
{
int32_t linearCenter; /**< Linear speed of the vehicle center. [mm/s] */
int32_t angular; /**< Angular speed. [mrad/s] */
} __attribute__((packed)) TurtleSpeed;

/******************************************************************************
* Functions
*****************************************************************************/
Expand Down

0 comments on commit a29caea

Please sign in to comment.