diff --git a/src/main/java/com/spartronics4915/frc/RobotContainer.java b/src/main/java/com/spartronics4915/frc/RobotContainer.java index 03bef79..027c973 100644 --- a/src/main/java/com/spartronics4915/frc/RobotContainer.java +++ b/src/main/java/com/spartronics4915/frc/RobotContainer.java @@ -2,7 +2,7 @@ import com.spartronics4915.frc.Constants; import com.spartronics4915.frc.commands.ExampleCommand; -import com.spartronics4915.frc.commands.JoystickMotorCommands; +import com.spartronics4915.frc.commands.JoystickMotorCommand; import com.spartronics4915.frc.subsystems.ExampleSubsystem; import com.spartronics4915.frc.subsystems.JoystickMotor; import com.spartronics4915.lib.subsystems.SpartronicsSubsystem; @@ -34,7 +34,7 @@ public class RobotContainer public final JoystickMotor mJoystickMotor; // public final ExampleCommand mAutoCommand; - public final JoystickMotorCommands mJoystickMotorCommands; + public final JoystickMotorCommand mJoystickMotorCommands; // private final int kJoystickPort = Constants.OI.kJoystickId; public static final Joystick mDriverController = new Joystick(Constants.OI.kJoystickId); @@ -49,12 +49,12 @@ public RobotContainer() // mAutoCommand = new ExampleCommand(mExampleSubsystem); mJoystickMotor = JoystickMotor.getInstance(); - mJoystickMotorCommands = new JoystickMotorCommands(mJoystickMotor); + mJoystickMotorCommands = new JoystickMotorCommand(mJoystickMotor); configureButtonBindings(); SmartDashboard.putString("Container","Completed"); - mJoystickMotor.setDefaultCommand(new JoystickMotorCommands(mJoystickMotor)); + mJoystickMotor.setDefaultCommand(new JoystickMotorCommand(mJoystickMotor)); } /** Use this method to define your button ==> command mappings. */ diff --git a/src/main/java/com/spartronics4915/frc/commands/JoystickMotorCommand.java b/src/main/java/com/spartronics4915/frc/commands/JoystickMotorCommand.java new file mode 100644 index 0000000..a372a47 --- /dev/null +++ b/src/main/java/com/spartronics4915/frc/commands/JoystickMotorCommand.java @@ -0,0 +1,54 @@ +package com.spartronics4915.frc.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; +import edu.wpi.first.wpilibj.Joystick; + +import com.spartronics4915.frc.Constants; +import com.spartronics4915.frc.subsystems.JoystickMotor; + +public class JoystickMotorCommand extends CommandBase +{ + private final JoystickMotor mJoystickMotor; + private final Joystick mJoystick; + private boolean mInverted; + private boolean mSlow; + + public JoystickMotorCommand(JoystickMotor motor) + { + mJoystickMotor = motor; + mJoystick = motor.getJoystick(); + mInverted = false; + mSlow = false; + addRequirements(mJoystickMotor); + } + + @Override + public void execute() + { + double y = -1 * mJoystick.getY(); + + if (mSlow) + { + y *= Constants.JoystickMotorConstants.kMotorSlowSpeed; + } + + if (mInverted) + { + y *= -1; + } + + // copied from 2020-InfiniteRecharge, no idea how it works (magic) + y = Math.copySign(Math.pow(Math.abs(y), 5.0/3.0), y); // apply response curve + mJoystickMotor.set(applyDeadzone(y, Constants.JoystickMotorConstants.kJoystickDeadzone)); + } + + // also copied from ir2020 + private double applyDeadzone(double val, double deadzone) + { + if (Math.abs(val) < deadzone) + { + return 0.0; + } + return val; + } +} diff --git a/src/main/java/com/spartronics4915/frc/commands/JoystickMotorCommands.java b/src/main/java/com/spartronics4915/frc/commands/JoystickMotorCommands.java deleted file mode 100644 index 00b55d1..0000000 --- a/src/main/java/com/spartronics4915/frc/commands/JoystickMotorCommands.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.spartronics4915.frc.commands; - -import edu.wpi.first.wpilibj2.command.CommandBase; -import edu.wpi.first.wpilibj.Joystick; - -import com.spartronics4915.frc.Constants; -import com.spartronics4915.frc.subsystems.JoystickMotor; - -public class JoystickMotorCommands extends CommandBase -{ - private final JoystickMotor mJoystickMotor; - private final Joystick mJoystick; - private boolean mInverted; - private boolean mSlow; - - public JoystickMotorCommands(JoystickMotor motor) - { - mJoystickMotor = motor; - mJoystick = motor.getJoystick(); - mInverted = false; - mSlow = false; - } - - public class TeleOpCommand extends CommandBase - { - public TeleOpCommand() - { - addRequirements(mJoystickMotor); - } - - @Override - public void execute() - { - double y = -1 * mJoystick.getY(); - - if (mSlow) - { - y *= Constants.JoystickMotorConstants.kMotorSlowSpeed; - } - - if (mInverted) - { - y *= -1; - } - - // copied from 2020-InfiniteRecharge, no idea how it works (magic) - y = Math.copySign(Math.pow(Math.abs(y), 5.0/3.0), y); // apply response curve - mJoystickMotor.set(applyDeadzone(y, Constants.JoystickMotorConstants.kJoystickDeadzone)); - } - - // also copied from ir2020 - private double applyDeadzone(double val, double deadzone) - { - if (Math.abs(val) < deadzone) - { - return 0.0; - } - return val; - } - } -}