Skip to content

Commit

Permalink
simple motor test
Browse files Browse the repository at this point in the history
  • Loading branch information
sigalrmp committed Jan 15, 2025
1 parent b98e165 commit 421fa6b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/org/sciborgs1155/lib/SimpleMotorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.sciborgs1155.lib;

import static edu.wpi.first.units.Units.RadiansPerSecondPerSecond;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.sciborgs1155.lib.UnitTestingUtil.*;

import edu.wpi.first.math.system.plant.DCMotor;
import edu.wpi.first.math.system.plant.LinearSystemId;
import edu.wpi.first.wpilibj.simulation.DCMotorSim;
import edu.wpi.first.wpilibj2.command.Commands;
import org.junit.jupiter.api.Test;

public class SimpleMotorTest {
@Test
public void test() throws Exception {
setupTests();
DCMotorSim motor =
new DCMotorSim(LinearSystemId.createDCMotorSystem(1, 0.3), DCMotor.getKrakenX60(1));

assert motor.getAngularAcceleration().in(RadiansPerSecondPerSecond) == 0;

SimpleMotor sm = new SimpleMotor(motor::setInput, () -> {});
run(Commands.run(() -> motor.update(0.02)));

sm.set(0.5);
assertEquals(motor.getInput().get(0, 0), 0.5);

fastForward();
assertEquals(motor.getAngularVelocityRadPerSec(), 0.5, 2e-3);

sm.set(-0.5);

fastForward();
assertEquals(motor.getAngularVelocityRadPerSec(), -0.5, 2e-3);

reset();
}
}

0 comments on commit 421fa6b

Please sign in to comment.