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

Turtle functionality in RemoteControl #149

Merged
merged 13 commits into from
Sep 3, 2024
32 changes: 32 additions & 0 deletions lib/APPRemoteControl/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
static void App_cmdChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);
static void App_motorSpeedSetpointsChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);
static void App_statusChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);
static void App_turtleChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData);

/******************************************************************************
* Local Variables
Expand Down Expand Up @@ -287,6 +288,7 @@ bool App::setupSerialMuxProt()
m_smpServer.subscribeToChannel(COMMAND_CHANNEL_NAME, App_cmdChannelCallback);
m_smpServer.subscribeToChannel(SPEED_SETPOINT_CHANNEL_NAME, App_motorSpeedSetpointsChannelCallback);
m_smpServer.subscribeToChannel(STATUS_CHANNEL_NAME, App_statusChannelCallback);
m_smpServer.subscribeToChannel(TURTLE_CHANNEL_NAME, App_turtleChannelCallback);

/* Channel creation. */
m_serialMuxProtChannelIdRemoteCtrlRsp =
Expand Down Expand Up @@ -384,3 +386,33 @@ void App_statusChannelCallback(const uint8_t* payload, const uint8_t payloadSize
application->systemStatusCallback(currentStatus->status);
}
}

/**
* 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] userData Instance of App class.
*/
void App_turtleChannelCallback(const uint8_t* payload, const uint8_t payloadSize, void* userData)
gabryelreyes marked this conversation as resolved.
Show resolved Hide resolved
{
(void)userData;
if ((nullptr != payload) && (TURTLE_CHANNEL_DLC == payloadSize))
{
const TurtleSpeed* turtleSpeedData = reinterpret_cast<const TurtleSpeed*>(payload);
DifferentialDrive& diffDrive = DifferentialDrive::getInstance();
int16_t angularSpeed = static_cast<int16_t>(turtleSpeedData->angular);

/* Convert to [steps/s] */
int16_t centerSpeed = Util::millimetersPerSecondToStepsPerSecond(turtleSpeedData->linearCenter);

/* Linear speed is set first. Overwrites all speed setpoints. */
diffDrive.setLinearSpeed(centerSpeed);
gabryelreyes marked this conversation as resolved.
Show resolved Hide resolved

/* Angular speed is set on-top of the linear speed. Must be called after setLinearSpeed(). */
diffDrive.setAngularSpeed(angularSpeed);

/* Turtle expects no initial data. Can be called without side-effects when no longer in StartupState. */
StartupState::getInstance().notifyInitialDataIsSet();
gabryelreyes marked this conversation as resolved.
Show resolved Hide resolved
}
}
13 changes: 13 additions & 0 deletions lib/APPRemoteControl/src/SerialMuxChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
/** 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 @@ -205,6 +211,13 @@ 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;
gabryelreyes marked this conversation as resolved.
Show resolved Hide resolved

/******************************************************************************
* Functions
*****************************************************************************/
Expand Down
7 changes: 7 additions & 0 deletions lib/MainNative/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <unistd.h>
#include <Arduino.h>
#include <Board.h>
#include <RobotDeviceNames.h>
Expand Down Expand Up @@ -77,6 +78,7 @@ static void systemDelay(unsigned long ms);
static const struct option LONG_OPTIONS[] = {{"help", no_argument, nullptr, 0},
{"serialRxCh", required_argument, nullptr, 0},
{"serialTxCh", required_argument, nullptr, 0},
{"cwd", required_argument, nullptr, 0},
{nullptr, no_argument, nullptr, 0}}; /* Marks the end. */

/** Program argument default value of the robot name. */
Expand Down Expand Up @@ -263,6 +265,10 @@ static int handleCommandLineArguments(PrgArguments& prgArguments, int argc, char
{
prgArguments.serialTxChannel = optarg;
}
else if (0 == strcmp(LONG_OPTIONS[optionIndex].name, "cwd"))
{
chdir(optarg);
gabryelreyes marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
status = -1;
Expand Down Expand Up @@ -307,6 +313,7 @@ static int handleCommandLineArguments(PrgArguments& prgArguments, int argc, char
printf("\t--serialTxCh <CHANNEL>\t\tSet serial tx channel (ZumoComSystem)."); /* Serial txchannel */
printf(" Default: %s\n", PRG_ARG_SERIAL_TX_CH_DEFAULT); /* Serial tx channel default value */
printf("\t-v\t\t\tVerbose mode. Default: Disabled\n"); /* Flag */
printf("\t--cwd <dir>\t\tSpecify working directory."); /* Set process working directory */
gabryelreyes marked this conversation as resolved.
Show resolved Hide resolved
}

return status;
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/src/Speedometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void Speedometer::process()

if (currentDrivingDirection != m_lastDirectionRight)
{
resetLeft = true;
resetRight = true;
}

m_lastDirectionRight = currentDrivingDirection;
Expand Down