From 363148bc9646b2599e790bf2e467a2d6c970025b Mon Sep 17 00:00:00 2001 From: Gabryel Reyes Date: Fri, 18 Oct 2024 10:53:42 +0200 Subject: [PATCH] Fixed review findings --- doc/architecture/README.md | 1 - lib/Service/src/DifferentialDrive.cpp | 15 ++++++++------- lib/Service/src/Util.h | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/architecture/README.md b/doc/architecture/README.md index bc74727..5e304d5 100644 --- a/doc/architecture/README.md +++ b/doc/architecture/README.md @@ -87,7 +87,6 @@ Linear speed right\ $v_R [\frac{steps}{s}] = \frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$ Consider robot linear speed center\ - Linear speed left\ $v_L [\frac{steps}{s}] = \frac{v_{Linear}}{2} [\frac{steps}{s}] -\frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$ diff --git a/lib/Service/src/DifferentialDrive.cpp b/lib/Service/src/DifferentialDrive.cpp index 2ce2c07..84861e3 100644 --- a/lib/Service/src/DifferentialDrive.cpp +++ b/lib/Service/src/DifferentialDrive.cpp @@ -245,13 +245,14 @@ DifferentialDrive::DifferentialDrive() : void DifferentialDrive::calculateLinearSpeedLeftRight(int16_t linearSpeedCenter, int16_t angularSpeed, int16_t& linearSpeedLeft, int16_t& linearSpeedRight) { - int32_t linearSpeedCenter32 = static_cast(linearSpeedCenter); /* [steps/s] */ - int32_t halfLinearSpeedCenter32 = linearSpeedCenter32 / 2; /* [steps/s] */ - int32_t angularSpeed32 = static_cast(angularSpeed); /* [mrad/s] */ - int32_t wheelBase32 = static_cast(RobotConstants::WHEEL_BASE); /* [mm] */ - int32_t encoderStepsPerM32 = static_cast(RobotConstants::ENCODER_STEPS_PER_M); /* [steps/m] */ - int32_t linearSpeedTurnInPlace32 = - (angularSpeed32 * wheelBase32 * encoderStepsPerM32) / static_cast(2000000); /* [steps/s] */ + static const int32_t ANGULAR_TO_LINEAR_SPEED_FACTOR = 2000000; /* 2 * 1000 mrad */ + int32_t linearSpeedCenter32 = static_cast(linearSpeedCenter); /* [steps/s] */ + int32_t halfLinearSpeedCenter32 = linearSpeedCenter32 / 2; /* [steps/s] */ + int32_t angularSpeed32 = static_cast(angularSpeed); /* [mrad/s] */ + int32_t wheelBase32 = static_cast(RobotConstants::WHEEL_BASE); /* [mm] */ + int32_t encoderStepsPerM32 = static_cast(RobotConstants::ENCODER_STEPS_PER_M); /* [steps/m] */ + int32_t linearSpeedTurnInPlace32 = (angularSpeed32 * wheelBase32 * encoderStepsPerM32) / + static_cast(ANGULAR_TO_LINEAR_SPEED_FACTOR); /* [steps/s] */ linearSpeedLeft = halfLinearSpeedCenter32 - linearSpeedTurnInPlace32; /* [steps/s] */ linearSpeedRight = halfLinearSpeedCenter32 + linearSpeedTurnInPlace32; /* [steps/s] */ diff --git a/lib/Service/src/Util.h b/lib/Service/src/Util.h index 566a3e5..179b717 100644 --- a/lib/Service/src/Util.h +++ b/lib/Service/src/Util.h @@ -118,9 +118,9 @@ namespace Util /** * Convert a speed in encoder steps per second to a speed in mm/s. * - * @param[in] speedStepsPerSec Speed in encoder steps per second + * @param[in] speedStepsPerSec Speed in encoder steps per second. * - * @return Speed in mm/s + * @return Speed in mm/s. */ inline int32_t stepsPerSecondToMillimetersPerSecond(int16_t speedStepsPerSec) { @@ -131,9 +131,9 @@ namespace Util /** * Convert a speed in mm/s to a speed in encoder steps per second. * - * @param[in] speedMmPerSec Speed in mm/s + * @param[in] speedMmPerSec Speed in mm/s. * - * @return Speed in encoder steps per second + * @return Speed in encoder steps per second. */ inline int16_t millimetersPerSecondToStepsPerSecond(int32_t speedMmPerSec) {