Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade SerialMuxProt Channels #163

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ In a similar way, not providing a WiFi configuration will force the target into
| RemoteControl | No | Yes | RemoteControl | Yes |
| SensorFusion | No | Yes | SensorFusion | Yes |
| Test | Yes | No | N/A | No |
| Turtle | No | Yes | RemoteControl | Yes (ROS2 + Micro-ROS Agent) |

# Documentation

Expand Down
7 changes: 4 additions & 3 deletions lib/APPTurtle/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ bool App::setupSerialMuxProtServer()
bool isSuccessful = false;

m_serialMuxProtChannelIdStatus = m_smpServer.createChannel(STATUS_CHANNEL_NAME, STATUS_CHANNEL_DLC);
m_serialMuxProtChannelIdTurtle = m_smpServer.createChannel(TURTLE_CHANNEL_NAME, TURTLE_CHANNEL_DLC);
m_serialMuxProtChannelIdTurtle =
m_smpServer.createChannel(ROBOT_SPEED_SETPOINT_CHANNEL_NAME, ROBOT_SPEED_SETPOINT_CHANNEL_DLC);

if ((0U == m_serialMuxProtChannelIdStatus) || (0U == m_serialMuxProtChannelIdTurtle))
{
Expand All @@ -295,7 +296,7 @@ void App::handleTurtle()
/* Check for new data. */
if (true == m_isNewTurtleSpeedSetpoint)
{
TurtleSpeed payload;
RobotSpeed payload;
const int32_t MILLI_CONVERSION_FACTOR = 1000;
int32_t linearSpeed = m_turtleSpeedSetpoint.linear.x * MILLI_CONVERSION_FACTOR; /* Linear speed in mm/s */
int32_t angularSpeed = m_turtleSpeedSetpoint.angular.z * MILLI_CONVERSION_FACTOR; /* Angular speed in mrad/s */
Expand All @@ -318,7 +319,7 @@ void App::handleTurtle()

if (true == m_turtleMovementTimer.isTimeout())
{
TurtleSpeed payload;
RobotSpeed payload;
payload.linearCenter = 0;
payload.angular = 0;

Expand Down
43 changes: 21 additions & 22 deletions lib/APPTurtle/src/SerialMuxChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,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 @@ -86,12 +92,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 @@ -183,13 +183,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 @@ -215,13 +221,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
4 changes: 2 additions & 2 deletions lib/RemoteControl/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void App::setup()
/* Setup SerialMuxProt Channels */
m_serialMuxProtChannelIdRemoteCtrl = m_smpServer.createChannel(COMMAND_CHANNEL_NAME, COMMAND_CHANNEL_DLC);
m_serialMuxProtChannelIdMotorSpeeds =
m_smpServer.createChannel(SPEED_SETPOINT_CHANNEL_NAME, SPEED_SETPOINT_CHANNEL_DLC);
m_smpServer.createChannel(MOTOR_SPEED_SETPOINT_CHANNEL_NAME, MOTOR_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);
Expand Down Expand Up @@ -369,7 +369,7 @@ void App::motorSpeedsTopicCallback(const String& payload)

if ((false == leftSpeed.isNull()) && (false == rightSpeed.isNull()))
{
SpeedData motorSetpoints;
MotorSpeed motorSetpoints;
motorSetpoints.left = leftSpeed.as<int32_t>();
motorSetpoints.right = rightSpeed.as<int32_t>();

Expand Down
30 changes: 21 additions & 9 deletions lib/RemoteControl/src/SerialMuxChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,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 Down Expand Up @@ -177,13 +183,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 Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ lib_deps =
Utilities
bblanchon/ArduinoJson @ ^6.21.3
gabryelreyes/SerialMuxProt @ ^2.0.0
libmicroros
lib_ignore =
ConvoyLeader
ConvoyFollower
Expand Down Expand Up @@ -398,6 +397,7 @@ lib_deps =
lib_ignore =
${target:esp32.lib_ignore}
${app:Turtle.lib_ignore}
libmicroros
extra_scripts =
${target:esp32.extra_scripts}

Expand Down