11package frc .robot .subsystems .elevator ;
22
3- import edu .wpi .first .math .MathUtil ;
43import edu .wpi .first .math .controller .ArmFeedforward ;
54import edu .wpi .first .math .controller .ElevatorFeedforward ;
65import edu .wpi .first .math .trajectory .TrapezoidProfile ;
@@ -48,7 +47,7 @@ public class Elevator extends SubsystemBase {
4847 private TrapezoidProfile .State barCurrent = new TrapezoidProfile .State ();
4948
5049 private double goal ;
51- private double barGoalPos ;
50+ // private double barGoalPos;
5251 private final ElevatorFeedforward elevatorFFModel ;
5352 private final ArmFeedforward barFFmodel ;
5453
@@ -66,8 +65,8 @@ public Elevator(ElevatorIO elevator, AmpBarIO ampBar) {
6665 kP .initDefault (0.44 );
6766 kI .initDefault (0 );
6867
69- barkP .initDefault (0 );
70- barkV .initDefault (0 );
68+ barkP .initDefault (0.04 );
69+ barkV .initDefault (4 );
7170 barkG .initDefault (0 );
7271 break ;
7372 case REPLAY :
@@ -115,8 +114,8 @@ public Elevator(ElevatorIO elevator, AmpBarIO ampBar) {
115114 extenderProfile = new TrapezoidProfile (extenderConstraints );
116115 extenderCurrent = extenderProfile .calculate (0 , extenderCurrent , extenderGoal );
117116
118- maxVelocityDegPerSec = 15 ;
119- maxAccelerationDegPerSecSquared = 1 ;
117+ maxVelocityDegPerSec = 90 ;
118+ maxAccelerationDegPerSecSquared = 30 ;
120119
121120 barConstraints =
122121 new TrapezoidProfile .Constraints (maxVelocityDegPerSec , maxAccelerationDegPerSecSquared );
@@ -126,7 +125,7 @@ public Elevator(ElevatorIO elevator, AmpBarIO ampBar) {
126125 this .elevator .configurePID (kP .get (), 0 , 0 );
127126 elevatorFFModel = new ElevatorFeedforward (kS .get (), kG .get (), kV .get (), kA .get ());
128127
129- ampBar .configurePID (barkP .get (), 0 , 0 );
128+ this . ampBar .configurePID (barkP .get (), 0 , 0 );
130129 barFFmodel = new ArmFeedforward (0 , barkG .get (), barkV .get (), 0 );
131130 }
132131
@@ -135,7 +134,7 @@ public boolean atGoal() {
135134 }
136135
137136 public boolean barAtGoal () {
138- return (Math .abs (aInputs .barPositionDegrees - barGoalPos )
137+ return (Math .abs (aInputs .barPositionDegrees - barGoal . position )
139138 <= Constants .ElevatorConstants .BAR_THRESHOLD );
140139 }
141140
@@ -152,13 +151,17 @@ private double getBarError() {
152151 return aInputs .barPositionSetpointDegrees - aInputs .barPositionDegrees ;
153152 }
154153
154+ private double getbarErrorToGoal () {
155+ return barGoal .position - aInputs .barPositionDegrees ;
156+ }
157+
155158 public boolean elevatorAtSetpoint () {
156159 return (Math .abs (getElevatorError ()) <= Constants .ElevatorConstants .THRESHOLD );
157160 }
158161
159- public boolean ampBarAtSetpoint () {
162+ public boolean ampBarAtGoal () {
160163
161- return (Math .abs (getBarError ()) <= Constants .ElevatorConstants .BAR_THRESHOLD );
164+ return (Math .abs (getbarErrorToGoal ()) <= Constants .ElevatorConstants .BAR_THRESHOLD );
162165 }
163166
164167 public void setBarBrakeMode (boolean bool ) {
@@ -171,7 +174,7 @@ public double getBarPositionRotations() {
171174
172175 public void setBarPosition (double positionRotations , double velocityDegsPerSec ) {
173176
174- positionRotations = MathUtil .clamp (positionRotations , 0 , 20 );
177+ // positionRotations = MathUtil.clamp(positionRotations, 0, 20);
175178 ampBar .setPositionSetpoint (
176179 positionRotations ,
177180 barFFmodel .calculate (
@@ -183,8 +186,9 @@ public void stopAmpBar() {
183186 }
184187
185188 public void setBarGoal (double setpoint ) {
186- this . barGoalPos = setpoint ;
189+
187190 barGoal = new TrapezoidProfile .State (setpoint , 0 );
191+ Logger .recordOutput ("bar goal" , setpoint );
188192 }
189193
190194 public void setbarCurrent (double current ) {
@@ -242,10 +246,15 @@ public void periodic() {
242246 Logger .processInputs ("Amp bar inputs" , aInputs );
243247
244248 Logger .recordOutput ("amp bar error" , getBarError ());
245- Logger .recordOutput ("amp bar goal" , barGoalPos );
249+ Logger .recordOutput ("amp bar goal" , barGoal . position );
246250
247251 if (kP .hasChanged (hashCode ()) || kI .hasChanged (hashCode ())) {
248252 elevator .configurePID (kP .get (), kI .get (), 0 );
249253 }
254+ if (barkP .hasChanged (hashCode ())
255+ || barkV .hasChanged (hashCode ())
256+ || barkG .hasChanged (hashCode ())) {
257+ ampBar .configurePID (barkP .get (), 0 , 0 );
258+ }
250259 }
251260}
0 commit comments