-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from CyberCoyotes/gyro-adjustment
Gyro adjustment
- Loading branch information
Showing
7 changed files
with
267 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/frc/robot/experimental/ArmConstants.java.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Use this approach in offseason. | ||
See TunerConstants.java for an example of how to setup | ||
*/ | ||
|
||
package frc.robot.subsystems; | ||
|
||
public class ArmConstants { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* 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 org.littletonrobotics.junction.AutoLog; | ||
|
||
/** | ||
* Connects the software to the hardware and directly receives data from the gyroscope. | ||
*/ | ||
public interface GyroIO { | ||
/** | ||
* Reads information from sources (hardware or simulation) and updates the inputs object. | ||
* | ||
* @param inputs Contains the defaults for the input values listed above. | ||
*/ | ||
// default void updateInputs(GyroIOInputs inputs) {} | ||
|
||
default BaseStatusSignal[] getSignals() { | ||
return new BaseStatusSignal[0]; | ||
} | ||
|
||
|
||
/** | ||
* Holds data that can be read from the corresponding gyroscope IO implementation. | ||
*/ | ||
|
||
/* | ||
@AutoLog | ||
class GyroIOInputs { | ||
public boolean connected = false; | ||
public double yaw = 0; | ||
public double pitch = 0; | ||
public double roll = 0; | ||
public double angularVelocity = 0; | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/main/java/frc/robot/experimental/ShooterConstants.java.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package frc.robot.subsystems; | ||
|
||
import com.ctre.phoenix6.configs.CurrentLimitsConfigs; | ||
import com.ctre.phoenix6.configs.MotorOutputConfigs; | ||
import com.ctre.phoenix6.configs.Slot0Configs; | ||
import com.ctre.phoenix6.configs.VoltageConfigs; | ||
import com.ctre.phoenix6.controls.VelocityVoltage; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.ctre.phoenix6.StatusSignal; | ||
import com.ctre.phoenix6.configs.CurrentLimitsConfigs; | ||
import com.ctre.phoenix6.configs.MotorOutputConfigs; | ||
import com.ctre.phoenix6.configs.Slot0Configs; | ||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.configs.VoltageConfigs; | ||
import com.ctre.phoenix6.controls.VelocityVoltage; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.ctre.phoenix6.signals.NeutralModeValue; | ||
|
||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Constants; | ||
|
||
import frc.robot.Constants; | ||
|
||
public class ShooterConstants { | ||
|
||
// Declare variables for the motors to be controlled | ||
private TalonFX m_primaryMotor = new TalonFX(Constants.CANIDs.RIGHT_FLYWHEEL_ID, "rio"); // Right | ||
private TalonFX m_secondaryMotor = new TalonFX(Constants.CANIDs.LEFT_FLYWHEEL_ID, "rio"); // Left | ||
|
||
// TODO Tune this value | ||
public final double FLYWHEEL_VELOCITY = 100; // rotations per second (rps) | ||
public final double FLYWHEEL_VELOCITY_SHORT_RANGE = 40; // Not currently in use anywhere | ||
public final double FLYWHEEL_VELOCITY_LONG_RANGE = 60; // Not currently in use anywhere, Flywheel speed for long range shots only | ||
public final double FLYWHEEL_IDLE_VELOCITY = FLYWHEEL_VELOCITY * 0.30; // 30% of max speed | ||
public final double FLYWHEEL_MARGIN_ERROR = FLYWHEEL_VELOCITY * 0.10; // 5% of max speed | ||
public final double FLYWHEEL_MIN = FLYWHEEL_VELOCITY * .95; | ||
public final double FLYWHEEL_MAX = FLYWHEEL_VELOCITY * 1.05; | ||
|
||
|
||
// Class member variables | ||
private VelocityVoltage m_velocityVoltage = new VelocityVoltage(0); | ||
|
||
private double currentFlywheelVel = m_primaryMotor.getVelocity().getValue(); | ||
m_primaryMotor.setControl(m_velocityVoltage); | ||
m_secondaryMotor.setControl(m_velocityVoltage); | ||
|
||
m_primaryMotor.getConfigurator().apply(new TalonFXConfiguration()); | ||
m_secondaryMotor.getConfigurator().apply(new TalonFXConfiguration()); | ||
|
||
/* Various Configs */ | ||
/* | ||
| Ks | output to overcome static friction (output) | ||
| Kv | output per unit of velocity (output/rps) | ||
| Ka | output per unit of acceleration; unused, as there is no target acceleration (output/(rps/s)) | ||
| Kp | output per unit of error (output/rps) | ||
| Ki | output per unit of integrated error in velocity (output/rotation) | ||
| kd | output per unit of error derivative in velocity (output/(rps/s)) | ||
*/ | ||
|
||
/* Example provided by CTRE */ | ||
/* | ||
slot0Configs.kS = 0.05; // Add 0.05 V output to overcome static friction | ||
slot0Configs.kV = 0.12; // A velocity target of 1 rps results in 0.12 V output | ||
slot0Configs.kP = 0.11; // An error of 1 rps results in 0.11 V output | ||
slot0Configs.kI = 0; // no output for integrated error | ||
slot0Configs.kD = 0; // no output for error derivative | ||
*/ | ||
|
||
var flywheelConfigs0 = new Slot0Configs(); | ||
flywheelConfigs0 | ||
// https://github.com/CrossTheRoadElec/Phoenix6-Examples/blob/main/java/VelocityClosedLoop/src/main/java/frc/robot/Robot.java | ||
.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); | ||
|
||
|
||
var flywheelVelocityConfig = new VoltageConfigs(); | ||
flywheelVelocityConfig | ||
.withPeakForwardVoltage(12) // FRC 2910 running 12 | ||
.withPeakReverseVoltage(12); // Originally -8, with negative the "helper" text goes away | ||
|
||
var flywheelCurrentConfigs = new CurrentLimitsConfigs(); | ||
flywheelCurrentConfigs | ||
.withStatorCurrentLimit(60) | ||
.withStatorCurrentLimitEnable(true); | ||
|
||
var flywheelMotorOutput = new MotorOutputConfigs(); | ||
flywheelMotorOutput | ||
.withNeutralMode(NeutralModeValue.Coast); | ||
|
||
/* Apply Configs */ | ||
m_primaryMotor.getConfigurator().apply(flywheelConfigs0); | ||
m_secondaryMotor.getConfigurator().apply(flywheelConfigs0); | ||
|
||
m_primaryMotor.getConfigurator().apply(flywheelVelocityConfig); | ||
m_secondaryMotor.getConfigurator().apply(flywheelVelocityConfig); | ||
|
||
m_primaryMotor.getConfigurator().apply(flywheelCurrentConfigs); | ||
m_secondaryMotor.getConfigurator().apply(flywheelCurrentConfigs); | ||
|
||
m_primaryMotor.getConfigurator().apply(flywheelMotorOutput); | ||
m_secondaryMotor.getConfigurator().apply(flywheelMotorOutput); | ||
|
||
m_primaryMotor.setInverted(true); | ||
m_secondaryMotor.setInverted(true); | ||
|
||
// Alternate way to get the current flywheel velocity? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters