Skip to content

Refactor directories and added a command and a filter#235

Open
imaspacecat wants to merge 9 commits intoFTCLib:devfrom
imaspacecat:dev
Open

Refactor directories and added a command and a filter#235
imaspacecat wants to merge 9 commits intoFTCLib:devfrom
imaspacecat:dev

Conversation

@imaspacecat
Copy link
Copy Markdown

Refactor: moved controller into math and added filter package.
Feat: added SlewRateLimiter filter and DelayedCommand command.

No breaking changes.

@imaspacecat imaspacecat changed the title Dev refactor directories and added a command and a filter Jan 14, 2023
@imaspacecat imaspacecat changed the title refactor directories and added a command and a filter Refactor directories and added a command and a filter Jan 14, 2023
@JIceberg
Copy link
Copy Markdown
Member

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){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space between open bracket and end of method header.

Comment on lines +2 to +4
// 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment should be multi-line at the top of the file, before the package statement.

Comment on lines +1 to +4
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix copyright statement location.

Comment on lines +1 to +3
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix statement location

Comment on lines +59 to +62
m_prevVal +=
MathUtils.clamp(input - m_prevVal,
m_negativeRateLimit * elapsedTime,
m_positiveRateLimit * elapsedTime);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
);

Comment on lines +56 to +60
() -> setCurrentTarget(junction),
() -> {},
interrupted -> {},
this::atTarget,
this
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much whitespace

Comment on lines +22 to +24
() -> drive.driveFieldCentric(strafeSpeed.getAsDouble(), forwardSpeed.getAsDouble(),
turnSpeed.getAsDouble(), gyroAngle.getAsDouble()),
this
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much whitespace

Comment on lines +31 to +33
() -> drive.driveRobotCentric(strafeSpeed.getAsDouble(), forwardSpeed.getAsDouble(),
turnSpeed.getAsDouble()),
this
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much whitespace

Comment on lines +53 to +55



Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much whitespace.

Comment on lines +18 to +116
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();
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more thorough comments to this file.

@Powercube7
Copy link
Copy Markdown
Contributor

I personally can't find the usefulness of the Powerplay sample, I'd suggest just removing it @JIceberg

@JIceberg
Copy link
Copy Markdown
Member

I think more samples are always good, they help users understand the usage of the library a bit more @Powercube7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants