Skip to content

Commit

Permalink
Cleanup Java sysid example
Browse files Browse the repository at this point in the history
  • Loading branch information
bhall-ctre committed Apr 10, 2024
1 parent 6d7a942 commit aa05581
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 9 additions & 10 deletions java/PhoenixSysId/src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
import frc.robot.subsystems.FlywheelMechanism;

public class RobotContainer {

CommandXboxController m_joystick = new CommandXboxController(0);
FlywheelMechanism m_mechanism = new FlywheelMechanism();
private final CommandXboxController m_joystick = new CommandXboxController(0);
private final FlywheelMechanism m_mechanism = new FlywheelMechanism();

public RobotContainer() {
configureBindings();
Expand All @@ -26,21 +24,22 @@ private void configureBindings() {
/* Default command is duty cycle control with the left up/down stick */
m_mechanism.setDefaultCommand(m_mechanism.joystickDriveCommand(m_joystick::getLeftY));

/* Manually start logging with left bumper before running any tests,
* and stop logging with right bumper after we're done with ALL tests.
* This isn't necessary, but is convenient to reduce the size of the hoot file */
m_joystick.leftBumper().onTrue(Commands.runOnce(SignalLogger::start));
m_joystick.rightBumper().onTrue(Commands.runOnce(SignalLogger::stop));

/**
* Joystick Y = quasistatic forward
* Joystick B = dynamic forward
* Joystick A = quasistatic reverse
* Joystick B = dynamic forward
* Joystick X = dyanmic reverse
*/
m_joystick.y().whileTrue(m_mechanism.sysIdQuasistatic(SysIdRoutine.Direction.kForward));
m_joystick.a().whileTrue(m_mechanism.sysIdQuasistatic(SysIdRoutine.Direction.kReverse));
m_joystick.b().whileTrue(m_mechanism.sysIdDynamic(SysIdRoutine.Direction.kForward));
m_joystick.x().whileTrue(m_mechanism.sysIdDynamic(SysIdRoutine.Direction.kReverse));


/* Manually stop logging with left bumper after we're done with the tests */
/* This isn't necessary, but is convenient to reduce the size of the hoot file */
m_joystick.leftBumper().onTrue(new RunCommand(SignalLogger::stop));
}

public Command getAutonomousCommand() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FlywheelMechanism extends SubsystemBase {
private final DutyCycleOut m_joystickControl = new DutyCycleOut(0);
private final VoltageOut m_sysidControl = new VoltageOut(0);

private SysIdRoutine m_SysIdRoutine =
private final SysIdRoutine m_SysIdRoutine =
new SysIdRoutine(
new SysIdRoutine.Config(
null, // Default ramp rate is acceptable
Expand All @@ -40,6 +40,7 @@ public FlywheelMechanism() {
setName("Flywheel");

TalonFXConfiguration cfg = new TalonFXConfiguration();
// Set any necessary configs in the Feedback group here
m_motorToTest.getConfigurator().apply(cfg);

/* Speed up signals for better charaterization data */
Expand All @@ -48,9 +49,10 @@ public FlywheelMechanism() {
m_motorToTest.getVelocity(),
m_motorToTest.getMotorVoltage());

/* Optimize out the other signals, since they're not particularly helpful for us */
/* Optimize out the other signals, since they're not useful for SysId */
m_motorToTest.optimizeBusUtilization();

/* Start the signal logger */
SignalLogger.start();
}

Expand Down

0 comments on commit aa05581

Please sign in to comment.