Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#88] create drivetrain system test #115

Merged
merged 5 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.WaitCommand;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.MathUtil;
import frc.robot.subsystems.Flywheel;
import frc.robot.subsystems.Pivot;
import frc.robot.subsystems.Shooter;
Expand All @@ -26,6 +30,8 @@
import frc.robot.command.SetLED;
import frc.robot.command.TipDetection;
import frc.robot.command.Shoot;
import frc.robot.command.tests.DrivetrainSystemTest;
import frc.robot.command.tests.TurnSystemTest;
import frc.robot.command.ChasePieces;
import frc.robot.command.Climb;
import frc.robot.command.ManualClimb;
Expand All @@ -38,7 +44,9 @@
import frc.robot.subsystems.Shooter;
import frc.robot.subsystems.Swerve;
import frc.thunder.LightningContainer;
import frc.thunder.command.TimedCommand;
import frc.thunder.shuffleboard.LightningShuffleboard;
import frc.thunder.testing.SystemTest;

public class RobotContainer extends LightningContainer {
XboxController driver;
Expand Down Expand Up @@ -161,5 +169,12 @@ protected void configureFaultMonitors() {

@Override
protected void configureSystemTests() {
SystemTest.registerTest("Drive All Directions", new DrivetrainSystemTest(drivetrain, 0.25));

SystemTest.registerTest("Azimuth Test", new SequentialCommandGroup(
new TimedCommand(new TurnSystemTest(drivetrain, () -> 0.25), 2),
new WaitCommand(0.5),
new TimedCommand(new TurnSystemTest(drivetrain, () -> -0.25), 2)
));
}
}
51 changes: 51 additions & 0 deletions src/main/java/frc/robot/command/tests/DriveTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.command.tests;

import java.util.function.DoubleSupplier;

import com.ctre.phoenix6.mechanisms.swerve.SwerveRequest;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.Swerve;

public class DriveTest extends Command {

private Swerve drivetrain;
private DoubleSupplier speedX;
private DoubleSupplier speedY;

/**
* Creates a new drive test
* @param drivetrain swerve subsystem
* @param speedX X velocity
* @param speedY Y velocity
*/
public DriveTest(Swerve drivetrain, DoubleSupplier speedX, DoubleSupplier speedY) {
this.drivetrain = drivetrain;
this.speedX = speedX;
this.speedY = speedY;

addRequirements(drivetrain);
}

@Override
public void initialize() {}

@Override
public void execute() {
drivetrain.setControl(new SwerveRequest.FieldCentric().withVelocityX(speedX.getAsDouble()).withVelocityY(speedY.getAsDouble()));
}

@Override
public void end(boolean interrupted) {
drivetrain.setControl(new SwerveRequest.FieldCentric().withVelocityX(0).withVelocityY(0).withRotationalRate(0));
}

@Override
public boolean isFinished() {
return false;
}
}
26 changes: 26 additions & 0 deletions src/main/java/frc/robot/command/tests/DrivetrainSystemTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.command.tests;

import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.WaitCommand;
import frc.robot.subsystems.Swerve;
import frc.thunder.command.TimedCommand;

public class DrivetrainSystemTest extends SequentialCommandGroup {

public DrivetrainSystemTest(Swerve drivetrain, double speed) {
addCommands(
new WaitCommand(0.5),
new TimedCommand(new DriveTest(drivetrain, () -> 0d, () -> speed), 2), // Forward
new WaitCommand(1),
new TimedCommand(new DriveTest(drivetrain, () -> 0d, () -> -speed), 2), // Backward
new WaitCommand(1),
new TimedCommand(new DriveTest(drivetrain, () -> -speed, () -> 0), 2), // Left
new WaitCommand(1),
new TimedCommand(new DriveTest(drivetrain, () -> speed, () -> 0), 2) // Right
);
}
}
48 changes: 48 additions & 0 deletions src/main/java/frc/robot/command/tests/TurnSystemTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.command.tests;

import java.util.function.DoubleSupplier;

import com.ctre.phoenix6.mechanisms.swerve.SwerveRequest;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.Swerve;

public class TurnSystemTest extends Command {

private Swerve drivetrain;
private DoubleSupplier speed;

/**
* System test for testing azimuth motors
* @param drivetrain swerve subsystem
* @param speed rotational rate
*/
public TurnSystemTest(Swerve drivetrain, DoubleSupplier speed) {
this.drivetrain = drivetrain;
this.speed = speed;

addRequirements(drivetrain);
}

@Override
public void initialize() {}

@Override
public void execute() {
drivetrain.setControl(new SwerveRequest.FieldCentric().withVelocityX(0).withVelocityY(0).withRotationalRate(speed.getAsDouble()));
}

@Override
public void end(boolean interrupted) {
drivetrain.setControl(new SwerveRequest.FieldCentric().withVelocityX(0).withVelocityY(0).withRotationalRate(0));
}

@Override
public boolean isFinished() {
return false;
}
}
Loading