diff --git a/python/PhoenixSysId/robot.py b/python/PhoenixSysId/robot.py index 246ba5d4..f77b8c13 100644 --- a/python/PhoenixSysId/robot.py +++ b/python/PhoenixSysId/robot.py @@ -23,6 +23,8 @@ def robotInit(self) -> None: """ self.container = RobotContainer() + self.autonomousCommand = None + def disabledInit(self) -> None: """This function is called once each time the robot enters Disabled mode.""" pass diff --git a/python/PhoenixSysId/robotcontainer.py b/python/PhoenixSysId/robotcontainer.py index a5fe5b79..e25844fd 100644 --- a/python/PhoenixSysId/robotcontainer.py +++ b/python/PhoenixSysId/robotcontainer.py @@ -6,7 +6,7 @@ from subsystems.flywheel import FlywheelMechanism -class SysIdRoutineBot: +class RobotContainer: def __init__(self) -> None: self.joystick = CommandXboxController(0) self.mechanism = FlywheelMechanism() @@ -46,4 +46,4 @@ def getAutonomousCommand(self) -> Command: Scheduled during :meth:`.Robot.autonomousInit`. """ - return cmd.print("No autonomous command configured") + return cmd.print_("No autonomous command configured") diff --git a/python/PhoenixSysId/subsystems/flywheel.py b/python/PhoenixSysId/subsystems/flywheel.py index ef633c7c..84d038bd 100644 --- a/python/PhoenixSysId/subsystems/flywheel.py +++ b/python/PhoenixSysId/subsystems/flywheel.py @@ -1,7 +1,6 @@ from commands2 import Command, Subsystem from commands2.sysid import SysIdRoutine from wpilib.sysid import SysIdRoutineLog -from wpimath.units import volts from phoenix6 import configs, controls, hardware, BaseStatusSignal, SignalLogger @@ -9,7 +8,7 @@ from typing import Callable -class FlywheelMechanism: +class FlywheelMechanism(Subsystem): def __init__(self) -> None: self.motor_to_test = hardware.TalonFX(Constants.kTalonFxId, Constants.kCANbus) self.joystick_control = controls.DutyCycleOut(0) @@ -24,7 +23,7 @@ def __init__(self) -> None: recordState = lambda state: SignalLogger.write_string("state", SysIdRoutineLog.stateEnumToString(state)) ), SysIdRoutine.Mechanism( - lambda volts: self.motor.set_control(self.voltage_req.with_output(volts)), + lambda volts: self.motor_to_test.set_control(self.sys_id_control.with_output(volts)), lambda log: None, self ) diff --git a/python/PhoenixSysId/tests/pyfrc_test.py b/python/PhoenixSysId/tests/pyfrc_test.py index bc5b4f42..4c03f00b 100644 --- a/python/PhoenixSysId/tests/pyfrc_test.py +++ b/python/PhoenixSysId/tests/pyfrc_test.py @@ -5,11 +5,6 @@ from pyfrc.tests import * from wpilib.simulation import XboxControllerSim -import time -from subsystems.flywheel import FlywheelMechanism - -FIRST_SET = 0 -SECOND_SET = 4.8 def assert_almost_equal(a: float, b: float, range_val: float): """ @@ -18,21 +13,23 @@ def assert_almost_equal(a: float, b: float, range_val: float): assert a >= (b - range_val) and a <= (b + range_val) def test_sysid_quasistatic(control, robot): - joysim = XboxControllerSim(robot.container.joystick.getHID()) + with control.run_robot(): + joysim = XboxControllerSim(robot.container.joystick.getHID()) - joysim.setYButton(True) - control.step_timing(seconds=0.1, autonomous=False, enabled=True) + joysim.setYButton(True) + control.step_timing(seconds=0.1, autonomous=False, enabled=True) - assert robot.container.mechanism.sys_id_control.output > 0.1 + assert_almost_equal(robot.container.mechanism.sys_id_control.output, 0.16, 0.01) - joysim.setYButton(False) + joysim.setYButton(False) def test_sysid_dynamic(control, robot): - joysim = XboxControllerSim(robot.container.joystick.getHID()) + with control.run_robot(): + joysim = XboxControllerSim(robot.container.joystick.getHID()) - joysim.setXButton(True) - control.step_timing(seconds=0.1, autonomous=False, enabled=True) + joysim.setBButton(True) + control.step_timing(seconds=0.1, autonomous=False, enabled=True) - assert robot.container.mechanism.sys_id_control.output > 0.1 - - joysim.setXButton(False) + assert_almost_equal(robot.container.mechanism.sys_id_control.output, 4.0, 0.01) + + joysim.setBButton(False)