Skip to content

Commit

Permalink
Reorganizing
Browse files Browse the repository at this point in the history
  • Loading branch information
JediScoy committed Mar 28, 2024
1 parent 6f5700e commit e2cb65b
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 33 deletions.
48 changes: 23 additions & 25 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package frc.robot;

import com.ctre.phoenix6.mechanisms.swerve.SwerveModule.DriveRequestType;
import com.ctre.phoenix6.hardware.Pigeon2;
import com.ctre.phoenix6.mechanisms.swerve.SwerveRequest;
import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.auto.NamedCommands;
Expand Down Expand Up @@ -32,14 +33,16 @@
import frc.robot.experimental.ShootWhenReadyAuton;
import frc.robot.experimental.ShootWhenReady;
import frc.robot.commands.ShootFromStage;
import frc.robot.generated.TunerConstants;
import frc.robot.subsystems.ArmSubsystem;
import frc.robot.subsystems.CommandSwerveDrivetrain;
import frc.robot.subsystems.Gyro;
import frc.robot.subsystems.IndexSubsystem;
import frc.robot.subsystems.IntakeSubsystem;
import frc.robot.subsystems.Limelight;
import frc.robot.subsystems.ShooterSubsystemVelocity;
import frc.robot.subsystems.WinchSubsystem2;
import frc.robot.util.Constants;
import frc.robot.util.TunerConstants;
import frc.robot.subsystems.ShooterSubsystem2;
import frc.robot.subsystems.NoteSensorSubsystem;

Expand All @@ -65,6 +68,8 @@ public class RobotContainer {
WinchSubsystem2 winch = new WinchSubsystem2();
ArmSubsystem arm = new ArmSubsystem();
NoteSensorSubsystem notesensor = new NoteSensorSubsystem();
Gyro pidgey = new Gyro();

// #endregion Subsystems

// #region commands
Expand Down Expand Up @@ -92,25 +97,18 @@ public class RobotContainer {
private final SwerveRequest.PointWheelsAt point = new SwerveRequest.PointWheelsAt();
private final Telemetry logger = new Telemetry(MaxSpeed);

// Command Group for Intake and Index
private final IntakeCommandGroup intakeGroup = new IntakeCommandGroup(index, intake);

// Command Group for Intake and Index reverse
private final IntakeRevCommandGroup intakeRevGroup = new IntakeRevCommandGroup(index, intake);

// Only Sets the flywheel to target velocity, no index
private final SetFlywheel setShooterVelocity = new SetFlywheel(shooter2, arm, shooter2.FLYWHEEL_VELOCITY);

// Only Sets the flywheel to idle velocity, no index
private final SetFlywheel setShooterIdle = new SetFlywheel(shooter2, arm, shooter2.FLYWHEEL_IDLE_VELOCITY);

// An updated version of the RevAndShootCommand
private final ShootWhenReady shootWhenReady = new ShootWhenReady(shooter2, index, notesensor);

// Autonomous version of the Shoot When Ready command that addeds notesensor checks for ending the command
private final ShootWhenReadyAuton shootWhenReadyAuton = new ShootWhenReadyAuton(shooter2, index, notesensor);

// An updated version of the RevAndShootCommand that increases "power" to shoots from the stage
private final ShootFromStage shootFromStage = new ShootFromStage(arm, index, intake, shooter2, notesensor);


Expand All @@ -125,14 +123,16 @@ public class RobotContainer {
public RobotContainer() {
Limelight lime = new Limelight();

/* Pathplanner Named Commands for Auton */
NamedCommands.registerCommand("ShootClose", new ShootClose(arm, index, intake, shooter)); // Command Group
NamedCommands.registerCommand("ShootClose2", shootWhenReadyAuton); // Command for autonomous, same as below
/* Pathplanner Named Commands */
NamedCommands.registerCommand("ShootClose", new ShootClose(arm, index, intake, shooter));
NamedCommands.registerCommand("ShootClose2", shootWhenReadyAuton);
NamedCommands.registerCommand("ShootFromStage", shootFromStage);
NamedCommands.registerCommand("Intake", new IntakeIndex(index, intake)); // Command Group
NamedCommands.registerCommand("Intake", new IntakeIndex(index, intake));

NamedCommands.registerCommand("AutoShootWhenReady", shootWhenReadyAuton);
NamedCommands.registerCommand("ShootWhenReady", shootWhenReadyAuton); // Command for autonomous
NamedCommands.registerCommand("ShootWhenReady", shootWhenReadyAuton); // Autonomous
NamedCommands.registerCommand("SetFlywheelToIdle", setShooterIdle);
// Constants.ArmConstants.ARM_MID_POSE));

/*
* Auto Chooser
Expand Down Expand Up @@ -182,14 +182,14 @@ private void configureBindings() {
// negative X (left)
));
// m_driverController.a().whileTrue(drivetrain.applyRequest(() -> brake));

/*
* m_driverController.b().whileTrue(drivetrain
* .applyRequest(() -> point
* .withModuleDirection(new Rotation2d(-m_driverController.getLeftY(),
* -m_driverController.getLeftX()))));
*/

// reset the field-centric heading
/*
* m_driverController.b().whileTrue(drivetrain.applyRequest(() -> point
* .withModuleDirection(new Rotation2d(-m_driverController.getLeftY(),
Expand All @@ -202,20 +202,13 @@ private void configureBindings() {
m_driverController.x().whileTrue(new InstantCommand(() -> arm.setArmPose(Constants.ArmConstants.ARM_AMP_POSE)));
m_driverController.rightBumper().whileTrue(new IntakeCommandGroup(index, intake));
m_driverController.leftBumper().whileTrue(new IntakeRevCommandGroup(index, intake));

/* Ideally, this is the working command for turning on the shooter and index */
m_driverController.rightTrigger().whileTrue(shootWhenReady);

// TODO Testing purposes, remove later. This only turns on the flywheel-shooter
// m_driverController.rightTrigger().whileTrue(setShooterVelocity);

// TODO Testing purposes, remove later. This would be the ideal command used for Autonomous shooting
// m_driverController.rightTrigger().whileTrue(autonShootWhenReady);

// m_driverController.rightTrigger().whileTrue(setShooterVelocity); // TODO Testing purposes, remove later
// m_driverController.rightTrigger().whileTrue(autonShootWhenReady); // TODO Testing purposes, remove later
m_driverController.leftTrigger().whileTrue(new SetIndex(index, -0.75));

// m_driverController.rightTrigger().whileTrue(new RevAndShootCommand(index, shooter)); /* Previous bindings from LC and TC */
// m_driverController.rightTrigger().whileFalse(new InstantCommand(() -> shooter.SetOutput(0))); /* Previous bindings from LC and TC */
// m_driverController.rightTrigger().whileTrue(new RevAndShootCommand(index, shooter)); /* Previous bindings */
// m_driverController.rightTrigger().whileFalse(new InstantCommand(() -> shooter.SetOutput(0))); /* Previous bindings */

/* OPERATOR BINDINGS */
m_operatorController.b().whileTrue(new SetArmClimb(arm, Constants.ArmConstants.ARM_MANUAL_POWER));
Expand All @@ -237,6 +230,11 @@ public void DebugMethodSingle() {
// arm.showArmTelemetry("Driver Diagnostics");
// Shuffleboard.getTab("Arm").add("Arm Output", arm);


SmartDashboard.putNumber("Yaw", pidgey.getYaw());
SmartDashboard.putNumber("Angle", pidgey.getAngle());
SmartDashboard.putNumber("Rotation2d", pidgey.Rotation2d());

// #endregion Testing
}

Expand Down
81 changes: 81 additions & 0 deletions src/main/java/frc/robot/experimental/GyroIOPigeon2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* This is from FRC 2910, 2023 season with some
* updates for this year's version of the CTRE Phoenix library.
*/

package frc.robot.experimental;

import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.StatusSignal;
import com.ctre.phoenix6.configs.GyroTrimConfigs;
import com.ctre.phoenix6.configs.MountPoseConfigs;
import com.ctre.phoenix6.configs.Pigeon2Configuration;
import com.ctre.phoenix6.hardware.Pigeon2;
import edu.wpi.first.math.util.Units;
import frc.robot.util.Constants;


@SuppressWarnings("unused")

/**
* Implementation of the gyroscope class. Uses the Pigeon2 gyroscope to receive data about the robots yaw, pitch, and roll values.
*/
public class GyroIOPigeon2 implements GyroIO {

/**
* Pigeon2 gyroscope object. Receives direct data from the gyroscope about the yaw, pitch, and roll.
*/
private final Pigeon2 gyro;

/**
* Pigeon2 gyroIO implementation.
*
* @param canId Is the unique identifier to the gyroscope used on the robot.
* @param canBus The name of the CAN bus the device is connected to.
*/
private StatusSignal<Double> yawSignal;

private StatusSignal<Double> angularVelocitySignal;

private BaseStatusSignal[] signals;

public GyroIOPigeon2(int mountPose, double error, String canBus) {

gyro = new Pigeon2(mountPose, canBus);

Pigeon2Configuration config = new Pigeon2Configuration();
MountPoseConfigs mountPoseConfigs = new MountPoseConfigs();
mountPoseConfigs.MountPoseYaw = mountPose;
GyroTrimConfigs gyroTrimConfigs = new GyroTrimConfigs();
gyroTrimConfigs.GyroScalarZ = error;
config.MountPose = mountPoseConfigs;
config.GyroTrim = gyroTrimConfigs;
gyro.getConfigurator().apply(config);

yawSignal = gyro.getYaw();
// angularVelocitySignal = gyro.getAngularVelocityZ();
angularVelocitySignal = gyro.getAngularVelocityZDevice(); // Not sure if this is the correct method to use or ZWorld

signals = new BaseStatusSignal[2];
signals[0] = yawSignal;
signals[1] = angularVelocitySignal;
}


/*
@Override
public void updateInputs(GyroIOInputs inputs) {
inputs.connected = true;
inputs.yaw = Units.degreesToRadians(
BaseStatusSignalValue.getLatencyCompensatedValue(yawSignal, angularVelocitySignal));
inputs.pitch = Units.degreesToRadians(gyro.getPitch().getValue());
inputs.roll = Units.degreesToRadians(gyro.getRoll().getValue());
inputs.angularVelocity = Units.degreesToRadians(angularVelocitySignal.getValue());
}
*/
@Override
public BaseStatusSignal[] getSignals() {
return signals;
}
}
1 change: 0 additions & 1 deletion src/main/java/frc/robot/experimental/IntakeIndexTimer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package frc.robot.experimental;

import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import frc.robot.commands.SetIndex;
import frc.robot.commands.SetIntake;
import frc.robot.subsystems.IndexSubsystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot;
package frc.robot.subsystems;

import java.util.function.Supplier;

Expand All @@ -21,7 +21,8 @@
import edu.wpi.first.wpilibj.RobotController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Subsystem;
import frc.robot.generated.TunerConstants;
import frc.robot.RobotContainer;
import frc.robot.util.TunerConstants;

/**
* Class that extends the Phoenix SwerveDrivetrain class and implements subsystem
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/frc/robot/subsystems/Gyro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package frc.robot.subsystems;

import com.ctre.phoenix6.configs.MountPoseConfigs;
import com.ctre.phoenix6.configs.Pigeon2Configuration;
import com.ctre.phoenix6.hardware.Pigeon2;

/*
Pigeon2 treats +X as the forward axis
+Y as the left axis
+Z towards the sky
This is a common way to define the world frame reference for groundbased vehicles
*/

public class Gyro {

private final Pigeon2 pidgey;

public Gyro() {
pidgey = new Pigeon2(14); // ID from Change the ID as needed

// StatusSignal<Double> yawSignal;

/* User can change the configs if they want, or leave it empty for factory-default */
// Mimicing ArmSubsystem.java
pidgey.getConfigurator().apply(new Pigeon2Configuration());

var pidgeyConfigs = new Pigeon2Configuration();
/* Speed up signals to an appropriate rate */
// pidgey.getYaw().setUpdateFrequency(100);
// pidgey.getGravityVectorZ().setUpdateFrequency(100);
// pidgey.getAccelerationX().setUpdateFrequency(100);
var pidgeyMountConfigs = new MountPoseConfigs();
// pidgeyMountConfigs.MountPose = MountPoseConfigs.MountedPose.TwoDegreesPitch;

pidgey.getConfigurator().apply(pidgeyConfigs);
pidgey.getConfigurator().apply(pidgeyMountConfigs);
}

/* Not sure what difference is between these three
* Values will be posted to the Dashboard
*/
public double getYaw() {
return pidgey.getYaw().getValue();
}

public double getAngle() {
return pidgey.getAngle();
}

public double Rotation2d() {
return pidgey.getRotation2d().getDegrees();
}

/*
* The Pigeon2 class has a default reset method `reset()`
* So can it be called directly without this method?
* Maybe, but not 100% sure
*/

public void resetGyro() {
pidgey.reset();
}



} // end of class Gyro


/*
* Mount Calibration
* It’s recommended to perform a mount calibration when placement of the Pigeon 2.0 has been finalized.
* This can be done via the Calibration page in Tuner X.
*/

/* Documentation
https://api.ctr-electronics.com/phoenix6/release/java/com/ctre/phoenix6/hardware/Pigeon2.html
Iterative Example
https://github.com/CrossTheRoadElec/Phoenix6-Examples/blob/main/java/Pigeon2/src/main/java/frc/robot/Robot.java
* Method Summary
Modifier & Type | Method | Description
----------------|--------------- |-------------------
void | close() |
double | getAngle() | Returns the heading of the robot in degrees.
double | getRate() | Returns the rate of rotation of the Pigeon 2.
Rotation2d | getRotation2d() | Returns the heading of the robot as a Rotation2d.
Rotation3d | getRotation3d() | Returns the orientation of the robot as a Rotation3d created from the quaternion signals.
void | initSendable​(SendableBuilder builder) |
void | reset() | Resets the Pigeon 2 to a heading of zero.
*/

/*
* public double getAngle()
Returns the heading of the robot in degrees.
The angle increases as the Pigeon 2 turns clockwise when looked at from the top. This follows the NED axis convention.
The angle is continuous; that is, it will continue from 360 to 361 degrees. This allows for algorithms that wouldn't want to see a discontinuity in the gyro output as it sweeps past from 360 to 0 on the second time around.
Returns: The current heading of the robot in degrees
*/
5 changes: 2 additions & 3 deletions src/main/java/frc/robot/subsystems/ShooterSubsystem2.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ public ShooterSubsystem2() {
var flywheelConfigs0 = new Slot0Configs();
flywheelConfigs0
// https://github.com/CrossTheRoadElec/Phoenix6-Examples/blob/main/java/VelocityClosedLoop/src/main/java/frc/robot/Robot.java
// https://docs.wpilib.org/en/latest/docs/software/advanced-controls/introduction/tuning-flywheel.html
.withKP(0.10) // P and V are the most important for a flywheel
.withKI(0.00) // Should not be needed for a flywheel
.withKP(0.10)
.withKI(0.00)
.withKS(0.00) // Should low for a light flywheel? Maybe the pulley strength would impact it though?
.withKV(0.00);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package frc.robot.generated;
package frc.robot.util;

import com.ctre.phoenix6.configs.Slot0Configs;
import com.ctre.phoenix6.mechanisms.swerve.SwerveDrivetrainConstants;
Expand All @@ -8,7 +8,7 @@
import com.ctre.phoenix6.mechanisms.swerve.SwerveModuleConstants.SteerFeedbackType;

import edu.wpi.first.math.util.Units;
import frc.robot.CommandSwerveDrivetrain;
import frc.robot.subsystems.CommandSwerveDrivetrain;

// Generated by the Tuner X Swerve Project Generator
// https://v6.docs.ctr-electronics.com/en/stable/docs/tuner/tuner-swerve/index.html
Expand Down

0 comments on commit e2cb65b

Please sign in to comment.