Adding CS16 and CS17 demos

This commit is contained in:
2024-06-22 13:04:43 -04:00
parent 1c2266f4c5
commit f828ecd6f6
45 changed files with 2593 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
Files placed in this directory will be deployed to the RoboRIO into the
'deploy' directory in the home folder. Use the 'Filesystem.getDeployDirectory' wpilib function
to get a proper path relative to the deploy directory.

View File

@@ -0,0 +1,15 @@
// 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.
package frc.robot;
import edu.wpi.first.wpilibj.RobotBase;
public final class Main {
private Main() {}
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}

View File

@@ -0,0 +1,73 @@
// 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.
package frc.robot;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
public class Robot extends TimedRobot {
private Command m_autonomousCommand;
private RobotContainer m_robotContainer;
@Override
public void robotInit() {
m_robotContainer = new RobotContainer();
}
@Override
public void robotPeriodic() {
CommandScheduler.getInstance().run();
}
@Override
public void disabledInit() {}
@Override
public void disabledPeriodic() {}
@Override
public void disabledExit() {}
@Override
public void autonomousInit() {
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
if (m_autonomousCommand != null) {
m_autonomousCommand.schedule();
}
}
@Override
public void autonomousPeriodic() {}
@Override
public void autonomousExit() {}
@Override
public void teleopInit() {
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}
}
@Override
public void teleopPeriodic() {}
@Override
public void teleopExit() {}
@Override
public void testInit() {
CommandScheduler.getInstance().cancelAll();
}
@Override
public void testPeriodic() {}
@Override
public void testExit() {}
}

View File

@@ -0,0 +1,37 @@
// 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.
package frc.robot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import frc.robot.constants.OIConstants;
import frc.robot.subsystems.Drivetrain;
public class RobotContainer {
private Drivetrain drivetrain;
private CommandXboxController driver;
public RobotContainer() {
drivetrain = new Drivetrain();
driver = new CommandXboxController(OIConstants.kDriverUSB);
configureBindings();
}
private void configureBindings() {
drivetrain.setDefaultCommand(
drivetrain.driveArcade(
driver::getLeftY,
driver::getLeftX
)
);
}
public Command getAutonomousCommand() {
return drivetrain.driveTank(() -> .4, () -> -.4);
}
}

View File

@@ -0,0 +1,8 @@
package frc.robot.constants;
public class DrivetrainConstants {
public static final int kLeftFrontID = 0;
public static final int kLeftRearID = 1;
public static final int kRightFrontID = 2;
public static final int kRightRearID = 3;
}

View File

@@ -0,0 +1,5 @@
package frc.robot.constants;
public class OIConstants {
public static final int kDriverUSB = 0;
}

View File

@@ -0,0 +1,115 @@
package frc.robot.subsystems;
import java.util.function.DoubleSupplier;
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;
import com.ctre.phoenix6.controls.Follower;
import com.ctre.phoenix6.hardware.TalonFX;
import com.revrobotics.CANSparkFlex;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkLowLevel.MotorType;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
import edu.wpi.first.wpilibj.motorcontrol.Talon;
import edu.wpi.first.wpilibj.motorcontrol.VictorSP;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.constants.DrivetrainConstants;
public class Drivetrain extends SubsystemBase {
private MotorController leftFront;
private MotorController leftRear;
private MotorController rightFront;
private MotorController rightRear;
private DifferentialDrive drive;
public Drivetrain() {
/* VICTOR SP STYLE
leftFront = new VictorSP(DrivetrainConstants.kLeftFrontID);
leftRear = new VictorSP(DrivetrainConstants.kLeftRearID);
rightFront = new VictorSP(DrivetrainConstants.kRightFrontID);
rightRear = new VictorSP(DrivetrainConstants.kRightRearID);
leftFront.addFollower(leftRear);
rightFront.addFollower(rightRear);
rightFront.setInverted(true);
*/
/* CAN SPARK MAX STYLE
leftFront = new CANSparkMax(DrivetrainConstants.kLeftFrontID, MotorType.kBrushless);
leftRear = new CANSparkMax(DrivetrainConstants.kLeftRearID, MotorType.kBrushless);
rightFront = new CANSparkMax(DrivetrainConstants.kRightFrontID, MotorType.kBrushless);
rightRear = new CANSparkMax(DrivetrainConstants.kRightRearID, MotorType.kBrushless);
((CANSparkMax)leftRear).follow((CANSparkMax)leftFront);
((CANSparkMax)rightRear).follow((CANSparkMax)rightFront);
rightFront.setInverted(true);
*/
/* CAN SPARK FLEX STYLE
leftFront = new CANSparkFlex(DrivetrainConstants.kLeftFrontID, MotorType.kBrushless);
leftRear = new CANSparkFlex(DrivetrainConstants.kLeftRearID, MotorType.kBrushless);
rightFront = new CANSparkFlex(DrivetrainConstants.kRightFrontID, MotorType.kBrushless);
rightRear = new CANSparkFlex(DrivetrainConstants.kRightRearID, MotorType.kBrushless);
((CANSparkMax)leftRear).follow((CANSparkMax)leftFront);
((CANSparkMax)rightRear).follow((CANSparkMax)rightFront);
rightFront.setInverted(true);
*/
/* KRAKEN X60/FALCON 500 STYLE
leftFront = new TalonFX(DrivetrainConstants.kLeftFrontID);
leftRear = new TalonFX(DrivetrainConstants.kLeftRearID);
rightFront = new TalonFX(DrivetrainConstants.kRightFrontID);
rightRear = new TalonFX(DrivetrainConstants.kRightRearID);
((TalonFX)leftRear).setControl(new Follower(DrivetrainConstants.kLeftFrontID, false));
((TalonFX)rightRear).setControl(new Follower(DrivetrainConstants.kRightFrontID, false));
rightFront.setInverted(true);
*/
/* TALON SRX STYLE
leftFront = new WPI_TalonSRX(DrivetrainConstants.kLeftFrontID);
leftRear = new WPI_TalonSRX(DrivetrainConstants.kLeftRearID);
rightFront = new WPI_TalonSRX(DrivetrainConstants.kRightFrontID);
rightRear = new WPI_TalonSRX(DrivetrainConstants.kRightRearID);
((WPI_TalonSRX)leftRear).follow((WPI_TalonSRX)leftFront);
((WPI_TalonSRX)rightRear).follow((WPI_TalonSRX)rightFront);
rightFront.setInverted(true);
*/
/* VICTOR SPX STYLE
leftFront = new WPI_VictorSPX(DrivetrainConstants.kLeftFrontID);
leftRear = new WPI_VictorSPX(DrivetrainConstants.kLeftRearID);
rightFront = new WPI_VictorSPX(DrivetrainConstants.kRightFrontID);
rightRear = new WPI_VictorSPX(DrivetrainConstants.kRightRearID);
((WPI_VictorSPX)leftRear).follow((WPI_VictorSPX)leftFront);
((WPI_VictorSPX)rightRear).follow((WPI_VictorSPX)rightFront);
rightFront.setInverted(true);
*/
drive = new DifferentialDrive(leftFront, rightFront);
}
public Command driveArcade(DoubleSupplier xSpeed, DoubleSupplier zRotation) {
return run(() -> {
drive.arcadeDrive(xSpeed.getAsDouble(), zRotation.getAsDouble());
});
}
public Command driveTank(DoubleSupplier leftSpeed, DoubleSupplier rightSpeed) {
return run(() -> {
drive.tankDrive(leftSpeed.getAsDouble(), rightSpeed.getAsDouble());
});
}
}