Skip to content

Commit 22290c0

Browse files
committed
Climber Sim Code Done (and IO updated)
1 parent d03bd76 commit 22290c0

File tree

4 files changed

+72
-16
lines changed

4 files changed

+72
-16
lines changed

src/main/java/frc/robot/subsystems/climber/ClimberIO.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ public interface ClimberIO {
66
@AutoLog
77
class ClimberIOInputs {
88
public double hangAppliedVolts = 0.0;
9-
public double currentDrawLeft = 0.0;
10-
public double currentDrawRight = 0.0;
9+
public double leftCurrentAmps = 0.0;
10+
public double rightCurrentAmps = 0.0;
1111
public double encoderRight = 0.0;
1212
public double encoderLeft = 0.0;
13-
public double leftOutput;
14-
public double rightOutput;
13+
1514
}
1615

1716
default void updateInputs(ClimberIOInputs inputs) {}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package frc.robot.subsystems.climber;
2+
import edu.wpi.first.math.geometry.Rotation2d;
3+
import edu.wpi.first.math.system.plant.DCMotor;
4+
import edu.wpi.first.wpilibj.simulation.DCMotorSim;
5+
6+
public class ClimberIOSIM implements ClimberIO{
7+
private static final double LOOP_PERIOD_SECS = 0.02;
8+
9+
private static final DCMotor leftExtentionMotor = DCMotor.DCMotor.getVex775Pro(1);
10+
private static final DCMotor rightExtentionMotor = DCMotorgetNEO(1);
11+
12+
private DCMotorSim intakeSpinMotor =
13+
new DCMotorSim(
14+
LinearSystemId.createDCMotorSystem(leftExtentionMotor, 1.0, 1.0), leftExtentionMotor);
15+
16+
private DCMotorSim intakeRotateMotor =
17+
new DCMotorSim(
18+
LinearSystemId.createDCMotorSystem(leftExtentionMotor, 1.0, 1.0), leftExtentionMotor);
19+
20+
private double hangAppliedVolts = 0.0;
21+
private double leftCurrentAmps = 0.0;
22+
private double rightCurrentAmps = 0.0;
23+
24+
@Override
25+
public void updateInputs(EndEffectorIOInputs inputs) {
26+
leftHangMotor.update(LOOP_PERIOD_SECS);
27+
rightHangMotor.update(LOOP_PERIOD_SECS);
28+
29+
inputs.hangAppliedVolts = hangAppliedVolts;
30+
inputs.leftCurrentAmps = leftCurrentAmps;
31+
inputs.rightCurrentAmps = rightCurrentAmps;
32+
33+
inputs.spinAppliedVolts = intakeSpinMotor.getInputVoltage();
34+
inputs.rightCurrentAmps = intakeSpinMotor.getCurrentDrawAmps();
35+
36+
inputs.spinPositionRad = intakeSpinMotor.getAngularPositionRad();
37+
inputs.spinAngularVelocity = intakeSpinMotor.getAngularVelocity();
38+
39+
inputs.articulationPositionRad = intakeRotateMotor.getAngularPositionRad();
40+
inputs.articulationAngularVelocity = intakeSpinMotor.getAngularVelocity();
41+
}
42+
43+
@Override
44+
public void articulationRunVoltage(double voltage) {
45+
articulationAppliedVolts = voltage;
46+
intakeRotateMotor.setInputVoltage(voltage); //why setINPUTVoltage?
47+
}
48+
49+
@Override
50+
public void spinRunVoltage(double voltage) {
51+
spinAppliedVolts = voltage;
52+
intakeSpinMotor.setInputVoltage(voltage); //why setINPUTVoltage?
53+
54+
}
55+
56+
}
57+
58+
59+
inputs.articulationAppliedVolts = intakeRotateMotor.getAppliedOutput();
60+
inputs.articulationCurrentAmps = intakeRotateMotor.getOutputCurrent();

src/main/java/frc/robot/subsystems/endEffector/EndEffectorIO.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package frc.robot.subsystems.endEffector;
22

33
import edu.wpi.first.math.geometry.Rotation2d;
4+
import edu.wpi.first.units.measure.AngularVelocity;
5+
46
import org.littletonrobotics.junction.AutoLog;
57

68
public interface EndEffectorIO {
@@ -16,8 +18,10 @@ class EndEffectorIOInputs {
1618
public boolean limitSwitchPressed = false;
1719

1820
public double spinPositionRad = 0.0;
21+
public AngularVelocity spinAngularVelocity;
1922

20-
public double articulationAngularVelocity = 0.0;
23+
public double articulationPositionRad = 0.0;
24+
public AngularVelocity articulationAngularVelocity;
2125
}
2226

2327
default void updateInputs(EndEffectorIOInputs inputs) {}

src/main/java/frc/robot/subsystems/endEffector/EndEffectorIOSim.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ public class EndEffectorIOSim implements EndEffectorIO {
99
private static final DCMotor leftExtentionMotor = DCMotor.DCMotor.getVex775Pro(1);
1010
private static final DCMotor rightExtentionMotor = DCMotorgetNEO(1);
1111

12-
private DCMotorSim intakeSpinMotor =
13-
new DCMotorSim(
12+
private DCMotorSim intakeSpinMotor =
13+
new DCMotorSim(
1414
LinearSystemId.createDCMotorSystem(leftExtentionMotor, 1.0, 1.0), leftExtentionMotor);
1515

16-
private DCMotorSim intakeRotateMotor =
17-
new DCMotorSim(
16+
private DCMotorSim intakeRotateMotor =
17+
new DCMotorSim(
1818
LinearSystemId.createDCMotorSystem(leftExtentionMotor, 1.0, 1.0), leftExtentionMotor);
1919

2020

@@ -29,12 +29,6 @@ public void updateInputs(EndEffectorIOInputs inputs) {
2929
intakeSpinMotor.update(LOOP_PERIOD_SECS);
3030
intakeRotateMotor.update(LOOP_PERIOD_SECS);
3131

32-
//inputs.articulationPosition = intakeSpinMotor.();
33-
/*
34-
private double intakeSpinMotorVelocityRadPerSec = intakeSpinMotor.getAngularVelocityRadPerSec();
35-
private double intakeRotateMotorPositionRad = intakeRotateMotor.getAngularPositionRad();
36-
private double intakeRotateMotorVelocityRadPerSec = intakeRotateMotor.getAngularVelocityRadPerSec();
37-
*/
3832
inputs.spinAppliedVolts = spinAppliedVolts;
3933
inputs.spinCurrentAmps = spinCurrentAmps;
4034

@@ -46,7 +40,6 @@ public void updateInputs(EndEffectorIOInputs inputs) {
4640

4741
inputs.articulationPositionRad = intakeRotateMotor.getAngularPositionRad();
4842
inputs.articulationAngularVelocity = intakeSpinMotor.getAngularVelocity();
49-
5043
}
5144

5245
@Override

0 commit comments

Comments
 (0)