This repository has been archived by the owner on Jul 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7252c55
commit ac95bb5
Showing
11 changed files
with
166 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/org/team1540/elmo/subsystems/drivetrain/BobaTankDrive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.team1540.elmo.subsystems.drivetrain; | ||
|
||
import edu.wpi.first.wpilibj.XboxController; | ||
import edu.wpi.first.wpilibj2.command.CommandBase; | ||
import org.team1540.elmo.utils.SignedSlewRateLimiter; | ||
|
||
/** | ||
* Standard drive, left stick controls left side of drivetrain, right stick controls right side. | ||
*/ | ||
public class BobaTankDrive extends CommandBase { | ||
|
||
private final DriveTrain drivetrain; | ||
private final XboxController controller; | ||
private final double deadzone = 0.15; | ||
|
||
private final SignedSlewRateLimiter speedRateLimiter = new SignedSlewRateLimiter(2,2); | ||
private final SignedSlewRateLimiter spinRateLimiter = new SignedSlewRateLimiter(3,3); | ||
|
||
public BobaTankDrive(DriveTrain drivetrain, XboxController controller) { | ||
this.drivetrain = drivetrain; | ||
this.controller = controller; | ||
addRequirements(drivetrain); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
double left = Math.abs(controller.getLeftY()) > deadzone ? controller.getLeftY() : 0; | ||
double right = Math.abs(controller.getRightY()) > deadzone ? controller.getRightY() : 0; | ||
// double forward = Math.abs(controller.getRightTriggerAxis()) > deadzone ? Math.pow(controller.getRightTriggerAxis(), 3) : 0; | ||
// double backward = Math.abs(controller.getLeftTriggerAxis()) > deadzone ? Math.pow(controller.getLeftTriggerAxis(), 3) : 0; | ||
// double multiplier = 0.5 - ((0.3 * elevator.getRotations())/ElevatorConstants.ELEVATOR_ROTS_TO_TOP); | ||
// speedRateLimiter.setAccelerationLimit(2-(elevatorPercentHeight*1)); // at bottom = 2-0%*1, at top: 2-100%*1 | ||
|
||
double speed = (left + right) / 2; | ||
double spin = left - speed; // this changes sign lol | ||
/// | ||
speed = Math.pow(speed,2) * Math.signum(speed); | ||
|
||
spin = Math.pow(spin,2) * Math.signum(spin); | ||
spin = spin/2; | ||
/// | ||
double rateLimitedSpeed = speedRateLimiter.calculate(speed); | ||
double rateLimitedSpin = spinRateLimiter.calculate(spin); | ||
|
||
// double rateLimitedLeft = speed + spin; | ||
// double rateLimitedRight = speed - spin; | ||
double rateLimitedLeft = rateLimitedSpeed + rateLimitedSpin; | ||
double rateLimitedRight = rateLimitedSpeed - rateLimitedSpin; | ||
|
||
// drivetrain.setPercent(multiplier*(-1*left + forward - backward), multiplier*(-1*right + forward - backward)); | ||
drivetrain.setPercent(rateLimitedLeft,rateLimitedRight); | ||
} | ||
|
||
@Override | ||
public void end(boolean isInterrupted) { | ||
drivetrain.stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/org/team1540/elmo/subsystems/drivetrain/SegmentedAuto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.team1540.elmo.subsystems.drivetrain; | ||
|
||
import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
import edu.wpi.first.wpilibj2.command.WaitCommand; | ||
import org.team1540.elmo.Constants; | ||
import org.team1540.elmo.subsystems.ejectors.EjectInnerCommand; | ||
import org.team1540.elmo.subsystems.ejectors.EjectOuterCommand; | ||
import org.team1540.elmo.subsystems.ejectors.EjectUpperCommand; | ||
import org.team1540.elmo.subsystems.ejectors.Ejector; | ||
import org.team1540.elmo.utils.ChickenPhotonCamera; | ||
|
||
public class SegmentedAuto extends SequentialCommandGroup { | ||
public SegmentedAuto(DriveTrain driveTrain, Ejector.UpperEjector upperEjector, Ejector.OuterEjector outerEjector, Ejector.InnerEjector innerEjector, ChickenPhotonCamera camera) { | ||
super( | ||
// drive forward until can see april tag | ||
deadline( | ||
new WaitUntilCanSeeAprilTagCommand(Constants.TOWER_APRILTAG_ID,camera), | ||
new DriveForwardRampedForeverCommand(-0.8,driveTrain) | ||
), | ||
// drive fast (w/ ramping) pointing to tag until close to april tag | ||
deadline( | ||
new WaitUntilAprilTagIsWithinXMetersCommand(Constants.TOWER_APRILTAG_ID,2,camera), | ||
new DriveToAprilTagCommand(Constants.TOWER_APRILTAG_ID,0.7,1,driveTrain,camera) | ||
), | ||
// drive slow (w/ ramping) pointing to tag until very close to april tag | ||
deadline( | ||
new WaitUntilAprilTagIsWithinXMetersCommand(Constants.TOWER_APRILTAG_ID,0.1,camera), | ||
new DriveToAprilTagCommand(Constants.TOWER_APRILTAG_ID,0.1,1,driveTrain,camera) | ||
), | ||
// drive forward slowly for last few seconds | ||
deadline( | ||
new WaitCommand(1), | ||
new DriveForwardRampedForeverCommand(0.1,driveTrain) | ||
), | ||
// stop drivetrain (right now no ramping, possibly add ramping?) | ||
new InstantCommand(driveTrain::stop,driveTrain), | ||
// eject all tubes! | ||
parallel( | ||
new EjectUpperCommand(upperEjector), | ||
new EjectInnerCommand(innerEjector), | ||
new EjectOuterCommand(outerEjector) | ||
), | ||
// wait for tubes to fully eject | ||
new WaitCommand(2), | ||
// back up from the tower for a few seconds to give better position for driver to take over | ||
deadline( | ||
new DriveForwardRampedForeverCommand(-0.3,driveTrain), | ||
new WaitCommand(1.5) | ||
), | ||
new InstantCommand(driveTrain::stopRamped,driveTrain) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters