Skip to content

Commit c42d2ca

Browse files
committed
Update Intake to take in Motor
1 parent af6d9c2 commit c42d2ca

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/main/java/com/team2813/subsystems/Intake.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.ctre.phoenix6.configs.TalonFXConfigurator;
77
import com.ctre.phoenix6.configs.VoltageConfigs;
88
import com.team2813.lib2813.control.InvertType;
9-
import com.team2813.lib2813.control.PIDMotor;
9+
import com.team2813.lib2813.control.Motor;
1010
import com.team2813.lib2813.control.motors.TalonFXWrapper;
1111
import com.team2813.lib2813.subsystems.ParameterizedIntakeSubsystem;
1212
import com.team2813.lib2813.util.ConfigUtils;
@@ -31,7 +31,7 @@ public Intake(NetworkTableInstance networkTableInstance) {
3131
networkTableInstance);
3232
}
3333

34-
Intake(PIDMotor motor, DigitalInput beamBreak, NetworkTableInstance networkTableInstance) {
34+
Intake(Motor motor, DigitalInput beamBreak, NetworkTableInstance networkTableInstance) {
3535
super(motor, PARAMS);
3636
this.beamBreak = beamBreak;
3737
if (motor instanceof TalonFXWrapper wrapper) {

src/test/java/com/team2813/subsystems/IntakeTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,49 @@
33
import static com.google.common.truth.Truth.assertThat;
44
import static com.team2813.subsystems.Intake.BUMP_VOLTAGE;
55
import static org.mockito.Mockito.mock;
6-
import static org.mockito.Mockito.verifyNoInteractions;
76
import static org.mockito.Mockito.when;
87

98
import com.team2813.IsolatedNetworkTablesExtension;
10-
import com.team2813.lib2813.testing.FakePIDMotor;
9+
import com.team2813.lib2813.testing.FakeMotor;
1110
import com.team2813.lib2813.testing.junit.jupiter.CommandTester;
1211
import com.team2813.lib2813.testing.junit.jupiter.WPILibExtension;
1312
import edu.wpi.first.networktables.NetworkTableInstance;
13+
import edu.wpi.first.units.Units;
1414
import edu.wpi.first.wpilibj.DigitalInput;
1515
import edu.wpi.first.wpilibj2.command.Command;
1616
import org.junit.jupiter.api.Test;
1717
import org.junit.jupiter.api.extension.ExtendWith;
18-
import org.mockito.Answers;
1918

2019
@ExtendWith({IsolatedNetworkTablesExtension.class, WPILibExtension.class})
2120
public final class IntakeTest {
22-
final FakePIDMotor fakeMotor = mock(FakePIDMotor.class, Answers.CALLS_REAL_METHODS);
21+
final FakeMotor fakeMotor = new FakeMotor();
2322
final DigitalInput mockBeamBreak = mock(DigitalInput.class);
2423

2524
@Test
2625
public void constructRealInstance(NetworkTableInstance ntInstance) {
2726
try (Intake ignored = new Intake(ntInstance)) {
28-
assertThat(fakeMotor.demand).isWithin(0.01).of(0.0);
27+
assertThat(fakeMotor.getDemand()).isWithin(0.01).of(0.0);
2928
}
3029
}
3130

3231
@Test
3332
public void initialState(NetworkTableInstance ntInstance) {
3433
try (Intake ignored = new Intake(fakeMotor, mockBeamBreak, ntInstance)) {
35-
assertThat(fakeMotor.demand).isWithin(0.01).of(0.0);
36-
verifyNoInteractions(fakeMotor);
34+
assertThat(fakeMotor.getDemand()).isWithin(0.01).of(0.0);
3735
}
3836
}
3937

4038
@Test
4139
public void intakeCoral(NetworkTableInstance ntInstance, CommandTester commandTester) {
4240
try (Intake intake = new Intake(fakeMotor, mockBeamBreak, ntInstance)) {
4341
Command command = intake.intakeItemCommand();
44-
assertThat(fakeMotor.demand).isWithin(0.01).of(0.0);
42+
assertThat(fakeMotor.getDemand()).isWithin(0.01).of(0.0);
4543

4644
commandTester.runUntilComplete(command);
4745

48-
assertThat(fakeMotor.getVoltage()).isWithin(0.01).of(Intake.PARAMS.intakeDemand());
46+
assertThat(fakeMotor.getMotorVoltage().in(Units.Volts))
47+
.isWithin(0.01)
48+
.of(Intake.PARAMS.intakeDemand());
4949
}
5050
}
5151

@@ -78,7 +78,9 @@ public void outtakeCoral(NetworkTableInstance ntInstance, CommandTester commandT
7878

7979
commandTester.runUntilComplete(command);
8080
assertMotorIsRunning();
81-
assertThat(fakeMotor.getVoltage()).isWithin(0.01).of(Intake.PARAMS.outtakeDemand());
81+
assertThat(fakeMotor.getMotorVoltage().in(Units.Volts))
82+
.isWithin(0.01)
83+
.of(Intake.PARAMS.outtakeDemand());
8284
}
8385
}
8486

@@ -114,7 +116,7 @@ public void bumpAlgae(NetworkTableInstance ntInstance, CommandTester commandTest
114116

115117
commandTester.runUntilComplete(command);
116118

117-
assertThat(fakeMotor.getVoltage()).isWithin(0.01).of(BUMP_VOLTAGE);
119+
assertThat(fakeMotor.getMotorVoltage().in(Units.Volts)).isWithin(0.01).of(BUMP_VOLTAGE);
118120
}
119121
}
120122

@@ -149,10 +151,10 @@ public void hasCoral_withoutCoral(NetworkTableInstance ntInstance) {
149151
}
150152

151153
private void assertMotorIsStopped() {
152-
assertThat(fakeMotor.demand).isWithin(0.01).of(0.0);
154+
assertThat(fakeMotor.getDemand()).isWithin(0.01).of(0.0);
153155
}
154156

155157
private void assertMotorIsRunning() {
156-
assertThat(fakeMotor.demand).isNotWithin(0.01).of(0.0);
158+
assertThat(fakeMotor.getDemand()).isNotWithin(0.01).of(0.0);
157159
}
158160
}

0 commit comments

Comments
 (0)