[wpilib] Enable ArmSubsystem in ArmBot example (#2752)

This commit is contained in:
Prateek Machiraju
2020-10-01 23:03:50 -04:00
committed by GitHub
parent 693daafe29
commit 330b90e046
5 changed files with 50 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2020 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. */
@@ -54,6 +54,7 @@ public class Robot extends TimedRobot {
*/
@Override
public void disabledInit() {
m_robotContainer.disablePIDSubsystems();
}
@Override

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2019-2020 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. */
@@ -62,11 +62,21 @@ public class RobotContainer {
// Move the arm to 2 radians above horizontal when the 'A' button is pressed.
new JoystickButton(m_driverController, Button.kA.value)
.whenPressed(() -> m_robotArm.setGoal(2), m_robotArm);
.whenPressed(() -> {
m_robotArm.setGoal(2);
m_robotArm.enable();
}, m_robotArm);
// Move the arm to neutral position when the 'B' button is pressed.
new JoystickButton(m_driverController, Button.kB.value)
.whenPressed(() -> m_robotArm.setGoal(Constants.ArmConstants.kArmOffsetRads), m_robotArm);
.whenPressed(() -> {
m_robotArm.setGoal(Constants.ArmConstants.kArmOffsetRads);
m_robotArm.enable();
}, m_robotArm);
// Disable the arm controller when Y is pressed.
new JoystickButton(m_driverController, Button.kY.value)
.whenPressed(m_robotArm::disable);
// Drive at half speed when the bumper is held
new JoystickButton(m_driverController, Button.kBumperRight.value)
@@ -74,6 +84,13 @@ public class RobotContainer {
.whenReleased(() -> m_robotDrive.setMaxOutput(1));
}
/**
* Disables all ProfiledPIDSubsystem and PIDSubsystem instances. This
* should be called on robot disable to prevent integral windup.
*/
public void disablePIDSubsystems() {
m_robotArm.disable();
}
/**
* Use this to pass the autonomous command to the main {@link Robot} class.