generated from StuyPulse/Phil
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* started subsystem * some fixes to Amper and AmperImpl * Implemented Amper methods in AmperImpl.java, added ElevatorSim in AmperSim.java, added logging for lift and intake, added configure for lift and score motor Co-authored-by: Zixi52 <Zixi52@users.noreply.github.com> Co-authored-by: Baiulus <Baiulus@users.noreply.github.com> Co-authored-by: Naowal Rahman <naowal.ar@gmail.com> Co-authored-by: Rahel Arka <RahelArka@users.noreply.github.com> * clean up amper code * Added singleton in RobotContainer.java * Co-authored-by: Zixi52 <Zixi52@users.noreply.github.com> Co-authored-by: Rahuldeb75 <Rahuldeb75@users.noreply.github.com> Co-authored-by: Rahel Arka <RahelArka@users.noreply.github.com> Co-authored-by: Baiulus <Baiulus@users.noreply.github.com> Co-authored-by: Naowal Rahman <naowal.ar@gmail.com> Co-authored-by: Ian Shi <IanShiii@users.noreply.github.com * Made some fixes to Amper, AmperImpl * Organize settings + velocity conversion factor * Fix AmperSim --------- Co-authored-by: Kalimul Kaif <kalimul.kaif@stuypulse.com> Co-authored-by: Zixi52 <Zixi52@users.noreply.github.com> Co-authored-by: Baiulus <Baiulus@users.noreply.github.com> Co-authored-by: Rahel Arka <RahelArka@users.noreply.github.com> Co-authored-by: BenG49 <ben@goldfisher.com> Co-authored-by: BenG49 <64862590+BenG49@users.noreply.github.com>
- Loading branch information
1 parent
3daa165
commit 36fe001
Showing
7 changed files
with
296 additions
and
3 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
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
66 changes: 66 additions & 0 deletions
66
src/main/java/com/stuypulse/robot/subsystems/amper/Amper.java
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,66 @@ | ||
package com.stuypulse.robot.subsystems.amper; | ||
|
||
import com.stuypulse.robot.constants.Settings; | ||
import com.stuypulse.robot.constants.Settings.Amper.Lift; | ||
import com.stuypulse.stuylib.control.Controller; | ||
import com.stuypulse.stuylib.control.feedback.PIDController; | ||
import com.stuypulse.stuylib.math.SLMath; | ||
import com.stuypulse.stuylib.network.SmartNumber; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
/* | ||
AMP: | ||
1 motor | ||
1 limit switch | ||
IR Sensor | ||
LIFT: | ||
1 motor | ||
1 encoder | ||
Bottom (shooter) limit switch | ||
*/ | ||
|
||
public abstract class Amper extends SubsystemBase { | ||
|
||
private static Amper instance; | ||
|
||
static { | ||
instance = new AmperImpl(); | ||
} | ||
|
||
public static Amper getInstance() { | ||
return instance; | ||
} | ||
|
||
public final SmartNumber targetHeight; | ||
public final Controller liftController; | ||
|
||
public Amper() { | ||
liftController = new PIDController(Lift.PID.kP, Lift.PID.kI, Lift.PID.kD); | ||
targetHeight = new SmartNumber("Amp/Target Height", 0); // TODO: determine the default value | ||
} | ||
|
||
public void setTargetHeight(double height) { | ||
targetHeight.set(SLMath.clamp(height, Settings.Amper.Lift.MIN_HEIGHT, Settings.Amper.Lift.MAX_HEIGHT)); | ||
} | ||
|
||
public abstract boolean hasNote(); | ||
|
||
public abstract void score(); | ||
public abstract void intake(); | ||
public abstract void stopRoller(); | ||
|
||
public abstract boolean liftAtBottom(); | ||
public abstract double getLiftHeight(); | ||
public abstract void stopLift(); | ||
public abstract void setLiftVoltageImpl(double voltage); | ||
|
||
public abstract boolean touchingAmp(); | ||
|
||
@Override | ||
public void periodic() { | ||
setLiftVoltageImpl(liftController.update(targetHeight.get(), getLiftHeight())); | ||
} | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/com/stuypulse/robot/subsystems/amper/AmperImpl.java
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,99 @@ | ||
package com.stuypulse.robot.subsystems.amper; | ||
import com.revrobotics.CANSparkLowLevel.MotorType; | ||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.RelativeEncoder; | ||
import com.stuypulse.robot.constants.Motors; | ||
import com.stuypulse.robot.constants.Ports; | ||
import com.stuypulse.robot.constants.Settings; | ||
|
||
import edu.wpi.first.wpilibj.DigitalInput; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
||
|
||
public class AmperImpl extends Amper { | ||
|
||
private final CANSparkMax scoreMotor; | ||
private final CANSparkMax liftMotor; | ||
private final RelativeEncoder liftEncoder; | ||
|
||
private final DigitalInput alignedSwitch; | ||
private final DigitalInput minSwitch; | ||
private final DigitalInput ampIRSensor; | ||
|
||
public AmperImpl() { | ||
scoreMotor = new CANSparkMax(Ports.Amper.SCORE, MotorType.kBrushless); | ||
liftMotor = new CANSparkMax(Ports.Amper.LIFT, MotorType.kBrushless); | ||
liftEncoder = liftMotor.getEncoder(); | ||
|
||
liftEncoder.setPositionConversionFactor(Settings.Amper.Lift.Encoder.POSITION_CONVERSION); | ||
liftEncoder.setVelocityConversionFactor(Settings.Amper.Lift.Encoder.VELOCITY_CONVERSION); | ||
|
||
alignedSwitch = new DigitalInput(Ports.Amper.ALIGNED_SWITCH_CHANNEL); | ||
minSwitch = new DigitalInput(Ports.Amper.MIN_LIFT_CHANNEL); | ||
ampIRSensor = new DigitalInput(Ports.Amper.AMP_IR_CHANNEL); | ||
|
||
Motors.Amper.LIFT_MOTOR.configure(liftMotor); | ||
Motors.Amper.SCORE_MOTOR.configure(scoreMotor); | ||
} | ||
|
||
@Override | ||
public boolean hasNote() { | ||
return !ampIRSensor.get(); | ||
} | ||
|
||
@Override | ||
public boolean liftAtBottom() { | ||
return !minSwitch.get(); | ||
} | ||
|
||
@Override | ||
public double getLiftHeight() { | ||
return liftEncoder.getPosition(); | ||
} | ||
|
||
@Override | ||
public boolean touchingAmp() { | ||
return !alignedSwitch.get(); | ||
} | ||
|
||
@Override | ||
public void score() { | ||
scoreMotor.set(Settings.Amper.Score.ROLLER_SPEED.get()); | ||
} | ||
|
||
@Override | ||
public void intake() { | ||
scoreMotor.set(-Settings.Amper.Score.ROLLER_SPEED.get()); | ||
} | ||
|
||
@Override | ||
public void stopLift() { | ||
liftMotor.stopMotor(); | ||
} | ||
|
||
@Override | ||
public void stopRoller() { | ||
scoreMotor.stopMotor(); | ||
} | ||
|
||
@Override | ||
public void setLiftVoltageImpl(double voltage) { | ||
if (liftAtBottom() && voltage < 0) { | ||
stopLift(); | ||
} | ||
else { | ||
liftMotor.setVoltage(voltage); | ||
} | ||
} | ||
|
||
public void periodic() { | ||
super.periodic(); | ||
|
||
SmartDashboard.putNumber("Amper/Intake Speed", scoreMotor.get()); | ||
SmartDashboard.putNumber("Amper/Lift Speed", liftMotor.get()); | ||
SmartDashboard.putNumber("Amper/Intake Current", scoreMotor.getOutputCurrent()); | ||
SmartDashboard.putNumber("Amper/Lift Current", liftMotor.getOutputCurrent()); | ||
SmartDashboard.putNumber("Amper/Lift Height", getLiftHeight()); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/stuypulse/robot/subsystems/amper/AmperSim.java
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,75 @@ | ||
package com.stuypulse.robot.subsystems.amper; | ||
|
||
import static com.stuypulse.robot.constants.Settings.Amper.Lift.*; | ||
|
||
import com.stuypulse.robot.constants.Settings; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.ElevatorSim; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
||
public class AmperSim extends Amper { | ||
|
||
private final ElevatorSim sim; | ||
|
||
public AmperSim() { | ||
sim = new ElevatorSim( | ||
DCMotor.getNEO(1), | ||
Encoder.GEARING, | ||
CARRIAGE_MASS, | ||
Encoder.DRUM_RADIUS, | ||
MIN_HEIGHT, | ||
MAX_HEIGHT, | ||
true, | ||
0 | ||
); | ||
} | ||
|
||
@Override | ||
public boolean hasNote() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void intake() {} | ||
|
||
@Override | ||
public void score() {} | ||
|
||
@Override | ||
public boolean liftAtBottom() { | ||
return sim.hasHitLowerLimit(); | ||
} | ||
|
||
@Override | ||
public boolean touchingAmp() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void stopLift() { | ||
sim.setInputVoltage(0.0); | ||
} | ||
|
||
@Override | ||
public double getLiftHeight() { | ||
return sim.getPositionMeters(); | ||
} | ||
|
||
@Override | ||
public void setLiftVoltageImpl(double voltage) { | ||
sim.setInputVoltage(voltage); | ||
} | ||
|
||
@Override | ||
public void stopRoller() {} | ||
|
||
@Override | ||
public void simulationPeriodic() { | ||
sim.update(Settings.DT); | ||
|
||
SmartDashboard.putNumber("Amper/Lift Height", getLiftHeight()); | ||
} | ||
|
||
} | ||
|
||
|