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
21 changes: 8 additions & 13 deletions lib/APPRemoteControl/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ void App::handleRemoteCommand(const Command& cmd)
Odometry::getInstance().clearMileage();
Odometry::getInstance().setPosition(cmd.xPos, cmd.yPos);
Odometry::getInstance().setOrientation(cmd.orientation);

StartupState::getInstance().notifyInitialDataIsSet();
break;

default:
Expand Down Expand Up @@ -286,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 @@ -363,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);
gabryelreyes marked this conversation as resolved.
Show resolved Hide resolved
DrivingState::getInstance().setTargetSpeeds(motorSpeedData->left, motorSpeedData->right);
}
}
Expand All @@ -390,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)
gabryelreyes marked this conversation as resolved.
Show resolved Hide resolved
{
(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 All @@ -411,8 +409,5 @@ void App_turtleChannelCallback(const uint8_t* payload, const uint8_t payloadSize

/* 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();
}
}
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
2 changes: 1 addition & 1 deletion lib/APPRemoteControl/src/StartupState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void StartupState::process(StateMachine& sm)
ErrorState::getInstance().setErrorMsg("MCAL=0");
sm.setState(&ErrorState::getInstance());
}
else if (true == m_initialDataSet)
else
{
sm.setState(&DrivingState::getInstance());
}
Expand Down
15 changes: 1 addition & 14 deletions lib/APPRemoteControl/src/StartupState.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,17 @@ class StartupState : public IState
*/
void exit() final;

/**
* Notify the state, that the initial data set was received.
*/
void notifyInitialDataIsSet()
{
m_initialDataSet = true;
}

protected:
private:
/**
* Duration in ms how long the application name shall be shown at startup.
*/
static const uint32_t APP_NAME_DURATION = 2000U;

/**
* Flag to indicate, that the initial data was set.
*/
bool m_initialDataSet;

/**
* Default constructor.
*/
StartupState() : m_initialDataSet(false)
StartupState()
{
}

Expand Down