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 Dec 28, 2020
1 parent 574a42f commit c0af475
Show file tree
Hide file tree
Showing 52 changed files with 2,733 additions and 2,026 deletions.
18 changes: 17 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,17 @@ 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 c0af475

Please sign in to comment.