Skip to content

Commit

Permalink
Clean up drive class implementations
Browse files Browse the repository at this point in the history
Left and right sides of the differential drive and mecanum drive classes
are now both forward and the "inversion multiplier" was removed.

The deadband functionality was moved to GenericHID::GetRawAxis() since
the deadband is generally applied to joystick axes.

MotorSafety was removed since that's handled by the drivetrain's motor
controllers already.

RobotDrive was removed because it's been deprecated for several years
and was only used in tests.
  • Loading branch information
calcmogul committed Apr 10, 2021
1 parent a1c87e1 commit 15da046
Show file tree
Hide file tree
Showing 54 changed files with 2,739 additions and 2,151 deletions.
20 changes: 19 additions & 1 deletion wpilibc/src/main/native/cpp/GenericHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "frc/GenericHID.h"

#include <cmath>

#include <hal/DriverStation.h>

#include "frc/DriverStation.h"
Expand Down Expand Up @@ -31,7 +33,7 @@ bool GenericHID::GetRawButtonReleased(int button) {
}

double GenericHID::GetRawAxis(int axis) const {
return m_ds->GetStickAxis(m_port, axis);
return ApplyDeadband(m_ds->GetStickAxis(m_port, axis), m_deadband);
}

int GenericHID::GetPOV(int pov) const {
Expand Down Expand Up @@ -95,3 +97,19 @@ void GenericHID::SetRumble(RumbleType type, double value) {
}
HAL_SetJoystickOutputs(m_port, m_outputs, m_leftRumble, m_rightRumble);
}

void GenericHID::SetAxisDeadband(double deadband) {
m_deadband = deadband;
}

double GenericHID::ApplyDeadband(double value, double deadband) {
if (std::abs(value) > deadband) {
if (value > 0.0) {
return (value - deadband) / (1.0 - deadband);
} else {
return (value + deadband) / (1.0 - deadband);
}
} else {
return 0.0;
}
}
Loading

0 comments on commit 15da046

Please sign in to comment.