Skip to content

Commit

Permalink
Reporting Motor Speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
gabryelreyes committed Oct 27, 2023
1 parent 4ba20a6 commit 7c78792
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
22 changes: 17 additions & 5 deletions lib/ConvoyLeader/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ void App::setup()
m_systemStateMachine.setState(&StartupState::getInstance());
m_controlInterval.start(DIFFERENTIAL_DRIVE_CONTROL_PERIOD);
m_serialMuxProtChannelIdOdometry = m_smpServer.createChannel(ODOMETRY_CHANNEL_NAME, ODOMETRY_CHANNEL_DLC);
m_serialMuxProtChannelIdSpeed = m_smpServer.createChannel(SPEED_CHANNEL_NAME, SPEED_CHANNEL_DLC);

/* Channel sucesfully created? */
if (0U != m_serialMuxProtChannelIdOdometry)
{
m_reportOdometryTimer.start(REPORT_ODOMETRY_PERIOD);
m_reportTimer.start(REPORTING_PERIOD);
}
}

Expand All @@ -102,12 +103,13 @@ void App::loop()
m_controlInterval.restart();
}

if (true == m_reportOdometryTimer.isTimeout())
if (true == m_reportTimer.isTimeout())
{
/* Send Odometry to SerialMuxProt Client */
/* Send current data to SerialMuxProt Client */
reportOdometry();
reportSpeed();

m_reportOdometryTimer.restart();
m_reportTimer.restart();
}

m_systemStateMachine.process();
Expand All @@ -133,7 +135,17 @@ void App::reportOdometry()
payload.yPos = yPos;
payload.orientation = odometry.getOrientation();

m_smpServer.sendData(ODOMETRY_CHANNEL_NAME, reinterpret_cast<uint8_t*>(&payload), sizeof(payload));
m_smpServer.sendData(m_serialMuxProtChannelIdOdometry, reinterpret_cast<uint8_t*>(&payload), sizeof(payload));
}

void App::reportSpeed()
{
Speedometer& speedometer = Speedometer::getInstance();
SpeedData payload;
payload.left = speedometer.getLinearSpeedLeft();
payload.right = speedometer.getLinearSpeedRight();

m_smpServer.sendData(m_serialMuxProtChannelIdSpeed, reinterpret_cast<uint8_t*>(&payload), sizeof(payload));
}

/******************************************************************************
Expand Down
20 changes: 15 additions & 5 deletions lib/ConvoyLeader/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ class App
*/
App() :
m_serialMuxProtChannelIdOdometry(0U),
m_serialMuxProtChannelIdSpeed(0U),
m_systemStateMachine(),
m_controlInterval(),
m_reportOdometryTimer(),
m_reportTimer(),
m_smpServer(Serial)
{
}
Expand All @@ -93,23 +94,26 @@ class App
/** Differential drive control period in ms. */
static const uint32_t DIFFERENTIAL_DRIVE_CONTROL_PERIOD = 5U;

/** Odometry reporting period in ms. */
static const uint32_t REPORT_ODOMETRY_PERIOD = 100U;
/** Current data reporting period in ms. */
static const uint32_t REPORTING_PERIOD = 100U;

/** Baudrate for Serial Communication */
static const uint32_t SERIAL_BAUDRATE = 115200U;

/** SerialMuxProt Channel id for sending the current odometry. */
uint8_t m_serialMuxProtChannelIdOdometry;

/** SerialMuxProt Channel id for sending the current speed. */
uint8_t m_serialMuxProtChannelIdSpeed;

/** The system state machine. */
StateMachine m_systemStateMachine;

/** Timer used for differential drive control processing. */
SimpleTimer m_controlInterval;

/** Timer for reporting odometry through SerialMuxProt. */
SimpleTimer m_reportOdometryTimer;
/** Timer for reporting current data through SerialMuxProt. */
SimpleTimer m_reportTimer;

/**
* SerialMuxProt Server Instance
Expand All @@ -125,6 +129,12 @@ class App
*/
void reportOdometry();

/**
* Report the current motor speeds of the robot using the Speedometer data.
* Sends data through the SerialMuxProtServer.
*/
void reportSpeed();

private:
/* An instance shall not be copied or assigned. */
App(const App& app);
Expand Down
15 changes: 14 additions & 1 deletion lib/ConvoyLeader/SerialMuxChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ SOFTWARE.
#define ODOMETRY_CHANNEL_NAME "ODOMETRY"

/** DLC of Odometry Channel */
#define ODOMETRY_CHANNEL_DLC (12U)
#define ODOMETRY_CHANNEL_DLC (sizeof(OdometryData))

/** Name of Channel to send Speedometer Data to. */
#define SPEED_CHANNEL_NAME "SPEED"

/** DLC of Speedometer Channel */
#define SPEED_CHANNEL_DLC (sizeof(SpeedData))

/******************************************************************************
* Types and Classes
Expand All @@ -61,6 +67,13 @@ typedef struct _OdometryData
int32_t orientation;
} __attribute__((packed)) OdometryData;

/** Struct of the "Speed" channel payload. */
typedef struct _SpeedData
{
int16_t left;
int16_t right;
} __attribute__((packed)) SpeedData;

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

0 comments on commit 7c78792

Please sign in to comment.