Switch top and bottom buttons on the pistol grip
Signed-off-by: Maxwell Henderson <mxwhenderson@gmail.com>
Change-Id: Ie1ac2b96c01217c2f09284b5c32ac880221369f6
diff --git a/frc971/control_loops/drivetrain/drivetrain_config.h b/frc971/control_loops/drivetrain/drivetrain_config.h
index 51f92b1..9c17fc8 100644
--- a/frc971/control_loops/drivetrain/drivetrain_config.h
+++ b/frc971/control_loops/drivetrain/drivetrain_config.h
@@ -13,6 +13,28 @@
namespace control_loops {
namespace drivetrain {
+// What to use the top two buttons for on the pistol grip.
+enum class PistolTopButtonUse {
+ // Normal shifting.
+ kShift,
+ // Line following (currently just uses top button).
+ kLineFollow,
+ // Don't use the top button
+ kNone,
+};
+
+enum class PistolSecondButtonUse {
+ kTurn1,
+ kShiftLow,
+ kNone,
+};
+
+enum class PistolBottomButtonUse {
+ kControlLoopDriving,
+ kSlowDown,
+ kNone,
+};
+
enum class ShifterType : int32_t {
HALL_EFFECT_SHIFTER = 0, // Detect when inbetween gears.
SIMPLE_SHIFTER = 1, // Switch gears without speedmatch logic.
@@ -145,6 +167,10 @@
LineFollowConfig line_follow_config{};
+ PistolTopButtonUse top_button_use = PistolTopButtonUse::kShift;
+ PistolSecondButtonUse second_button_use = PistolSecondButtonUse::kShiftLow;
+ PistolBottomButtonUse bottom_button_use = PistolBottomButtonUse::kSlowDown;
+
// Converts the robot state to a linear distance position, velocity.
static Eigen::Matrix<Scalar, 2, 1> LeftRightToLinear(
const Eigen::Matrix<Scalar, 7, 1> &left_right) {
diff --git a/frc971/input/drivetrain_input.cc b/frc971/input/drivetrain_input.cc
index 69795dd..239eddf 100644
--- a/frc971/input/drivetrain_input.cc
+++ b/frc971/input/drivetrain_input.cc
@@ -262,7 +262,8 @@
std::unique_ptr<PistolDrivetrainInputReader> PistolDrivetrainInputReader::Make(
::aos::EventLoop *event_loop, bool default_high_gear,
- TopButtonUse top_button_use) {
+ PistolTopButtonUse top_button_use, PistolSecondButtonUse second_button_use,
+ PistolBottomButtonUse bottom_button_use) {
// Pistol Grip controller
const JoystickAxis kTriggerHigh(1, 1), kTriggerLow(1, 4),
kTriggerVelocityHigh(1, 2), kTriggerVelocityLow(1, 5),
@@ -275,6 +276,7 @@
const ButtonLocation kQuickTurn(1, 3);
const ButtonLocation kTopButton(1, 1);
+
const ButtonLocation kSecondButton(1, 2);
const ButtonLocation kBottomButton(1, 4);
// Non-existant button for nops.
@@ -282,17 +284,20 @@
// TODO(james): Make a copy assignment operator for ButtonLocation so we don't
// have to shoehorn in these ternary operators.
- const ButtonLocation kTurn1 = (top_button_use == TopButtonUse::kLineFollow)
- ? kSecondButton
- : kDummyButton;
+ const ButtonLocation kTurn1 =
+ (second_button_use == PistolSecondButtonUse::kTurn1) ? kSecondButton
+ : kDummyButton;
// Turn2 does closed loop driving.
const ButtonLocation kTurn2 =
- (top_button_use == TopButtonUse::kLineFollow) ? kTopButton : kDummyButton;
+ (top_button_use == PistolTopButtonUse::kLineFollow) ? kTopButton
+ : kDummyButton;
const ButtonLocation kShiftHigh =
- (top_button_use == TopButtonUse::kShift) ? kTopButton : kDummyButton;
+ (top_button_use == PistolTopButtonUse::kShift) ? kTopButton
+ : kDummyButton;
const ButtonLocation kShiftLow =
- (top_button_use == TopButtonUse::kShift) ? kSecondButton : kDummyButton;
+ (second_button_use == PistolSecondButtonUse::kShiftLow) ? kSecondButton
+ : kDummyButton;
std::unique_ptr<PistolDrivetrainInputReader> result(
new PistolDrivetrainInputReader(
@@ -300,7 +305,12 @@
kTriggerVelocityLow, kTriggerTorqueHigh, kTriggerTorqueLow,
kTriggerHigh, kTriggerLow, kWheelVelocityHigh, kWheelVelocityLow,
kWheelTorqueHigh, kWheelTorqueLow, kQuickTurn, kShiftHigh, kShiftLow,
- kTurn1, kTurn2, kBottomButton));
+ kTurn1,
+ (bottom_button_use == PistolBottomButtonUse::kControlLoopDriving)
+ ? kBottomButton
+ : kTurn2,
+ (top_button_use == PistolTopButtonUse::kNone) ? kTopButton
+ : kBottomButton));
result->set_default_high_gear(default_high_gear);
return result;
@@ -335,13 +345,25 @@
drivetrain_input_reader = SteeringWheelDrivetrainInputReader::Make(
event_loop, dt_config.default_high_gear);
break;
- case InputType::kPistol:
- drivetrain_input_reader = PistolDrivetrainInputReader::Make(
- event_loop, dt_config.default_high_gear,
+ case InputType::kPistol: {
+ // For backwards compatibility
+ PistolTopButtonUse top_button_use =
dt_config.pistol_grip_shift_enables_line_follow
- ? PistolDrivetrainInputReader::TopButtonUse::kLineFollow
- : PistolDrivetrainInputReader::TopButtonUse::kShift);
+ ? PistolTopButtonUse::kLineFollow
+ : dt_config.top_button_use;
+
+ PistolSecondButtonUse second_button_use = dt_config.second_button_use;
+ PistolBottomButtonUse bottom_button_use = dt_config.bottom_button_use;
+
+ if (top_button_use == PistolTopButtonUse::kLineFollow) {
+ second_button_use = PistolSecondButtonUse::kTurn1;
+ }
+
+ drivetrain_input_reader = PistolDrivetrainInputReader::Make(
+ event_loop, dt_config.default_high_gear, top_button_use,
+ second_button_use, bottom_button_use);
break;
+ }
case InputType::kXbox:
drivetrain_input_reader = XboxDrivetrainInputReader::Make(event_loop);
break;
diff --git a/frc971/input/drivetrain_input.h b/frc971/input/drivetrain_input.h
index a33d449..0cb724d 100644
--- a/frc971/input/drivetrain_input.h
+++ b/frc971/input/drivetrain_input.h
@@ -16,6 +16,10 @@
namespace frc971 {
namespace input {
+using control_loops::drivetrain::PistolBottomButtonUse;
+using control_loops::drivetrain::PistolSecondButtonUse;
+using control_loops::drivetrain::PistolTopButtonUse;
+
// We have a couple different joystick configurations used to drive our skid
// steer robots. These configurations don't change very often, and there are a
// small, discrete, set of them. The interface to the drivetrain is the same
@@ -179,19 +183,13 @@
public:
using DrivetrainInputReader::DrivetrainInputReader;
- // What to use the top two buttons for on the pistol grip.
- enum class TopButtonUse {
- // Normal shifting.
- kShift,
- // Line following (currently just uses top button).
- kLineFollow,
- };
-
// Creates a DrivetrainInputReader with the corresponding joystick ports and
// axis for the (cheap) pistol grip controller.
static std::unique_ptr<PistolDrivetrainInputReader> Make(
::aos::EventLoop *event_loop, bool default_high_gear,
- TopButtonUse top_button_use);
+ PistolTopButtonUse top_button_use,
+ PistolSecondButtonUse second_button_use,
+ PistolBottomButtonUse bottom_button_use);
private:
PistolDrivetrainInputReader(
diff --git a/y2023/control_loops/drivetrain/drivetrain_base.cc b/y2023/control_loops/drivetrain/drivetrain_base.cc
index 4efba61..a11a896 100644
--- a/y2023/control_loops/drivetrain/drivetrain_base.cc
+++ b/y2023/control_loops/drivetrain/drivetrain_base.cc
@@ -76,6 +76,10 @@
.finished()
.asDiagonal()),
.max_controllable_offset = 0.5},
+ frc971::control_loops::drivetrain::PistolTopButtonUse::kNone,
+ frc971::control_loops::drivetrain::PistolSecondButtonUse::kTurn1,
+ frc971::control_loops::drivetrain::PistolBottomButtonUse::
+ kControlLoopDriving,
};
return kDrivetrainConfig;