- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Elevator safety - max Chen #99
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
base: main
Are you sure you want to change the base?
Changes from all commits
68ec3d0
              2c3d07b
              731a1ac
              ef5d23e
              ade8c2c
              9e56f81
              84529b6
              0016bdd
              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,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.commands.elevator; | ||
|  | ||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import frc.robot.subsystems.elevator.ElevatorConstants; | ||
| import frc.robot.subsystems.elevator.ElevatorSubsystem; | ||
|  | ||
| /* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */ | ||
| public class ZeroElevator extends Command { | ||
| 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 this a command factory in elevator subsystem 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. ok -maxc | ||
| /** Creates a new ZeroElevator. */ | ||
| ElevatorSubsystem elevatorSubsystem; | ||
|  | ||
| public ZeroElevator(ElevatorSubsystem elevatorSubsystem) { | ||
| // Use addRequirements() here to declare subsystem dependencies. | ||
| this.elevatorSubsystem = elevatorSubsystem; | ||
| addRequirements(elevatorSubsystem); | ||
| } | ||
|  | ||
| // Called when the command is initially scheduled. | ||
| @Override | ||
| public void initialize() {} | ||
|  | ||
| // Called every time the scheduler runs while the command is scheduled. | ||
| @Override | ||
| public void execute() { | ||
| elevatorSubsystem.setElevatorPosition(ElevatorConstants.MIN_HEIGHT); // zeroes it | ||
| } | ||
|  | ||
| // Called once the command ends or is interrupted. | ||
| @Override | ||
| public void end(boolean interrupted) { | ||
| elevatorSubsystem.setVolts(0); //stop it and stuff | ||
| } | ||
| // Returns true when the command should end. | ||
| @Override | ||
| public boolean isFinished() { | ||
| return false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|  | @@ -11,7 +11,7 @@ public class ElevatorConstants { | |||||||||
| public static final int ELEVATOR_LEADER_MOTOR_ID = 0; | ||||||||||
| public static final int ELEVATOR_FOLLOWER_MOTOR_ID = 28; | ||||||||||
|  | ||||||||||
| public static final double ELEVATOR_P = 1; | ||||||||||
| public static final double ELEVATOR_P = 2; | ||||||||||
| public static final double ELEVATOR_I = 0; | ||||||||||
| public static final double ELEVATOR_D = 0; | ||||||||||
| public static final double ELEVATOR_S = 0; | ||||||||||
|  | @@ -26,11 +26,13 @@ public class ElevatorConstants { | |||||||||
| public static final double MAX_HEIGHT = 3; | ||||||||||
| public static final double INCLINE_ANGLE_RADIANS = Units.degreesToRadians(8); | ||||||||||
| public static final boolean SIMULATE_GRAVITY = true; | ||||||||||
|  | ||||||||||
| //stator and supply | ||||||||||
| public static final double STATOR_CURRENT_LIMIT = 0; | ||||||||||
| public static final double SUPPLY_CURRENT_LIMIT = 0; | ||||||||||
| public static final boolean STATOR_CURRENT_LIMIT_ENABLE = false; | ||||||||||
| public static final boolean SUPPLY_CURRENT_LIMIT_ENABLE = false; | ||||||||||
| public static final double MAX_STATOR_THRESHOLD = 59343494; | ||||||||||
| public static final double MIN_STATOR_THRESHOLD = 59343494; | ||||||||||
|  | ||||||||||
| 
      Comment on lines
    
      +34
     to 
      36
    
   
     | ||||||||||
| public static final double MAX_STATOR_THRESHOLD = 59343494; | |
| public static final double MIN_STATOR_THRESHOLD = 59343494; | |
| public static final double MAX_STATOR_THRESHOLD = 40.0; | |
| public static final double MIN_STATOR_THRESHOLD = 0.0; | 
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.
it said 59334343494 is not operational limits???
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -4,6 +4,8 @@ | |
|  | ||
| package frc.robot.subsystems.elevator; | ||
|  | ||
| import static edu.wpi.first.units.Units.Rotations; | ||
|  | ||
| import com.ctre.phoenix6.BaseStatusSignal; | ||
| import com.ctre.phoenix6.StatusSignal; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
|  | @@ -13,6 +15,7 @@ | |
| import com.ctre.phoenix6.signals.InvertedValue; | ||
| import com.ctre.phoenix6.signals.NeutralModeValue; | ||
| import edu.wpi.first.units.measure.Angle; | ||
| import edu.wpi.first.units.measure.Current; | ||
| import edu.wpi.first.units.measure.Voltage; | ||
| import frc.robot.Constants.HardwareConstants; | ||
|  | ||
|  | @@ -30,6 +33,7 @@ public class PhysicalElevator implements ElevatorInterface { | |
| private final StatusSignal<Voltage> followerAppliedVoltage; | ||
| private final StatusSignal<Double> followerDutyCycle; | ||
| private final StatusSignal<Double> leaderDutyCycle; | ||
| private final StatusSignal<Current> elevatorStatorCurrent; | ||
|  | ||
| private double desiredPosition; | ||
|  | ||
|  | @@ -87,7 +91,7 @@ public PhysicalElevator() { | |
| followerAppliedVoltage = followerMotor.getMotorVoltage(); | ||
| followerDutyCycle = followerMotor.getDutyCycle(); | ||
| leaderDutyCycle = leaderMotor.getDutyCycle(); | ||
|  | ||
| elevatorStatorCurrent = leaderMotor.getStatorCurrent(); | ||
| BaseStatusSignal.setUpdateFrequencyForAll( | ||
| HardwareConstants.STATUS_SIGNAL_FREQUENCY, | ||
| leaderPosition, | ||
|  | @@ -98,6 +102,29 @@ public PhysicalElevator() { | |
| followerDutyCycle); | ||
|  | ||
| desiredPosition = 0.0; | ||
| } | ||
| /** | ||
| * Homing to prevent stalling. If there is too much stator current, that shows stalling, so we just set that to the max/or min positions and stop the motor | ||
| * | ||
| */ | ||
| public void homing() { | ||
| if (leaderMotor.getStatorCurrent().getValueAsDouble() >= ElevatorConstants.MAX_STATOR_THRESHOLD && leaderMotor.getVelocity().getValueAsDouble() >= 0.0) { //below stator threshold AND going in positive direction (going down) | ||
|         
                  JacksonElia marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| leaderMotor.setPosition(0);//set encoder back to 0 | ||
| followerMotor.setPosition(0); // set encoder back to 0 | ||
| //leaderMotor.setPosition(Rotations.of(0.0)); | ||
| followerMotor.set(0); | ||
| leaderMotor.set(0);} | ||
| 
      Comment on lines
    
      +112
     to 
      +116
    
   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. do you need to set both the leader and follower? Couldn't you just do the leader? | ||
|  | ||
| else if (leaderMotor.getStatorCurrent().getValueAsDouble() <= ElevatorConstants.MIN_STATOR_THRESHOLD && leaderMotor.getVelocity().getValueAsDouble() <= 0.0) { //above stator threshold AND going in negative direction (going up) | ||
| leaderMotor.setPosition(ElevatorConstants.MAX_HEIGHT);//set encoder to max height | ||
| followerMotor.setPosition(ElevatorConstants.MAX_HEIGHT); // set encoder to max height | ||
| 
      Comment on lines
    
      +119
     to 
      +120
    
   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. Idk if you want to set the position here, it could lead to the elevator getting zeroed wrong I think 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. dat da whole point of dis tho 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. no but like we should only ever zero it at the bottom i feel. Like what if the elevator gets stuck on something while its going up, or it gets 90% of the way up and bc of fucky belt stuff can't go any further? | ||
| //leaderMotor.setPosition(Rotations.of(0.0)); | ||
| followerMotor.set(0); | ||
| leaderMotor.set(0); | ||
| } | ||
|  | ||
|  | ||
|  | ||
| } | ||
|  | ||
| @Override | ||
|  | @@ -144,4 +171,5 @@ public void setVolts(double volts) { | |
| public double getVolts() { | ||
| return leaderAppliedVoltage.getValueAsDouble(); | ||
| } | ||
|  | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -77,4 +77,7 @@ public void setVolts(double volts) { | |
| public double getVolts() { | ||
| return currentVolts; | ||
| } | ||
|  | ||
|  | ||
|  | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -181,4 +181,11 @@ public record ModuleConfig( | |
| SensorDirectionValue encoderReversed, | ||
| InvertedValue turnReversed, | ||
| InvertedValue driveReversed) {} | ||
|  | ||
|  | ||
| // The limits for the gyro | ||
| public static final double MAX_ROLL_ANGLE = 30; // degrees | ||
| public static final double MAX_PITCH_ANGLE = 20; // degrees | ||
| 
      Comment on lines
    
      +187
     to 
      +188
    
   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. We should maybe try to "tune" these values, but these are probably pretty good | ||
| // public static final double MAX_ACCEL_X = 69; | ||
| // public static final double MAX_ACCEL_Y = 432423; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -309,6 +309,14 @@ public boolean getZeroedSpeeds(ChassisSpeeds speeds) { | |
| public double getHeading() { | ||
| return gyroInputs.yawDegrees; | ||
| } | ||
| /** Returns the pitch of the robot as double*/ | ||
| public double getPitch() { | ||
| 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. Docstrings? 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. no 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 the docstring have a return in it, and specify what units/direction this is in. E.g. Gets the pitch of the robot in degrees, positive being when the robot leans forwards (this is just a guess, I could be wrong, so double check it) | ||
| return gyroInputs.pitchDegrees; | ||
| } | ||
|  | ||
| public double getRoll() { | ||
| return gyroInputs.rollDegrees; | ||
| } | ||
|  | ||
| /** | ||
| * Gets the rate of rotation of the robot. | ||
|  | ||
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.