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 Aug 25, 2019
1 parent e3d86fe commit 108eb04
Show file tree
Hide file tree
Showing 60 changed files with 2,924 additions and 2,862 deletions.
20 changes: 18 additions & 2 deletions wpilibc/src/main/native/cpp/GenericHID.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include "frc/GenericHID.h"

#include <cmath>

#include <hal/HAL.h>

#include "frc/DriverStation.h"
Expand Down Expand Up @@ -34,7 +36,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 { return m_ds.GetStickPOV(m_port, pov); }
Expand Down Expand Up @@ -83,3 +85,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 108eb04

Please sign in to comment.