@@ -41,6 +41,7 @@ public static class PivotInputs {
4141 public double velocityRadsPerSec = 0.0 ;
4242 public double [] appliedVolts = new double [] {};
4343 public double [] supplyCurrentAmps = new double [] {};
44+ public double [] statorCurrentAmps = new double [] {};
4445 public double [] temperatureCelsius = new double [] {};
4546 }
4647
@@ -62,6 +63,7 @@ public static class PivotInputs {
6263 private StatusSignal <Double > velocityRotationsPerSec ;
6364 private List <StatusSignal <Double >> appliedVolts ;
6465 private List <StatusSignal <Double >> supplyCurrentAmps ;
66+ private List <StatusSignal <Double >> statorCurrentAmps ;
6567 private List <StatusSignal <Double >> temperatureCelsius ;
6668
6769 // Control modes
@@ -92,6 +94,9 @@ public PivotKrakenHardware(KrakenConfiguration configuration) {
9294 motorConfiguration .Voltage .PeakForwardVoltage = configuration .kPeakForwardVoltage ();
9395 motorConfiguration .Voltage .PeakReverseVoltage = configuration .kPeakReverseVoltage ();
9496
97+ // Reset encoder on startup
98+ kLeadMotor .setPosition (0.0 );
99+
95100 // Setup feedback sensor for position control
96101 if (PivotConstants .kUseThroughBore ) {
97102 throughBoreEncoder = new DutyCycleEncoder (PivotConstants .kThroughBoreEncoderPort );
@@ -110,6 +115,7 @@ public PivotKrakenHardware(KrakenConfiguration configuration) {
110115 velocityRotationsPerSec = kLeadMotor .getVelocity ();
111116 appliedVolts = List .of (kLeadMotor .getMotorVoltage (), kFollowMotor .getMotorVoltage ());
112117 supplyCurrentAmps = List .of (kLeadMotor .getSupplyCurrent (), kFollowMotor .getSupplyCurrent ());
118+ statorCurrentAmps = List .of (kLeadMotor .getStatorCurrent (), kFollowMotor .getStatorCurrent ());
113119 temperatureCelsius = List .of (kLeadMotor .getDeviceTemp (), kFollowMotor .getDeviceTemp ());
114120
115121 BaseStatusSignal .setUpdateFrequencyForAll (
@@ -120,6 +126,8 @@ public PivotKrakenHardware(KrakenConfiguration configuration) {
120126 appliedVolts .get (1 ),
121127 supplyCurrentAmps .get (0 ),
122128 supplyCurrentAmps .get (1 ),
129+ statorCurrentAmps .get (0 ),
130+ statorCurrentAmps .get (1 ),
123131 temperatureCelsius .get (0 ),
124132 temperatureCelsius .get (1 ));
125133
@@ -141,11 +149,15 @@ public void updateInputs(PivotInputs inputs) {
141149 velocityRotationsPerSec ,
142150 appliedVolts .get (0 ),
143151 supplyCurrentAmps .get (0 ),
152+ statorCurrentAmps .get (0 ),
144153 temperatureCelsius .get (0 ))
145154 .isOK ();
146155 inputs .followerMotorConnected =
147156 BaseStatusSignal .refreshAll (
148- appliedVolts .get (1 ), supplyCurrentAmps .get (1 ), temperatureCelsius .get (1 ))
157+ appliedVolts .get (1 ),
158+ supplyCurrentAmps .get (1 ),
159+ statorCurrentAmps .get (1 ),
160+ temperatureCelsius .get (1 ))
149161 .isOK ();
150162
151163 inputs .inteneralPosition =
@@ -156,6 +168,8 @@ public void updateInputs(PivotInputs inputs) {
156168 appliedVolts .stream ().mapToDouble (StatusSignal ::getValueAsDouble ).toArray ();
157169 inputs .supplyCurrentAmps =
158170 supplyCurrentAmps .stream ().mapToDouble (StatusSignal ::getValueAsDouble ).toArray ();
171+ inputs .statorCurrentAmps =
172+ statorCurrentAmps .stream ().mapToDouble (StatusSignal ::getValueAsDouble ).toArray ();
159173 inputs .temperatureCelsius =
160174 temperatureCelsius .stream ().mapToDouble (StatusSignal ::getValueAsDouble ).toArray ();
161175 }
@@ -176,7 +190,8 @@ public void setVoltage(double voltage) {
176190 * @param feedforwardOutput Feedforward that will also be applied to the control effort
177191 */
178192 public void setPosition (double positionRads ) {
179- kLeadMotor .setControl (kPositionVoltage .withPosition (positionRads ).withSlot (0 ));
193+ kLeadMotor .setControl (
194+ kPositionVoltage .withPosition (Units .radiansToRotations (positionRads )).withSlot (0 ));
180195 }
181196
182197 /** Sets the motor control to neutral, then switching to the default neutral control mode */
@@ -220,7 +235,13 @@ public void setMotionMagicConstraints(double maxVelocity, double maxAcceleration
220235
221236 motionMagicConfiguration .MotionMagicCruiseVelocity = maxVelocity ;
222237 motionMagicConfiguration .MotionMagicAcceleration = maxAcceleration ;
238+ motionMagicConfiguration .MotionMagicJerk = 10.0 * maxAcceleration ;
223239
224240 kLeadMotor .getConfigurator ().apply (motionMagicConfiguration );
225241 }
242+
243+ /** Reset the relative encoder used for position calculations */
244+ public void resetEncoder () {
245+ kLeadMotor .setPosition (0.0 );
246+ }
226247}
0 commit comments