Skip to content

Commit

Permalink
Added Mechanism2d stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
keckothedragon committed May 2, 2024
1 parent 64907fb commit 08a9c10
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 4 deletions.
Binary file added advantagekit/logs/Log_24-05-02_14-58-00.wpilog
Binary file not shown.
Binary file added advantagekit/logs/Log_24-05-02_15-02-55.wpilog
Binary file not shown.
Binary file added advantagekit/logs/Log_24-05-02_15-05-15.wpilog
Binary file not shown.
Binary file added advantagekit/logs/Log_24-05-02_15-06-59.wpilog
Binary file not shown.
Binary file added advantagekit/logs/Log_24-05-02_15-07-49.wpilog
Binary file not shown.
Binary file added advantagekit/logs/Log_24-05-02_15-49-50.wpilog
Binary file not shown.
Binary file added advantagekit/logs/Log_24-05-02_15-52-42.wpilog
Binary file not shown.
Binary file modified ctre_sim/Pigeon 2 - 020 - 0 - ext.dat
Binary file not shown.
Binary file added logs/FRC_20240502_185854.wpilog
Binary file not shown.
Binary file added logs/FRC_20240502_190307.wpilog
Binary file not shown.
Binary file added logs/FRC_20240502_190520.wpilog
Binary file not shown.
Binary file added logs/FRC_20240502_190707.wpilog
Binary file not shown.
Binary file added logs/FRC_20240502_190751.wpilog
Binary file not shown.
Binary file added logs/FRC_20240502_195024.wpilog
Binary file not shown.
Binary file added logs/FRC_20240502_195257.wpilog
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public void robotPeriodic() {
// This must be called from the robot's periodic block in order for anything in
// the Command-based framework to work.
CommandScheduler.getInstance().run();

robotContainer.updateRobotState();
}

/** This function is called once when the robot is disabled. */
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
* subsystems, commands, and button mappings) should be declared here.
*/
public class RobotContainer {
private RobotState m_robotState;

// Subsystems
private Drive m_drive;
private Shooter m_shooter;
Expand Down Expand Up @@ -86,6 +88,10 @@ private void configureSubsystems() {
ShooterConstants.kPivotController,
ShooterConstants.kFlywheelController);
}

m_shooter.setPivotAngle(ShooterConstants.kHomeAngle);

m_robotState = RobotState.startInstance(m_drive, m_shooter);
}

private void configureControllers() {
Expand All @@ -106,7 +112,7 @@ private void configureButtonBindings() {
Commands.runOnce(
() -> {
m_shooter.setFlywheelVelocity(2, 4);
m_shooter.setPivotAngle(Rotation2d.fromDegrees(50));
m_shooter.setPivotAngle(Rotation2d.fromDegrees(60));
}))
.onFalse(
Commands.runOnce(
Expand All @@ -115,4 +121,8 @@ private void configureButtonBindings() {
m_shooter.setPivotAngle(ShooterConstants.kHomeAngle);
}));
}

public void updateRobotState() {
m_robotState.updateRobotState();
}
}
69 changes: 69 additions & 0 deletions src/main/java/frc/robot/RobotState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package frc.robot;

import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj.util.Color8Bit;
import frc.robot.subsystems.drive.Drive;
import frc.robot.subsystems.shooter.Shooter;

public class RobotState {
private static RobotState instance = null;

// subsystems
private Drive m_drive;
private Shooter m_shooter;

// mechanism
private final boolean kMechanismEnabled = true;
MechanismLigament2d m_shooterPivotMech;

private RobotState(Drive drive, Shooter shooter) {
// subsystems
m_drive = drive;
m_shooter = shooter;

// mechanism set up
Mechanism2d m_mechanism = new Mechanism2d(3, 3);
MechanismRoot2d m_root = m_mechanism.getRoot("shooter", 3, 1);
m_shooterPivotMech =
m_root.append(
new MechanismLigament2d(
"pivot",
1,
m_shooter.getPivotAngle().getDegrees(),
6,
new Color8Bit(Color.kPurple)));

// post to dashboard
SmartDashboard.putData("Mech2d", m_mechanism);
}

public static RobotState startInstance(Drive drive, Shooter shooter) {
if (instance == null) {
instance = new RobotState(drive, shooter);
} else {
throw new IllegalStateException("RobotState instance already started");
}
return instance;
}

public static RobotState getInstance() {
if (instance == null) {
throw new IllegalStateException("RobotState instance not started");
}
return instance;
}

public void updateMechanism() {
m_shooterPivotMech.setAngle(m_shooter.getPivotAngle().getDegrees());
}

public void updateRobotState() {
if (kMechanismEnabled) {
updateMechanism();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/oi/DriverControlsXbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public double getDriveRotation() {

@Override
public Trigger testShooter() {
return m_controller.leftTrigger();
return m_controller.button(7);
}
}
8 changes: 6 additions & 2 deletions src/main/java/frc/robot/subsystems/shooter/Shooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class Shooter extends SubsystemBase {
private ShooterPivotIO m_pivotIO;
private FlywheelIO m_flywheelIO;

private ShooterPivotInputsAutoLogged m_pivotInputs;
private FlywheelInputsAutoLogged m_flywheelInputs;
public final ShooterPivotInputsAutoLogged m_pivotInputs;
public final FlywheelInputsAutoLogged m_flywheelInputs;

private ProfiledPIDController m_pivotController;
private ProfiledPIDController m_leftFlywheelController;
Expand Down Expand Up @@ -114,4 +114,8 @@ public Command setPivotAngleCommand(Rotation2d angle) {
public Command setFlywheelVelocityCommand(double leftRPM, double rightRPM) {
return Commands.runOnce(() -> setFlywheelVelocity(leftRPM, rightRPM));
}

public Rotation2d getPivotAngle() {
return Rotation2d.fromRadians(m_pivotInputs.curAngle);
}
}

0 comments on commit 08a9c10

Please sign in to comment.