From ff806b7f252d23b38add70f3ae6a071b8b386b68 Mon Sep 17 00:00:00 2001 From: Benjamin Hall Date: Wed, 29 May 2024 14:02:23 -0400 Subject: [PATCH] Fix python tests --- cpp/BasicLatencyCompensation/src/main/cpp/Robot.cpp | 2 ++ java/CANcoder/src/main/java/frc/robot/Robot.java | 1 + .../CurrentLimits/src/test/java/CurrentLimitTests.java | 2 +- .../src/main/java/frc/robot/Mechanisms.java | 1 + java/Pigeon2/src/main/java/frc/robot/Robot.java | 1 + python/MotionMagic/tests/pyfrc_test.py | 6 +++--- python/PositionClosedLoop/tests/pyfrc_test.py | 8 ++++---- python/VelocityClosedLoop/tests/pyfrc_test.py | 10 +++++----- 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cpp/BasicLatencyCompensation/src/main/cpp/Robot.cpp b/cpp/BasicLatencyCompensation/src/main/cpp/Robot.cpp index 6aaef37c..66672005 100644 --- a/cpp/BasicLatencyCompensation/src/main/cpp/Robot.cpp +++ b/cpp/BasicLatencyCompensation/src/main/cpp/Robot.cpp @@ -4,6 +4,8 @@ #include "Robot.h" +using namespace ctre::phoenix6; + void Robot::RobotInit() {} void Robot::RobotPeriodic() { /* Perform basic latency compensation based on latency and current derivative */ diff --git a/java/CANcoder/src/main/java/frc/robot/Robot.java b/java/CANcoder/src/main/java/frc/robot/Robot.java index ee05e8bb..91b1345c 100644 --- a/java/CANcoder/src/main/java/frc/robot/Robot.java +++ b/java/CANcoder/src/main/java/frc/robot/Robot.java @@ -4,6 +4,7 @@ package frc.robot; +import com.ctre.phoenix6.BaseStatusSignal; import com.ctre.phoenix6.configs.CANcoderConfiguration; import com.ctre.phoenix6.controls.DutyCycleOut; import com.ctre.phoenix6.hardware.CANcoder; diff --git a/java/CurrentLimits/src/test/java/CurrentLimitTests.java b/java/CurrentLimits/src/test/java/CurrentLimitTests.java index bf4b1b9c..cee456b7 100644 --- a/java/CurrentLimits/src/test/java/CurrentLimitTests.java +++ b/java/CurrentLimits/src/test/java/CurrentLimitTests.java @@ -107,7 +107,7 @@ public void testSupplyLimit() { /* Put the talon in a stall, which should produce a lot of current */ talon.setControl(new DutyCycleOut(1)); /* wait for the control to apply */ - Timer.delay(0.050); + Timer.delay(0.100); /* Get the next update for supply current */ supplyCurrent.waitForUpdate(1); diff --git a/java/FusedCANcoder/src/main/java/frc/robot/Mechanisms.java b/java/FusedCANcoder/src/main/java/frc/robot/Mechanisms.java index 2cc28b7d..4426d5d1 100644 --- a/java/FusedCANcoder/src/main/java/frc/robot/Mechanisms.java +++ b/java/FusedCANcoder/src/main/java/frc/robot/Mechanisms.java @@ -1,5 +1,6 @@ package frc.robot; +import com.ctre.phoenix6.BaseStatusSignal; import com.ctre.phoenix6.StatusSignal; import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d; diff --git a/java/Pigeon2/src/main/java/frc/robot/Robot.java b/java/Pigeon2/src/main/java/frc/robot/Robot.java index dc81b1d7..25604f93 100644 --- a/java/Pigeon2/src/main/java/frc/robot/Robot.java +++ b/java/Pigeon2/src/main/java/frc/robot/Robot.java @@ -4,6 +4,7 @@ package frc.robot; +import com.ctre.phoenix6.BaseStatusSignal; import com.ctre.phoenix6.configs.Pigeon2Configuration; import com.ctre.phoenix6.controls.DutyCycleOut; import com.ctre.phoenix6.hardware.Pigeon2; diff --git a/python/MotionMagic/tests/pyfrc_test.py b/python/MotionMagic/tests/pyfrc_test.py index 9d1fb11d..1c813d28 100644 --- a/python/MotionMagic/tests/pyfrc_test.py +++ b/python/MotionMagic/tests/pyfrc_test.py @@ -25,7 +25,7 @@ def assert_almost_equal(a: float, b: float, range_val: float): def wait_with_sim(time: float, fx: hardware.TalonFX, dcmotorsim: DCMotorSim): start_time = 0 while start_time < time: - feed_enable(LOOP_PERIOD * 2) + feed_enable(0.1) start_time += LOOP_PERIOD dcmotorsim.setInputVoltage(fx.sim_state.motor_voltage) @@ -59,7 +59,7 @@ def test_position_closed_loop(): assert talonfx.set_position(FIRST_SET).is_ok() pos.wait_for_update(1) - assert_almost_equal(pos.value, 0, 0.01) + assert_almost_equal(pos.value, 0, 0.02) # Closed loop for 1 seconds to a target of 1 rotation, and verify we're close target_control = controls.MotionMagicVoltage(position=1.0) @@ -69,4 +69,4 @@ def test_position_closed_loop(): # Verify position is close to target pos.wait_for_update(1) - assert_almost_equal(pos.value, 1, 0.01) + assert_almost_equal(pos.value, 1, 0.02) diff --git a/python/PositionClosedLoop/tests/pyfrc_test.py b/python/PositionClosedLoop/tests/pyfrc_test.py index 4e998b3e..47256591 100644 --- a/python/PositionClosedLoop/tests/pyfrc_test.py +++ b/python/PositionClosedLoop/tests/pyfrc_test.py @@ -25,7 +25,7 @@ def assert_almost_equal(a: float, b: float, range_val: float): def wait_with_sim(time: float, fx: hardware.TalonFX, dcmotorsim: DCMotorSim): start_time = 0 while start_time < time: - feed_enable(LOOP_PERIOD * 2) + feed_enable(0.1) start_time += LOOP_PERIOD dcmotorsim.setInputVoltage(fx.sim_state.motor_voltage) @@ -37,7 +37,7 @@ def wait_with_sim(time: float, fx: hardware.TalonFX, dcmotorsim: DCMotorSim): def test_position_closed_loop(): talonfx = hardware.TalonFX(1, "sim") - motorsim = DCMotorSim(DCMotor.falcon500FOC(1), 1.0, 0.001) + motorsim = DCMotorSim(DCMotor.krakenX60FOC(1), 1.0, 0.001) pos = talonfx.get_position() talonfx.sim_state.set_raw_rotor_position(radiansToRotations(motorsim.getAngularPosition())) @@ -51,7 +51,7 @@ def test_position_closed_loop(): assert talonfx.set_position(FIRST_SET).is_ok() pos.wait_for_update(1) - assert_almost_equal(pos.value, 0, 0.01) + assert_almost_equal(pos.value, 0, 0.02) # Closed loop for 1 seconds to a target of 1 rotation, and verify we're close target_control = controls.PositionVoltage(position=1.0) @@ -61,4 +61,4 @@ def test_position_closed_loop(): # Verify position is close to target pos.wait_for_update(1) - assert_almost_equal(pos.value, 1, 0.01) + assert_almost_equal(pos.value, 1, 0.02) diff --git a/python/VelocityClosedLoop/tests/pyfrc_test.py b/python/VelocityClosedLoop/tests/pyfrc_test.py index 790cfa27..f64d00d4 100644 --- a/python/VelocityClosedLoop/tests/pyfrc_test.py +++ b/python/VelocityClosedLoop/tests/pyfrc_test.py @@ -22,7 +22,7 @@ def assert_almost_equal(a: float, b: float, range_val: float): def wait_with_sim(time: float, fx: hardware.TalonFX, dcmotorsim: DCMotorSim): start_time = 0 while start_time < time: - feed_enable(LOOP_PERIOD * 2) + feed_enable(0.1) start_time += LOOP_PERIOD dcmotorsim.setInputVoltage(fx.sim_state.motor_voltage) @@ -32,8 +32,8 @@ def wait_with_sim(time: float, fx: hardware.TalonFX, dcmotorsim: DCMotorSim): sleep(LOOP_PERIOD) -def test_position_closed_loop(): - talonfx = hardware.TalonFX(1, "sim") +def test_velocity_closed_loop(): + talonfx = hardware.TalonFX(0, "sim") motorsim = DCMotorSim(DCMotor.krakenX60FOC(1), 1.0, 0.001) vel = talonfx.get_velocity() @@ -49,7 +49,7 @@ def test_position_closed_loop(): assert talonfx.configurator.apply(cfg).is_ok() vel.wait_for_update(1) - assert_almost_equal(vel.value, 0, 0.1) + assert_almost_equal(vel.value, 0, 0.2) # Closed loop for 1 second to a target of 10 rps, and verify we're close target_control = controls.VelocityVoltage(velocity=10) @@ -59,4 +59,4 @@ def test_position_closed_loop(): # Verify velocity is close to target vel.wait_for_update(1) - assert_almost_equal(vel.value, 1, 0.1) + assert_almost_equal(vel.value, 10, 0.2)