Refactor directories and added a command and a filter#235
Refactor directories and added a command and a filter#235imaspacecat wants to merge 9 commits intoFTCLib:devfrom
Conversation
|
For perspective -- this is a breaking change, as the change in directories makes it no longer backwards compatible with projects that used the older imports. |
| * @param command the command to execute | ||
| * @param delay the time until execution of the command occurs, in milliseconds | ||
| */ | ||
| public DelayedCommand(Command command, long delay){ |
There was a problem hiding this comment.
Add space between open bracket and end of method header.
| // Copyright (c) FIRST and other WPILib contributors. | ||
| // Open Source Software; you can modify and/or share it under the terms of | ||
| // the WPILib BSD license file in the root directory of this project. |
There was a problem hiding this comment.
Comment should be multi-line at the top of the file, before the package statement.
| package com.arcrobotics.ftclib.command; | ||
| // Copyright (c) FIRST and other WPILib contributors. | ||
| // Open Source Software; you can modify and/or share it under the terms of | ||
| // the WPILib BSD license file in the root directory of this project. |
There was a problem hiding this comment.
Fix copyright statement location.
| package com.arcrobotics.ftclib.math.filter;// Copyright (c) FIRST and other WPILib contributors. | ||
| // Open Source Software; you can modify and/or share it under the terms of | ||
| // the WPILib BSD license file in the root directory of this project. |
| m_prevVal += | ||
| MathUtils.clamp(input - m_prevVal, | ||
| m_negativeRateLimit * elapsedTime, | ||
| m_positiveRateLimit * elapsedTime); |
There was a problem hiding this comment.
| m_prevVal += | |
| MathUtils.clamp(input - m_prevVal, | |
| m_negativeRateLimit * elapsedTime, | |
| m_positiveRateLimit * elapsedTime); | |
| m_prevVal += MathUtils.clamp( | |
| input - m_prevVal, | |
| m_negativeRateLimit * elapsedTime, | |
| m_positiveRateLimit * elapsedTime | |
| ); |
| () -> setCurrentTarget(junction), | ||
| () -> {}, | ||
| interrupted -> {}, | ||
| this::atTarget, | ||
| this |
| () -> drive.driveFieldCentric(strafeSpeed.getAsDouble(), forwardSpeed.getAsDouble(), | ||
| turnSpeed.getAsDouble(), gyroAngle.getAsDouble()), | ||
| this |
| () -> drive.driveRobotCentric(strafeSpeed.getAsDouble(), forwardSpeed.getAsDouble(), | ||
| turnSpeed.getAsDouble()), | ||
| this |
|
|
||
|
|
||
|
|
| public class PowerPlayTeleOp extends CommandOpMode { | ||
|
|
||
| private MotorEx frontLeft, frontRight, backLeft, backRight, liftLeft, liftRight; | ||
| private SimpleServo clawServo; | ||
| private RevIMU imu; | ||
|
|
||
| private ClawSubsystem claw; | ||
| private LiftSubsystem lift; | ||
| private MecanumSubsystem drive; | ||
|
|
||
| private GamepadEx gamepadEx1, gamepadEx2; | ||
|
|
||
|
|
||
| @Override | ||
| public void initialize() { | ||
| gamepadEx1 = new GamepadEx(gamepad1); | ||
| gamepadEx2 = new GamepadEx(gamepad2); | ||
|
|
||
| initHardware(); | ||
| setUpHardware(); | ||
|
|
||
| claw = new ClawSubsystem(clawServo); | ||
| lift = new LiftSubsystem(liftLeft, liftRight); | ||
| drive = new MecanumSubsystem(frontLeft, frontRight, backLeft, backRight); | ||
|
|
||
| telemetry.addData("Mode", "Done initializing"); | ||
| telemetry.update(); | ||
|
|
||
| gamepadEx2.getGamepadButton(RIGHT_BUMPER) | ||
| .toggleWhenPressed(claw.runGrabCommand(), claw.runReleaseCommand()); | ||
| gamepadEx2.getGamepadButton(A).whenPressed(lift.goTo(Junction.NONE)); | ||
| gamepadEx2.getGamepadButton(DPAD_DOWN).whenPressed(lift.goTo(Junction.GROUND)); | ||
| gamepadEx2.getGamepadButton(X).whenPressed(lift.goTo(Junction.LOW)); | ||
| gamepadEx2.getGamepadButton(B).whenPressed(lift.goTo(Junction.MEDIUM)); | ||
| gamepadEx2.getGamepadButton(Y).whenPressed(lift.goTo(Junction.HIGH)); | ||
|
|
||
|
|
||
|
|
||
| register(claw, lift, drive); | ||
| drive.setDefaultCommand(drive.robotCentric(gamepadEx1::getLeftX, | ||
| gamepadEx1::getLeftY, gamepadEx1::getRightX)); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Instantiate hardware devices | ||
| */ | ||
| private void initHardware() { | ||
| frontLeft = new MotorEx(hardwareMap, "frontLeft"); | ||
| frontRight = new MotorEx(hardwareMap, "frontRight"); | ||
| backLeft = new MotorEx(hardwareMap, "backLeft"); | ||
| backRight = new MotorEx(hardwareMap, "backRight"); | ||
|
|
||
| liftLeft = new MotorEx(hardwareMap, "liftLeft"); | ||
| liftRight = new MotorEx(hardwareMap, "liftRight"); | ||
|
|
||
| clawServo = new SimpleServo(hardwareMap, "claw", 0, 120); | ||
|
|
||
| imu = new RevIMU(hardwareMap); | ||
| imu.init(); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse any motors, set behaviors, etc | ||
| */ | ||
| private void setUpHardware(){ | ||
| frontLeft.setZeroPowerBehavior(Motor.ZeroPowerBehavior.BRAKE); | ||
| frontRight.setZeroPowerBehavior(Motor.ZeroPowerBehavior.BRAKE); | ||
| backLeft.setZeroPowerBehavior(Motor.ZeroPowerBehavior.BRAKE); | ||
| backRight.setZeroPowerBehavior(Motor.ZeroPowerBehavior.BRAKE); | ||
|
|
||
| liftLeft.setRunMode(Motor.RunMode.RawPower); | ||
| liftRight.setRunMode(Motor.RunMode.RawPower); | ||
| liftLeft.resetEncoder(); | ||
| liftRight.resetEncoder(); | ||
| } | ||
|
|
||
| /** | ||
| * Update telemetry | ||
| */ | ||
| @Override | ||
| public void run() { | ||
| super.run(); | ||
| telemetry.addData("frontLeft Power", frontLeft.motor.getPower()); | ||
| telemetry.addData("frontRight Power", frontRight.motor.getPower()); | ||
| telemetry.addData("backLeft Power", backLeft.motor.getPower()); | ||
| telemetry.addData("backRight Power", backRight.motor.getPower()); | ||
|
|
||
| telemetry.addData("liftLeft Power", liftLeft.motor.getPower()); | ||
| telemetry.addData("liftRight Power", liftRight.motor.getPower()); | ||
| telemetry.addData("liftLeft Position", liftLeft.getCurrentPosition()); | ||
| telemetry.addData("liftRight Position", liftRight.getCurrentPosition()); | ||
|
|
||
| telemetry.addData("Servo Position", clawServo.getPosition()); | ||
| telemetry.addData("Current Junction", lift.getCurrentTarget()); | ||
|
|
||
| telemetry.update(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Please add more thorough comments to this file.
|
I personally can't find the usefulness of the Powerplay sample, I'd suggest just removing it @JIceberg |
|
I think more samples are always good, they help users understand the usage of the library a bit more @Powercube7 |
Refactor: moved controller into math and added filter package.
Feat: added SlewRateLimiter filter and DelayedCommand command.
No breaking changes.