Skip to content

Commit

Permalink
add makeshift motor rate limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
wusteven815 committed Apr 25, 2022
1 parent 43e3b4a commit 0888704
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/cpp/subsystems/Drivetrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "subsystems/Drivetrain.h"

#include <cmath>
#include <frc/Joystick.h>
#include <frc/smartdashboard/SmartDashboard.h>

Expand All @@ -23,7 +24,24 @@ Drivetrain::Drivetrain() {


void Drivetrain::Drive(double left, double right) {

if (left > m_lastSpeedLeft + m_speedRateLimit){
left = m_lastSpeedLeft + m_speedRateLimit;
} else if (left < m_lastSpeedLeft - m_speedRateLimit){
left = m_lastSpeedLeft - m_speedRateLimit;
}

if (right > m_lastSpeedRight + m_speedRateLimit){
right = m_lastSpeedRight + m_speedRateLimit;
} else if (right < m_lastSpeedRight - m_speedRateLimit){
right = m_lastSpeedRight - m_speedRateLimit;
}

m_robotDrive.TankDrive(-left, right);

m_lastSpeedLeft = left;
m_lastSpeedRight = right;

}


Expand Down
6 changes: 6 additions & 0 deletions src/main/include/subsystems/Drivetrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <AHRS.h>
#include <frc/controller/PIDController.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/filter/SlewRateLimiter.h>
#include <frc/SPI.h>
#include <frc2/command/SubsystemBase.h>
#include <rev/CANSparkMax.h>
Expand Down Expand Up @@ -36,6 +37,11 @@ class Drivetrain: public frc2::SubsystemBase {

frc::DifferentialDrive m_robotDrive{m_leftLeadMotor, m_rightLeadMotor};

// Makeshift Slew Rate Limiter
double m_lastSpeedLeft;
double m_lastSpeedRight;
const double m_speedRateLimit = 0.08;

public:

AHRS m_navX{frc::SPI::Port::kMXP};
Expand Down

0 comments on commit 0888704

Please sign in to comment.