From 8981527cecd5561b0f4a62733c407569a2f8f720 Mon Sep 17 00:00:00 2001 From: Mike Silva Date: Sun, 25 Jan 2026 09:10:19 -0500 Subject: [PATCH] More tinkering --- components/__init__.py | 6 +++- components/agitator.py | 24 ++++++++++++++ components/gyro.py | 74 ++++++++++++++++++++++++++++++++++++++++++ components/intake.py | 11 +++++-- components/pigeon.py | 33 ------------------- 5 files changed, 111 insertions(+), 37 deletions(-) create mode 100644 components/agitator.py create mode 100644 components/gyro.py delete mode 100644 components/pigeon.py diff --git a/components/__init__.py b/components/__init__.py index 24334a6..f13fb8e 100644 --- a/components/__init__.py +++ b/components/__init__.py @@ -1,8 +1,12 @@ # from .drivetrain import DriveTrain +from .agitator import Agitator from .controller import XboxController -from .pigeon import Pigeon +from .gyro import Pigeon +from .intake import Intake __all__ = [ + "Agitator", + "Intake", "Pigeon", "XboxController", ] diff --git a/components/agitator.py b/components/agitator.py new file mode 100644 index 0000000..4580956 --- /dev/null +++ b/components/agitator.py @@ -0,0 +1,24 @@ +import magicbot +from phoenix6.hardware import TalonFX +from phoenix6.configs.talon_fx_configs import TalonFXConfiguration +from phoenix6.signals import NeutralModeValue +from phoenix6.controls import VoltageOut + + +class Agitator: + motor: TalonFX + voltage = magicbot.will_reset_to(0.0) + + def execute(self): + self.motor.set_control(VoltageOut(self.voltage)) + + def setup(self): + config = TalonFXConfiguration() + config.motor_output.neutral_mode = NeutralModeValue.BRAKE + self.motor.configurator.apply(config) + + def spin(self): + self.voltage = 1.0 + + def stop(self): + self.voltage = 0.0 diff --git a/components/gyro.py b/components/gyro.py new file mode 100644 index 0000000..ebc66ba --- /dev/null +++ b/components/gyro.py @@ -0,0 +1,74 @@ +import math +from phoenix6.hardware.pigeon2 import Pigeon2 +import navx + + +class Pigeon: + gyro: Pigeon2 + + def setup(self): + self.gyro.reset() + + def execute(self): + pass + + def yaw(self) -> float: + return self.gyro.get_yaw().value + + def roll(self) -> float: + return self.gyro.get_roll().value + + def pitch(self) -> float: + return self.gyro.get_pitch().value + + def rotation2d(self): + return self.gyro.getRotation2d() + + def degrees_per_second_ccw(self) -> float: + return self.gyro.get_angular_velocity_z_world().value + + def radians_per_second_ccw(self) -> float: + return math.radians(self.degrees_per_second_ccw()) + + def set_yaw(self, angle): + self.gyro.set_yaw(angle) + + +class NavX: + gyro: navx.AHRS # Either navx.AHRS.create_spi() or navx.AHRS.create_i2c() + + def setup(self): + self.gyro.reset() + + def execute(self): + pass + + def yaw(self) -> float: + return self.gyro.getYaw() + + def roll(self) -> float: + return self.gyro.getRoll() + + def pitch(self) -> float: + return self.gyro.getPitch() + + def is_calibrating(self) -> bool: + return self.gyro.isCalibrating() + + def is_connected(self) -> bool: + return self.gyro.isConnected() + + def rotation2d(self): + return self.gyro.getRotation2d() + + def rotation3d(self): + return self.gyro.getRotation3d() + + def reset(self) -> None: + self.gyro.reset() + + def fused_heading(self) -> float: + return self.gyro.getFusedHeading() + + def zero_yaw(self) -> None: + self.gyro.zeroYaw() diff --git a/components/intake.py b/components/intake.py index fffa48c..b7c82a2 100644 --- a/components/intake.py +++ b/components/intake.py @@ -11,13 +11,18 @@ class Intake: voltage = magicbot.will_reset_to(0.0) def execute(self): - motor_control = VoltageOut(self.voltage) - self.motor.set_control(motor_control)S + self.motor.set_control(VoltageOut(self.voltage)) def setup(self): config = TalonFXConfiguration() config.motor_output.neutral_mode = NeutralModeValue.BRAKE self.motor.configurator.apply(config) + def extend(self): + pass # Implement extension logic here + + def retract(self): + pass # Implement retraction logic here + def set_voltage(self, voltage: units.volts): - self.voltage = voltage \ No newline at end of file + self.voltage = voltage diff --git a/components/pigeon.py b/components/pigeon.py deleted file mode 100644 index 1a5ee56..0000000 --- a/components/pigeon.py +++ /dev/null @@ -1,33 +0,0 @@ -import math -from phoenix6.hardware.pigeon2 import Pigeon2 - -class Pigeon: - - gyro: Pigeon2 - - def setup(self): - self.gyro.reset() - - def execute(self): - pass - - def yaw(self) -> float: - return self.gyro.get_yaw().value - - def roll(self) -> float: - return self.gyro.get_roll().value - - def pitch(self) -> float: - return self.gyro.get_pitch().value - - def rotation2d(self): - return self.gyro.getRotation2d() - - def degrees_per_second_ccw(self) -> float: - return self.gyro.get_angular_velocity_z_world().value - - def getRadiansPerSecCCW(self) -> float: - return math.radians(self.degrees_per_second_ccw()) - - def set_yaw(self, angle): - self.gyro.set_yaw(angle) \ No newline at end of file