Skip to content

Commit

Permalink
Fix python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bhall-ctre committed May 29, 2024
1 parent 18d8095 commit ff806b7
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
2 changes: 2 additions & 0 deletions cpp/BasicLatencyCompensation/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions java/CANcoder/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion java/CurrentLimits/src/test/java/CurrentLimitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions java/FusedCANcoder/src/main/java/frc/robot/Mechanisms.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package frc.robot;

import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.StatusSignal;

import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d;
Expand Down
1 change: 1 addition & 0 deletions java/Pigeon2/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions python/MotionMagic/tests/pyfrc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
8 changes: 4 additions & 4 deletions python/PositionClosedLoop/tests/pyfrc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()))
Expand All @@ -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)
Expand All @@ -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)
10 changes: 5 additions & 5 deletions python/VelocityClosedLoop/tests/pyfrc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand All @@ -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)
Expand All @@ -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)

0 comments on commit ff806b7

Please sign in to comment.