-
Notifications
You must be signed in to change notification settings - Fork 0
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
climb pivot + algae flywheel #35
base: main
Are you sure you want to change the base?
Changes from 8 commits
d24faf1
abfc315
7fe4ae0
c51f6e4
3c62df4
a9b9ffe
fe1cad3
3a40871
207acce
e53f2e8
60d19a5
aa5204e
398e90a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// 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.commands.drive; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.pivotforcoralorsomeshit.CoralPivot; | ||
|
||
public class CoralPivot extends Command { | ||
/** Creates a new CoralPivot. */ | ||
private final CoralPivot coralPivot; | ||
Check warning on line 12 in src/main/java/frc/robot/commands/drive/DealgaefierPivot.java
|
||
private final double targetPosition = 0; | ||
Check warning on line 13 in src/main/java/frc/robot/commands/drive/DealgaefierPivot.java
|
||
|
||
public CoralPivot(CoralPivot coralPivot, double targetPosition) { | ||
this.coralPivot = coralPivot; | ||
this.targetPosition = targetPosition; | ||
addRequirements(coralPivot); | ||
// Use addRequirements() here to declare subsystem dependencies. | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() { | ||
coralPivot.setPivotPosition(targetPosition); | ||
} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() {} | ||
|
||
// Called once the command ends or is interrupted. | ||
@Override | ||
public void end(boolean interrupted) { | ||
coralPivot.stop(); | ||
|
||
} | ||
|
||
// Returns true when the command should end. | ||
@Override | ||
public boolean isFinished() { | ||
double error = Math.abs(coralPivot.getCurrentPosition() - targetPosition); | ||
return error < 1.0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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.subsystems.flywheel; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.subsystems.flywheel.FlywheelConstants; | ||
|
||
public class FlywheelSubsystem extends SubsystemBase { | ||
/** Creates a new FlywheelSubsystem. */ | ||
private FlywheelInterface flywheelInterface; | ||
|
||
private FlywheelInputsAutoLogged inputs = new FlywheelInputsAutoLogged(); | ||
|
||
public Flywheel() { | ||
|
||
} | ||
|
||
public double getFlywheelSpeed() { | ||
return flywheelInterface.getFlywheelSpeed(); | ||
} | ||
|
||
public double getVolts() { | ||
return flywheelInterface.getVolts(); | ||
} | ||
|
||
public void setFlywheelSpeed(double speed) { | ||
flywheelInterface.setFlywheelSpeed(speed); | ||
} | ||
|
||
public void setVolts(double volts) { | ||
flywheelInterface.setVolts(volts); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
// This method will be called once per scheduler run | ||
flywheelInterface.updateInputs(inputs); | ||
Logger.processInputs("Flywheel/", inputs); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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.subsystems.flywheel; | ||
|
||
import com.ctre.phoenix6.hardware.TalonFX; | ||
|
||
/** Add your docs here. */ | ||
public class FlywheelConstants { | ||
public static final int FLYWHEEL_MOTOR_ID = 0-9; | ||
public static final double FLYWHEEL_GEAR_RATIO = 0; | ||
public static final double FLYWHEEL_P = 0; | ||
public static final double FLYWHEEL_I = 0; | ||
public static final double FLYWHEEL_D = 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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.subsystems.flywheel; | ||
import org.littletonrobotics.junction.AutoLog; | ||
/** Add your docs here. */ | ||
public class FlywheelInterface { | ||
@AutoLog | ||
public static class FlywheelInterface { | ||
public double leaderMotorPosition = 0.0; | ||
} | ||
|
||
|
||
public default void updateInputs(FlywheelInterface inputs) {} | ||
|
||
|
||
public default double getFlywheelSpeed() { | ||
return 0.0; | ||
} | ||
|
||
public default void setFlywheelSpeed(double speed) {} | ||
|
||
public default void setVolts(double volts) {} | ||
|
||
public default double getVolts() { | ||
return 0.0; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// 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.subsystems.flywheel; | ||
|
||
/** Add your docs here. */ | ||
public class PhysicalFlywheel {} |
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.subsystems.flywheel; | ||
|
||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.FlywheelSim; | ||
|
||
/** Add your docs here. */ | ||
public class SimulatedFlywheel implements FlywheelInterface { | ||
private SimulatedFlywheel simulatedflywheel = | ||
new SimulatedFlywheel( | ||
DCMotor.getFalcon500(2), | ||
FlywheelConstants.FLYWHEEL_GEAR_RATIO, | ||
true, | ||
0.0); | ||
private PIDController simPID; | ||
private double currentVolts; | ||
|
||
public SimulatedFlywheel(DCMotor dcMotor, double flywheelGearRatio, boolean b, double d) { | ||
simPID = | ||
new PIDController( | ||
FlywheelConstants.FLYWHEEL_P, | ||
FlywheelConstants.FLYWHEEL_I, | ||
FlywheelConstants.FLYWHEEL_D); | ||
} | ||
|
||
public void updateInputs(FlywheelInputs inputs) { | ||
inputs.leaderMotorPosition = getFlywheelPosition(); | ||
inputs.followerMotorPosition = getFlywheelPosition(); | ||
} | ||
|
||
public void setFlywheelspeed(double speed) { | ||
setVolts(simPID.calculate(getFlywheelSpeed(), speed)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure your units are and will be consistent. also your |
||
} | ||
|
||
public double getFlywheelSpeed() { | ||
return flywheelSim.getAngularVelocityRPM(); | ||
} | ||
|
||
public void setVolts(double volts) { | ||
currentVolts = simPID.calculate(volts); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you are setting straight voltage i wouldn't use pid. |
||
elevatorSim.setInputVoltage(currentVolts); | ||
} | ||
|
||
public double getVolts() { | ||
return currentVolts; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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.subsystems.pivot; | ||
import com.ctre.phoenix.motorcontrol.ControlMode; | ||
import com.ctre.phoenix.motorcontrol.can.TalonFX; | ||
import com.ctre.phoenix.motorcontrol.TalonFXConfiguration; | ||
import com.ctre.phoenix.motorcontrol.NeutralMode; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Constants; | ||
|
||
public class ClimbPivot extends SubsystemBase { | ||
/** Creates a new ClimbPivot. */ | ||
public TalonFX climbPivotMotor = new TalonFX(Constants.CLIMB_PIVOT_MOTOR); | ||
private static final int TICKS_PER_ROTATION = 2048; | ||
private static final double GEAR_RATIO = 10.0; | ||
|
||
public ClimbPivot() { | ||
TalonFXConfiguration config = new TalonFXConfiguration(); | ||
config.slot0.kP = 0.0; | ||
config.slot0.kI = 0.0; | ||
config.slot0.kD = 0.0; | ||
config.slot0.kF = 0.0; | ||
config.motionCruiseVelocity = 15000; | ||
climb.motionAcceleration = 6000; | ||
climbPivotMotor.configAllSettings(config); | ||
climbPivotMotor.setNeutralMode(NeutralMode.Brake); | ||
climbPivotMotor.setSelectedSensorPosition(0); | ||
} | ||
|
||
public void setPivotPosition(double degrees) { | ||
double ticks = degreesToTicks(degrees); | ||
climbPivotMotor.set(ControlMode.MotionMagic, ticks); | ||
} | ||
|
||
public double getCurrentPosition() { | ||
return ticksToDegrees(climbPivotMotor.getSelectedSensorPosition()); | ||
} | ||
|
||
public void stop() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait I'm not sure what the mechanism looks like, but what is stop doing? If we have one method used for setting a position, it seems weird having another method for just like turning off the motor. Rather than that it would make more sense to me that the commands that call this would just use |
||
climbPivotMotor.set(ControlMode.PercentOutput, 0); | ||
} | ||
|
||
private double degreesToTicks(double degrees) { | ||
return degrees / 360.0 * TICKS_PER_ROTATION * GEAR_RATIO; | ||
} | ||
|
||
private double ticksToDegrees(double ticks) { | ||
return ticks / (TICKS_PER_ROTATION * GEAR_RATIO) * 360.0; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
System.out.println("Current Position: " + getCurrentPosition()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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.subsystems.pivot; | ||
import com.ctre.phoenix.motorcontrol.ControlMode; | ||
import com.ctre.phoenix.motorcontrol.can.TalonFX; | ||
import com.ctre.phoenix.motorcontrol.TalonFXConfiguration; | ||
import com.ctre.phoenix.motorcontrol.NeutralMode; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Constants; | ||
|
||
public class CoralPivot extends SubsystemBase { | ||
/** Creates a new Cpivot. */ | ||
public TalonFX dealgaefierPivotMotor = new TalonFX(Constants.CORAL_PIVOT_MOTOR); | ||
private static final int TICKS_PER_ROTATION = 2048; | ||
private static final double GEAR_RATIO = 10.0; | ||
|
||
public CoralPivot() { | ||
TalonFXConfiguration config = new TalonFXConfiguration(); | ||
config.slot0.kP = 0.0; | ||
config.slot0.kI = 0.0; | ||
config.slot0.kD = 0.0; | ||
config.slot0.kF = 0.0; | ||
config.motionCruiseVelocity = 15000; | ||
config.motionAcceleration = 6000; | ||
dealgaefierPivotMotor.configAllSettings(config); | ||
dealgaefierPivotMotor.setNeutralMode(NeutralMode.Brake); | ||
dealgaefierPivotMotor.setSelectedSensorPosition(0); | ||
} | ||
|
||
public void setPivotPosition(double degrees) { | ||
double ticks = degreesToTicks(degrees); | ||
dealgaefierPivotMotor.set(ControlMode.MotionMagic, ticks); | ||
} | ||
|
||
public double getCurrentPosition() { | ||
return ticksToDegrees(dealgaefierPivotMotor.getSelectedSensorPosition()); | ||
} | ||
|
||
public void stop() { | ||
dealgaefierPivotMotor.set(ControlMode.PercentOutput, 0); | ||
} | ||
|
||
private double degreesToTicks(double degrees) { | ||
return degrees / 360.0 * TICKS_PER_ROTATION * GEAR_RATIO; | ||
} | ||
|
||
private double ticksToDegrees(double ticks) { | ||
return ticks / (TICKS_PER_ROTATION * GEAR_RATIO) * 360.0; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
System.out.println("Current Position: " + getCurrentPosition()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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.subsystems.pivot; | ||
|
||
/** Add your docs here. */ | ||
public class PivotConstants { | ||
public static final TalonFX CORAL_PIVOT_MOTOR = 0-9; | ||
public static final TalonFX CLIMB_PIVOT_MOTOR = 0-9; | ||
public static final TalonFX FLYWHEEL_MOTOR = 0-9; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id log this value to akit by adding something like
flywheelAppliedVolts
to the interface, and then setting this value equal to that inupdateInputs
.