mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpimath] Replace Speeds with Velocities (#8479)
I left "free speed" alone since that's the technical term for it. In general, velocity is a vector quantity, and speed is a magnitude (i.e., a strictly positive value). This PR also replaces the speed verbiage in MotorController with duty cycle. Fixes #8423.
This commit is contained in:
@@ -38,7 +38,7 @@ class DCMotorSimTest {
|
||||
// ------ SimulationPeriodic() happens after user code -------
|
||||
RoboRioSim.setVInVoltage(
|
||||
BatterySim.calculateDefaultBatteryLoadedVoltage(sim.getCurrentDraw()));
|
||||
sim.setInputVoltage(motor.get() * RobotController.getBatteryVoltage());
|
||||
sim.setInputVoltage(motor.getDutyCycle() * RobotController.getBatteryVoltage());
|
||||
sim.update(0.020);
|
||||
encoderSim.setRate(sim.getAngularVelocity());
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class DCMotorSimTest {
|
||||
// ------ SimulationPeriodic() happens after user code -------
|
||||
RoboRioSim.setVInVoltage(
|
||||
BatterySim.calculateDefaultBatteryLoadedVoltage(sim.getCurrentDraw()));
|
||||
sim.setInputVoltage(motor.get() * RobotController.getBatteryVoltage());
|
||||
sim.setInputVoltage(motor.getDutyCycle() * RobotController.getBatteryVoltage());
|
||||
sim.update(0.020);
|
||||
encoderSim.setRate(sim.getAngularVelocity());
|
||||
}
|
||||
@@ -76,12 +76,12 @@ class DCMotorSimTest {
|
||||
encoderSim.resetData();
|
||||
|
||||
for (int i = 0; i < 140; i++) {
|
||||
motor.set(controller.calculate(encoder.getDistance(), 750));
|
||||
motor.setDutyCycle(controller.calculate(encoder.getDistance(), 750));
|
||||
|
||||
// ------ SimulationPeriodic() happens after user code -------
|
||||
RoboRioSim.setVInVoltage(
|
||||
BatterySim.calculateDefaultBatteryLoadedVoltage(sim.getCurrentDraw()));
|
||||
sim.setInputVoltage(motor.get() * RobotController.getBatteryVoltage());
|
||||
sim.setInputVoltage(motor.getDutyCycle() * RobotController.getBatteryVoltage());
|
||||
sim.update(0.020);
|
||||
encoderSim.setDistance(sim.getAngularPosition());
|
||||
encoderSim.setRate(sim.getAngularVelocity());
|
||||
|
||||
@@ -65,9 +65,10 @@ class DifferentialDrivetrainSimTest {
|
||||
var state = traj.sample(t);
|
||||
var feedbackOut = feedback.calculate(sim.getPose(), state);
|
||||
|
||||
var wheelSpeeds = kinematics.toWheelSpeeds(feedbackOut);
|
||||
var wheelVelocities = kinematics.toWheelVelocities(feedbackOut);
|
||||
|
||||
var voltages = feedforward.calculate(VecBuilder.fill(wheelSpeeds.left, wheelSpeeds.right));
|
||||
var voltages =
|
||||
feedforward.calculate(VecBuilder.fill(wheelVelocities.left, wheelVelocities.right));
|
||||
|
||||
// Sim periodic code
|
||||
sim.setInputs(voltages.get(0, 0), voltages.get(1, 0));
|
||||
|
||||
@@ -48,11 +48,11 @@ class ElevatorSimTest {
|
||||
double nextVoltage = controller.calculate(encoderSim.getDistance());
|
||||
|
||||
double currentBatteryVoltage = RobotController.getBatteryVoltage();
|
||||
motor.set(nextVoltage / currentBatteryVoltage);
|
||||
motor.setDutyCycle(nextVoltage / currentBatteryVoltage);
|
||||
|
||||
// ------ SimulationPeriodic() happens after user code -------
|
||||
|
||||
var u = VecBuilder.fill(motor.get() * currentBatteryVoltage);
|
||||
var u = VecBuilder.fill(motor.getDutyCycle() * currentBatteryVoltage);
|
||||
sim.setInput(u);
|
||||
sim.update(0.020);
|
||||
var y = sim.getOutput();
|
||||
|
||||
@@ -18,14 +18,14 @@ class PWMMotorControllerSimTest {
|
||||
try (Spark spark = new Spark(0)) {
|
||||
PWMMotorControllerSim sim = new PWMMotorControllerSim(spark);
|
||||
|
||||
spark.set(0);
|
||||
assertEquals(0, sim.getSpeed());
|
||||
spark.setDutyCycle(0);
|
||||
assertEquals(0, sim.getDutyCycle());
|
||||
|
||||
spark.set(0.354);
|
||||
assertEquals(0.354, sim.getSpeed());
|
||||
spark.setDutyCycle(0.354);
|
||||
assertEquals(0.354, sim.getDutyCycle());
|
||||
|
||||
spark.set(-0.785);
|
||||
assertEquals(-0.785, sim.getSpeed());
|
||||
spark.setDutyCycle(-0.785);
|
||||
assertEquals(-0.785, sim.getDutyCycle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user