generated from StuyPulse/Phil
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish kitbot, still needs button bindings
- Loading branch information
Showing
11 changed files
with
369 additions
and
4 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
49 changes: 49 additions & 0 deletions
49
src/main/java/com/stuypulse/robot/commands/drivetrain/DrivetrainDrive.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,49 @@ | ||
package com.stuypulse.robot.commands.drivetrain; | ||
|
||
import com.stuypulse.robot.subsystems.Drivetrain; | ||
import com.stuypulse.stuylib.input.Gamepad; | ||
import com.stuypulse.stuylib.math.SLMath; | ||
import com.stuypulse.stuylib.streams.numbers.IStream; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
|
||
public class DrivetrainDrive extends Command { | ||
public final Drivetrain drivetrain; | ||
private final Gamepad driver; | ||
|
||
double rightSpeed; | ||
double leftSpeed; | ||
|
||
private final IStream speed; | ||
private final IStream angle; | ||
|
||
public DrivetrainDrive(Drivetrain drivetrain, Gamepad driver) { | ||
this.drivetrain = drivetrain; | ||
this.driver = driver; | ||
|
||
this.speed = IStream.create( | ||
() -> driver.getRightY() - driver.getLeftY()) | ||
.filtered( | ||
x -> SLMath.deadband(x, 0), | ||
x -> SLMath.spow(x, 2) | ||
); | ||
|
||
this.angle = IStream.create( | ||
() -> driver.getRightX() - driver.getLeftX()) | ||
.filtered( | ||
x -> SLMath.deadband(x, 0), | ||
x -> SLMath.spow(x, 2) | ||
); | ||
|
||
addRequirements(drivetrain); | ||
|
||
} | ||
|
||
@Override | ||
public void execute() { | ||
if (driver.getRawLeftButton() || driver.getRawRightButton()) { | ||
drivetrain.curvatureDrive(speed.get(), angle.get(), true); | ||
} | ||
else drivetrain.stop(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/stuypulse/robot/commands/drivetrain/DrivetrainDriveForever.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,27 @@ | ||
/************************ PROJECT DORCAS ************************/ | ||
/* Copyright (c) 2022 StuyPulse Robotics. All rights reserved. */ | ||
/* This work is licensed under the terms of the MIT license. */ | ||
/****************************************************************/ | ||
|
||
package com.stuypulse.robot.commands.drivetrain; | ||
|
||
import com.stuypulse.robot.subsystems.Drivetrain; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
|
||
public class DrivetrainDriveForever extends Command { | ||
private final Drivetrain drivetrain; | ||
private final double speed; | ||
|
||
public DrivetrainDriveForever(Drivetrain drivetrain, double speed) { | ||
this.drivetrain = drivetrain; | ||
this.speed = speed; | ||
|
||
addRequirements(drivetrain); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
drivetrain.curvatureDrive(speed, 0, false); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/stuypulse/robot/commands/launcher/LaunchNote.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,19 @@ | ||
package com.stuypulse.robot.commands.launcher; | ||
|
||
import com.stuypulse.robot.subsystems.Launcher; | ||
|
||
import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
|
||
public class LaunchNote extends InstantCommand { | ||
Launcher launcher; | ||
|
||
public LaunchNote() { | ||
launcher = Launcher.getInstance(); | ||
addRequirements(launcher); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
launcher.launch(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/stuypulse/robot/commands/launcher/LaunchPrepare.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,23 @@ | ||
package com.stuypulse.robot.commands.launcher; | ||
|
||
import com.stuypulse.robot.constants.Settings; | ||
import com.stuypulse.robot.subsystems.Launcher; | ||
|
||
import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
|
||
/** | ||
* PrepareLaunch sets the launcher to the launch speed, spins just the outside wheel of the launcher to allow it to get up to speed before launching | ||
*/ | ||
public class LaunchPrepare extends InstantCommand { | ||
Launcher launcher; | ||
|
||
public LaunchPrepare() { | ||
launcher = Launcher.getInstance(); | ||
addRequirements(launcher); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
launcher.setLaunchSpeed(Settings.Launcher.kLauncherSpeed); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/stuypulse/robot/commands/launcher/LauncherIntakeNote.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,19 @@ | ||
package com.stuypulse.robot.commands.launcher; | ||
|
||
import com.stuypulse.robot.subsystems.Launcher; | ||
|
||
import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
|
||
public class LauncherIntakeNote extends InstantCommand { | ||
Launcher launcher; | ||
|
||
public LauncherIntakeNote() { | ||
launcher = Launcher.getInstance(); | ||
addRequirements(launcher); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
launcher.intake(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/stuypulse/robot/commands/launcher/LauncherStop.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,20 @@ | ||
package com.stuypulse.robot.commands.launcher; | ||
|
||
import com.stuypulse.robot.subsystems.Launcher; | ||
|
||
import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
|
||
public class LauncherStop extends InstantCommand{ | ||
Launcher launcher; | ||
|
||
public LauncherStop() { | ||
launcher = Launcher.getInstance(); | ||
addRequirements(launcher); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
launcher.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
90 changes: 90 additions & 0 deletions
90
src/main/java/com/stuypulse/robot/subsystems/Drivetrain.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,90 @@ | ||
package com.stuypulse.robot.subsystems; | ||
|
||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.CANSparkLowLevel.MotorType; | ||
import com.stuypulse.robot.constants.Ports; | ||
import com.stuypulse.robot.constants.Settings; | ||
|
||
import edu.wpi.first.wpilibj.drive.DifferentialDrive; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public class Drivetrain extends SubsystemBase{ | ||
private static Drivetrain instance = new Drivetrain(); | ||
|
||
public static Drivetrain getInstance() { | ||
return instance; | ||
} | ||
|
||
private DifferentialDrive drivetrain; | ||
|
||
CANSparkMax leftFront; | ||
CANSparkMax leftBack; | ||
CANSparkMax rightFront; | ||
CANSparkMax rightBack; | ||
|
||
public Drivetrain() { | ||
leftFront = new CANSparkMax(Ports.Drivetrain.LEFTFRONT, MotorType.kBrushed); | ||
leftBack = new CANSparkMax(Ports.Drivetrain.LEFTFRONT, MotorType.kBrushed); | ||
rightFront = new CANSparkMax(Ports.Drivetrain.LEFTFRONT, MotorType.kBrushed); | ||
rightBack = new CANSparkMax(Ports.Drivetrain.LEFTFRONT, MotorType.kBrushed); | ||
|
||
leftBack.follow(leftFront); | ||
rightBack.follow(rightFront); | ||
|
||
leftFront.setInverted(true); | ||
rightFront.setInverted(false); | ||
|
||
leftFront.setSmartCurrentLimit(Settings.Drivetrain.kCurrentLimit); | ||
leftBack.setSmartCurrentLimit(Settings.Drivetrain.kCurrentLimit); | ||
rightFront.setSmartCurrentLimit(Settings.Drivetrain.kCurrentLimit); | ||
leftBack.setSmartCurrentLimit(Settings.Drivetrain.kCurrentLimit); | ||
|
||
drivetrain = new DifferentialDrive(leftFront, rightFront); | ||
} | ||
|
||
//********** GETTERS ********** | ||
public double getLeftSpeed() { | ||
return leftFront.getEncoder().getVelocity(); | ||
} | ||
|
||
public double getRightSpeed() { | ||
return rightFront.getEncoder().getVelocity(); | ||
} | ||
|
||
public double getLeftVoltage() { | ||
return leftFront.getAppliedOutput(); | ||
} | ||
|
||
public double getRightVoltage() { | ||
return rightFront.getAppliedOutput(); | ||
} | ||
|
||
//********** Drive Methods ********** | ||
public void tankDrive(double leftSpeed, double rightSpeed) { | ||
drivetrain.tankDrive(leftSpeed, rightSpeed); | ||
} | ||
|
||
public void arcadeDrive(double speed, double rotation) { | ||
drivetrain.arcadeDrive(speed, rotation); | ||
} | ||
|
||
public void curvatureDrive(double speed, double rotation, boolean isQuickTurn) { | ||
drivetrain.curvatureDrive(speed, rotation, isQuickTurn); | ||
} | ||
|
||
public void stop() { | ||
drivetrain.stopMotor(); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
SmartDashboard.putNumber("Drivetrain/ Left Speed", getLeftSpeed()); | ||
SmartDashboard.putNumber("Drivetrain/ Right Speed", getRightSpeed()); | ||
SmartDashboard.putNumber("Drivetrain/ Left Voltage", getLeftVoltage()); | ||
SmartDashboard.putNumber("Drivetrain/ Right Voltage", getRightVoltage()); | ||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.