Skip to content

Commit

Permalink
Moved utils from source to header file to aid compiler optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
gabryelreyes committed Aug 16, 2024
1 parent 8784e9f commit 9570fe8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
12 changes: 0 additions & 12 deletions lib/Service/src/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* Includes
*****************************************************************************/
#include <Util.h>
#include <RobotConstants.h>

/******************************************************************************
* Compiler Switches
Expand Down Expand Up @@ -211,17 +210,6 @@ bool Util::isButtonTriggered(IButton& button, bool& lastState)
return isTriggered;
}

int32_t Util::stepsPerSecondToMillimetersPerSecond(int16_t speedStepsPerSec)
{
return (static_cast<int32_t>(speedStepsPerSec) * 1000 / static_cast<int32_t>(RobotConstants::ENCODER_STEPS_PER_M));
}

int16_t Util::millimetersPerSecondToStepsPerSecond(int32_t speedMmPerSec)
{
int32_t speedStepsPerSec = speedMmPerSec * static_cast<int32_t>(RobotConstants::ENCODER_STEPS_PER_M);
return (static_cast<int16_t>(speedStepsPerSec / 1000));
}

/******************************************************************************
* Local Functions
*****************************************************************************/
13 changes: 11 additions & 2 deletions lib/Service/src/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <IButton.h>
#include <RobotConstants.h>

/**
* Utilities
Expand Down Expand Up @@ -121,7 +122,11 @@ namespace Util
*
* @return Speed in mm/s
*/
int32_t stepsPerSecondToMillimetersPerSecond(int16_t speedStepsPerSec);
inline int32_t stepsPerSecondToMillimetersPerSecond(int16_t speedStepsPerSec)
{
return (static_cast<int32_t>(speedStepsPerSec) * 1000 /
static_cast<int32_t>(RobotConstants::ENCODER_STEPS_PER_M));
}

/**
* Convert a speed in mm/s to a speed in encoder steps per second.
Expand All @@ -130,7 +135,11 @@ namespace Util
*
* @return Speed in encoder steps per second
*/
int16_t millimetersPerSecondToStepsPerSecond(int32_t speedMmPerSec);
inline int16_t millimetersPerSecondToStepsPerSecond(int32_t speedMmPerSec)
{
int32_t speedStepsPerSec = speedMmPerSec * static_cast<int32_t>(RobotConstants::ENCODER_STEPS_PER_M);
return (static_cast<int16_t>(speedStepsPerSec / 1000));
}

} /* namespace Util */

Expand Down

0 comments on commit 9570fe8

Please sign in to comment.