Skip to content

Commit

Permalink
Reordering of logic for #24
Browse files Browse the repository at this point in the history
Only do work if we need to move.
Also remove redundant deadzone checking
  • Loading branch information
FriedLongJohns committed Mar 9, 2024
1 parent 1348108 commit 2fd9430
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
18 changes: 9 additions & 9 deletions src/main/java/org/carlmontrobotics/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ private void setDefaultCommands() {
// () -> driverController.getRawButton(OI.Driver.slowDriveButton)
// ));

arm.setDefaultCommand(new ArmTeleop(arm,
() -> DeadzonedAxis(inputProcessing(getStickValue(manipulatorController, Axis.kLeftY)))));
arm.setDefaultCommand(new ArmTeleop(arm,
() -> ProcessedAxisValue(manipulatorController, Axis.kLeftY);
}

private void setBindingsDriver() {
Expand Down Expand Up @@ -123,7 +123,7 @@ public Command getAutonomousCommand() {
/**
* Flips an axis' Y coordinates upside down, but only if the select axis is a
* joystick axis
*
*
* @param hid The controller/plane joystick the axis is on
* @param axis The processed axis
* @return The processed value.
Expand All @@ -135,7 +135,7 @@ private double getStickValue(GenericHID hid, Axis axis) {
/**
* Processes an input from the joystick into a value between -1 and 1,
* sinusoidally instead of linearly
*
*
* @param value The value to be processed.
* @return The processed value.
*/
Expand All @@ -151,25 +151,25 @@ private double inputProcessing(double value) {
/**
* Combines both getStickValue and inputProcessing into a single function for
* processing joystick outputs
*
*
* @param hid The controller/plane joystick the axis is on
* @param axis The processed axis
* @return The processed value.
*/
private double ProcessedAxisValue(GenericHID hid, Axis axis) {
return inputProcessing(getStickValue(hid, axis));
return DeadzonedAxis(inputProcessing(getStickValue(hid, axis)));
}

/**
* Returns zero if a axis input is inside the deadzone
*
*
* @param hid The controller/plane joystick the axis is on
* @param axis The processed axis
* @return The processed value.
*/
private double DeadzonedAxis(double axOut) {
return (-OI.JOY_THRESH < axOut && axOut < OI.JOY_THRESH) ? 0.0 : axOut;
return (Math.abs(axOut) <= OI.JOY_THRESH) ? 0.0 : axOut;
}


}
24 changes: 11 additions & 13 deletions src/main/java/org/carlmontrobotics/commands/ArmTeleop.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ public void execute() {
// use trapazoid math and controllerMoveArm method from arm subsytem to apply
// voltage to the motor
double speeds = getRequestedSpeeds();
double currTime = Timer.getFPGATimestamp();
double deltaT = currTime - lastTime;
lastTime = currTime;
if (speeds == 0){// If no input, return so that the actual goal set by the instant command wouldn't be overriden, can be further explained in this issue: https://github.com/DeepBlueRobotics/RobotCode2024/issues/24

if (speeds == 0){//if no input, don't set any goals.
lastTime = Timer.getFPGATimestamp();
return;
}
double goalArmRad = goalState.position + speeds * deltaT;

double currTime = Timer.getFPGATimestamp();
double deltaT = currTime - lastTime;//only move by a tick of distance at once
lastTime = currTime;

double goalArmRad = goalState.position + speeds * deltaT;//speed*time = dist

goalArmRad = MathUtil.clamp(goalArmRad, UPPER_ANGLE_LIMIT_RAD, LOWER_ANGLE_LIMIT_RAD);
goalArmRad = MathUtil.clamp(goalArmRad, armSubsystem.getArmPos() + ARM_TELEOP_MAX_GOAL_DIFF_FROM_CURRENT_RAD,
armSubsystem.getArmPos() - ARM_TELEOP_MAX_GOAL_DIFF_FROM_CURRENT_RAD);
Expand All @@ -64,14 +69,7 @@ public void execute() {
}

public double getRequestedSpeeds() {
double rawArmVel;
if (Math.abs(joystick.getAsDouble()) <= Constants.OI.JOY_THRESH) {
rawArmVel = 0.0;
} else {
rawArmVel = armSubsystem.getMaxAccelRad() * joystick.getAsDouble();
}

return rawArmVel;
return armSubsystem.getMaxAccelRad() * joystick.getAsDouble();
}

// Called once the command ends or is interrupted.
Expand Down

0 comments on commit 2fd9430

Please sign in to comment.