From b7f444a83afda033c471451eb6e337300c9ded81 Mon Sep 17 00:00:00 2001 From: theA-Train <146664346+theA-Train@users.noreply.github.com> Date: Thu, 12 Feb 2026 09:44:22 -0500 Subject: [PATCH 1/9] deployintake now wraps setpivot and also voltage sets pivot motor in --- subsystems/intake/command.py | 53 ++++++++++++++++++++++++---------- subsystems/intake/subsystem.py | 4 +-- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/subsystems/intake/command.py b/subsystems/intake/command.py index 401b5d0..814b4a2 100644 --- a/subsystems/intake/command.py +++ b/subsystems/intake/command.py @@ -71,18 +71,17 @@ def isFinished(self) -> bool: def end(self, interrupted: bool): self.subsystem.stop_intake() -class SetPivotOut(commands2.Command): +class SetPivotIn(commands2.Command): """ - Set pivot motor to specified angle with voltage out + Set pivot motor to specified angle with voltage in """ - def __init__(self, subsystem: Intake, voltage:float, angle: float): + def __init__(self, subsystem: Intake, angle: float): super().__init__() self.subsystem = subsystem - self.voltage = voltage self.angle = angle def initialize(self): - self.subsystem.set_pivot_out(self.voltage) + self.subsystem.set_pivot_motor_in(voltage_out) self.subsystem.pivot_running = True def execute(self): @@ -98,22 +97,44 @@ def end(self, interrupted: bool): else: log.message("intake pivot interrupted") -class DeployIntake(commands2.SequentialCommandGroup): + +class DeployIntake(commands2.Command): """ Deploy intake by setting pivot to specificed angle and running intake """ - def __init__(self, subsystem: Intake): - super().__init__( - SetPivot(subsystem, intake_deploy_angle), - RunIntake(subsystem) - ) + def __init__(self, subsystem: Intake, angle: float): + super().__init__() + self.command = SetPivot(subsystem, intake_deploy_angle) + + def initialize(self): + self.command.initialize() + + def execute(self): + pass + + def isFinished(self) -> bool: + return self.command.isFinished() + + def end(self, interrupted: bool): + self.command.end(interrupted) + class DeployIntakeOut(commands2.SequentialCommandGroup): """ Deploy intake by setting pivot to specified angle with voltageout """ - def __init__(self, subsystem: Intake): - super().__init__( - SetPivotOut(subsystem, voltage_out, intake_deploy_angle), - RunIntake(subsystem) - ) \ No newline at end of file + def __init__(self, subsystem: Intake, angle: float): + super().__init__() + self.command = SetPivotIn(subsystem, intake_deploy_angle) + + def initialize(self): + self.command.initialize() + + def execute(self): + pass + + def isFinished(self) -> bool: + return self.command.isFinished() + + def end(self, interrupted: bool): + self.command.end(interrupted) \ No newline at end of file diff --git a/subsystems/intake/subsystem.py b/subsystems/intake/subsystem.py index ac72b32..30ef71d 100644 --- a/subsystems/intake/subsystem.py +++ b/subsystems/intake/subsystem.py @@ -85,12 +85,12 @@ def stop_pivot(self): self.pivot_request = controls.MotionMagicDutyCycle(0.0) self.pivot_motor.set_control(self.pivot_request) - def set_pivot_out(self, output:float): + def set_pivot_motor_in(self, output:float): """ set pivot motor voltage """ self.output = output - self.pivot_request = controls.VoltageOut(self.output) + self.pivot_request = controls.VoltageOut(-(self.output)) self.pivot_motor.set_control(self.pivot_request) def is_at_angle(self, angle: float): From c6b2831a3e7d2e4e61ba80e3b6fca71293a39a47 Mon Sep 17 00:00:00 2001 From: e-bauman Date: Fri, 13 Feb 2026 16:30:31 -0500 Subject: [PATCH 2/9] update deploy intake command --- subsystems/intake/command.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/subsystems/intake/command.py b/subsystems/intake/command.py index 814b4a2..0ee8f3e 100644 --- a/subsystems/intake/command.py +++ b/subsystems/intake/command.py @@ -97,26 +97,12 @@ def end(self, interrupted: bool): else: log.message("intake pivot interrupted") - -class DeployIntake(commands2.Command): +class DeployIntake(SetPivot): """ - Deploy intake by setting pivot to specificed angle and running intake + Deploy the intake """ - def __init__(self, subsystem: Intake, angle: float): - super().__init__() - self.command = SetPivot(subsystem, intake_deploy_angle) - - def initialize(self): - self.command.initialize() - - def execute(self): - pass - - def isFinished(self) -> bool: - return self.command.isFinished() - - def end(self, interrupted: bool): - self.command.end(interrupted) + def __init__(self, subsystem: Intake): + super().__init__(subsystem, intake_deploy_angle) class DeployIntakeOut(commands2.SequentialCommandGroup): From 03e16054ebdf6093e9609fe69e383f0ffebed696 Mon Sep 17 00:00:00 2001 From: e-bauman Date: Fri, 13 Feb 2026 16:51:17 -0500 Subject: [PATCH 3/9] cleanup some commands --- robotcontainer.py | 9 ++++++--- subsystems/climber/__init__.py | 2 +- subsystems/climber/command.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/robotcontainer.py b/robotcontainer.py index 5550b59..fed6058 100644 --- a/robotcontainer.py +++ b/robotcontainer.py @@ -3,7 +3,7 @@ # Open Source Software; you can modify and/or share it under the terms of # the WPILib BSD license file in the root directory of this project. # -from commands2 import ParallelCommandGroup +from commands2 import ParallelCommandGroup, SequentialCommandGroup from commands2.button import CommandXboxController, Trigger from commands2.sysid import SysIdRoutine @@ -119,7 +119,10 @@ def configureButtonBindings(self) -> None: # deploy and run intake self.operator_controller.rightTrigger().whileTrue( - DeployIntake(self.intake) + SequentialCommandGroup( + DeployIntake(self.intake), + RunIntake(self.intake) + ) ) # run intake in reverse @@ -139,7 +142,7 @@ def configureButtonBindings(self) -> None: # climb self.operator_controller.back().whileTrue( - Retract(self.climber) + RetractClimb(self.climber) ) # Run SysId routines when holding back/start and X/Y. diff --git a/subsystems/climber/__init__.py b/subsystems/climber/__init__.py index a54f7cd..083eb64 100644 --- a/subsystems/climber/__init__.py +++ b/subsystems/climber/__init__.py @@ -1,2 +1,2 @@ from .subsystem import Climber -from .command import DeployClimbL1, Retract \ No newline at end of file +from .command import DeployClimbL1, RetractClimb \ No newline at end of file diff --git a/subsystems/climber/command.py b/subsystems/climber/command.py index 5065de8..e1fe73b 100644 --- a/subsystems/climber/command.py +++ b/subsystems/climber/command.py @@ -30,7 +30,7 @@ def end(self, interrupted: bool): self.subsystem.moving = False -class Retract(commands2.Command): +class RetractClimb(commands2.Command): """ lower climber to climb robot. uses set_voltage method from Climber subsystem. From b32bfae0f23928136302744440ac8609a3bbc65b Mon Sep 17 00:00:00 2001 From: theA-Train <146664346+theA-Train@users.noreply.github.com> Date: Wed, 18 Feb 2026 14:24:47 -0500 Subject: [PATCH 4/9] gear mechanism ratios + index command --- subsystems/Intake/constants.py | 3 +-- subsystems/intake/command.py | 22 ++++------------------ subsystems/superstructure.py | 13 +++++++++++++ 3 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 subsystems/superstructure.py diff --git a/subsystems/Intake/constants.py b/subsystems/Intake/constants.py index fe7cf28..e848187 100644 --- a/subsystems/Intake/constants.py +++ b/subsystems/Intake/constants.py @@ -19,7 +19,6 @@ configs.MotorOutputConfigs() .with_inverted(signals.InvertedValue.CLOCKWISE_POSITIVE) .with_neutral_mode(signals.NeutralModeValue.BRAKE) - ) ) @@ -33,7 +32,7 @@ configs.FeedbackConfigs() .with_feedback_remote_sensor_id(pivot_motor_id) .with_feedback_sensor_source(signals.FeedbackSensorSourceValue.FUSED_CANCODER) - .with_sensor_to_mechanism_ratio(5) # placeholder + .with_sensor_to_mechanism_ratio(45) ).with_motion_magic( configs.MotionMagicConfigs() # .with_motion_magic_cruise_velocity(0) placeholder diff --git a/subsystems/intake/command.py b/subsystems/intake/command.py index 0ee8f3e..fdd75ba 100644 --- a/subsystems/intake/command.py +++ b/subsystems/intake/command.py @@ -96,7 +96,6 @@ def end(self, interrupted: bool): self.subsystem.pivot_running = False else: log.message("intake pivot interrupted") - class DeployIntake(SetPivot): """ Deploy the intake @@ -104,23 +103,10 @@ class DeployIntake(SetPivot): def __init__(self, subsystem: Intake): super().__init__(subsystem, intake_deploy_angle) - -class DeployIntakeOut(commands2.SequentialCommandGroup): +class DeployIntakeOut(SetPivotIn): """ - Deploy intake by setting pivot to specified angle with voltageout + Deploy intake by setting pivot to specified angle with voltagein """ - def __init__(self, subsystem: Intake, angle: float): - super().__init__() - self.command = SetPivotIn(subsystem, intake_deploy_angle) - - def initialize(self): - self.command.initialize() - - def execute(self): - pass + def __init__(self, subsystem: Intake): + super().__init__(subsystem, intake_deploy_angle) - def isFinished(self) -> bool: - return self.command.isFinished() - - def end(self, interrupted: bool): - self.command.end(interrupted) \ No newline at end of file diff --git a/subsystems/superstructure.py b/subsystems/superstructure.py new file mode 100644 index 0000000..77cc434 --- /dev/null +++ b/subsystems/superstructure.py @@ -0,0 +1,13 @@ +import commands2 +from .constants import * +from subsystems import indexer, intake +from intake import SetPivot +from indexer import RunIndexer +from wpimath.filter import Debouncer + +class Index(commands2.ParallelDeadlineGroup): + def __init__(self, indexer: Indexer, intake: Intake): + super().__init__( + SetPivot(intake, intake_initial_angle), + RunIndexer(indexer) + ) \ No newline at end of file From df69e74d7214f7eecb91a9458eed09ee4d42daae Mon Sep 17 00:00:00 2001 From: theA-Train <146664346+theA-Train@users.noreply.github.com> Date: Thu, 19 Feb 2026 16:26:16 -0500 Subject: [PATCH 5/9] setpivotin for superstructure.py --- subsystems/Intake/constants.py | 4 +++- subsystems/intake/__init__.py | 2 +- subsystems/intake/command.py | 1 - subsystems/intake/subsystem.py | 15 +++++++++++++-- subsystems/superstructure.py | 11 +++++------ 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/subsystems/Intake/constants.py b/subsystems/Intake/constants.py index e848187..4d9d2f7 100644 --- a/subsystems/Intake/constants.py +++ b/subsystems/Intake/constants.py @@ -9,9 +9,11 @@ cancoder_id = 26 #placeholder angle_threshold = 2 #placeholder fuel_speed = 0.0 #placeholder -intake_deploy_angle = 45 #placeholder +intake_deploy_angle = 90 intake_initial_angle = 0 #placeholder voltage_out = 3 #placeholder +intake_maximum_angle = 127 + horizontal_motor_configs = ( configs.TalonFXConfiguration() diff --git a/subsystems/intake/__init__.py b/subsystems/intake/__init__.py index 9aefef2..95bc597 100644 --- a/subsystems/intake/__init__.py +++ b/subsystems/intake/__init__.py @@ -1,3 +1,3 @@ from .subsystem import Intake -from .command import SetPivot, RunIntake, ReverseIntake, DeployIntake +from .command import * from .constants import intake_initial_angle, intake_deploy_angle \ No newline at end of file diff --git a/subsystems/intake/command.py b/subsystems/intake/command.py index fdd75ba..19fb3ab 100644 --- a/subsystems/intake/command.py +++ b/subsystems/intake/command.py @@ -70,7 +70,6 @@ def isFinished(self) -> bool: def end(self, interrupted: bool): self.subsystem.stop_intake() - class SetPivotIn(commands2.Command): """ Set pivot motor to specified angle with voltage in diff --git a/subsystems/intake/subsystem.py b/subsystems/intake/subsystem.py index 30ef71d..af637b0 100644 --- a/subsystems/intake/subsystem.py +++ b/subsystems/intake/subsystem.py @@ -97,15 +97,26 @@ def is_at_angle(self, angle: float): """ checks at angle """ - return abs(self.get_pivot_angle() - angle) < angle_threshold + self.angle = self.limit_pivot_angle(angle) + return abs(self.get_pivot_angle() - self.angle) < angle_threshold def set_pivot(self, angle: float): """ set pivot motor angle """ - self.target_angle = angle + self.target_angle = self.limit_pivot_angle(angle) self.pivot_request = controls.MotionMagicVoltage(angle) self.pivot_motor.set_control(self.pivot_request) + + def limit_pivot_angle(self, angle: float): + """ + limit angle request to max pivot motor + """ + if angle >= intake_maximum_angle: + return intake_maximum_angle + elif angle <= intake_initial_angle: + return intake_initial_angle + return angle def update_table(self): """ diff --git a/subsystems/superstructure.py b/subsystems/superstructure.py index 77cc434..96de335 100644 --- a/subsystems/superstructure.py +++ b/subsystems/superstructure.py @@ -1,13 +1,12 @@ import commands2 -from .constants import * +from subsystems.intake import constants from subsystems import indexer, intake -from intake import SetPivot -from indexer import RunIndexer -from wpimath.filter import Debouncer +from subsystems.intake import SetPivotIn +from subsystems.indexer import RunIndexer class Index(commands2.ParallelDeadlineGroup): - def __init__(self, indexer: Indexer, intake: Intake): + def __init__(self, indexer: indexer.Indexer, intake: intake.Intake): super().__init__( - SetPivot(intake, intake_initial_angle), + SetPivotIn(intake, constants.intake_deploy_angle), RunIndexer(indexer) ) \ No newline at end of file From 40946d2fd392bbf577da60427f11a7612d60de8c Mon Sep 17 00:00:00 2001 From: theA-Train <146664346+theA-Train@users.noreply.github.com> Date: Fri, 20 Feb 2026 15:18:58 -0500 Subject: [PATCH 6/9] angle -> rotations --- subsystems/Intake/constants.py | 6 +++--- subsystems/intake/__init__.py | 2 +- subsystems/intake/command.py | 6 +++--- subsystems/intake/subsystem.py | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/subsystems/Intake/constants.py b/subsystems/Intake/constants.py index 4d9d2f7..5baba82 100644 --- a/subsystems/Intake/constants.py +++ b/subsystems/Intake/constants.py @@ -9,10 +9,10 @@ cancoder_id = 26 #placeholder angle_threshold = 2 #placeholder fuel_speed = 0.0 #placeholder -intake_deploy_angle = 90 -intake_initial_angle = 0 #placeholder +intake_retract_rotation = -0.25 +intake_deploy_rotation = 0 voltage_out = 3 #placeholder -intake_maximum_angle = 127 +intake_maximum_rotation = -0.3527 horizontal_motor_configs = ( diff --git a/subsystems/intake/__init__.py b/subsystems/intake/__init__.py index 95bc597..99ac893 100644 --- a/subsystems/intake/__init__.py +++ b/subsystems/intake/__init__.py @@ -1,3 +1,3 @@ from .subsystem import Intake from .command import * -from .constants import intake_initial_angle, intake_deploy_angle \ No newline at end of file +from .constants import intake_retract_rotation, intake_deploy_rotation, intake_maximum_rotation \ No newline at end of file diff --git a/subsystems/intake/command.py b/subsystems/intake/command.py index 19fb3ab..8d9c7fb 100644 --- a/subsystems/intake/command.py +++ b/subsystems/intake/command.py @@ -95,17 +95,17 @@ def end(self, interrupted: bool): self.subsystem.pivot_running = False else: log.message("intake pivot interrupted") -class DeployIntake(SetPivot): +class RetractIntake(SetPivot): """ Deploy the intake """ def __init__(self, subsystem: Intake): - super().__init__(subsystem, intake_deploy_angle) + super().__init__(subsystem, intake_retract_rotation) class DeployIntakeOut(SetPivotIn): """ Deploy intake by setting pivot to specified angle with voltagein """ def __init__(self, subsystem: Intake): - super().__init__(subsystem, intake_deploy_angle) + super().__init__(subsystem, intake_deploy_rotation) diff --git a/subsystems/intake/subsystem.py b/subsystems/intake/subsystem.py index af637b0..2a6e62f 100644 --- a/subsystems/intake/subsystem.py +++ b/subsystems/intake/subsystem.py @@ -18,7 +18,7 @@ def __init__(self): self.pivot_request = controls.MotionMagicVoltage(0.0) self.target_angle = 0.0 - self.pivot_motor.set_position(0.0) + self.pivot_motor.set_position(intake_deploy_rotation) self.intake_running = False self.pivot_running = False @@ -112,10 +112,10 @@ def limit_pivot_angle(self, angle: float): """ limit angle request to max pivot motor """ - if angle >= intake_maximum_angle: - return intake_maximum_angle - elif angle <= intake_initial_angle: - return intake_initial_angle + if angle >= intake_maximum_rotation: + return intake_maximum_rotation + elif angle <= intake_retract_rotation: + return intake_retract_rotation return angle def update_table(self): From a79d19314975b62b439b4aff5c7552f04569a460 Mon Sep 17 00:00:00 2001 From: theA-Train <146664346+theA-Train@users.noreply.github.com> Date: Fri, 20 Feb 2026 16:31:02 -0500 Subject: [PATCH 7/9] organized constants --- subsystems/Intake/constants.py | 11 ++++++++--- subsystems/intake/subsystem.py | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/subsystems/Intake/constants.py b/subsystems/Intake/constants.py index 5baba82..17c7dd5 100644 --- a/subsystems/Intake/constants.py +++ b/subsystems/Intake/constants.py @@ -4,15 +4,20 @@ from phoenix6.hardware import TalonFX from phoenix6.configs import TalonFXConfiguration +# ids horizontal_motor_id = 25 #placeholder pivot_motor_id = 24 #placeholder cancoder_id = 26 #placeholder + +# constants angle_threshold = 2 #placeholder fuel_speed = 0.0 #placeholder -intake_retract_rotation = -0.25 -intake_deploy_rotation = 0 voltage_out = 3 #placeholder -intake_maximum_rotation = -0.3527 + +# +intake_retract_rotation = 0.25 +intake_deploy_rotation = 0 +intake_maximum_rotation = 0.3527 horizontal_motor_configs = ( diff --git a/subsystems/intake/subsystem.py b/subsystems/intake/subsystem.py index 2a6e62f..99aa648 100644 --- a/subsystems/intake/subsystem.py +++ b/subsystems/intake/subsystem.py @@ -18,7 +18,9 @@ def __init__(self): self.pivot_request = controls.MotionMagicVoltage(0.0) self.target_angle = 0.0 + #initial zero self.pivot_motor.set_position(intake_deploy_rotation) + self.intake_running = False self.pivot_running = False From d3a74f75cbf09fdc37e2daf821bf5648c0db9164 Mon Sep 17 00:00:00 2001 From: e-bauman Date: Mon, 23 Feb 2026 09:08:23 -0500 Subject: [PATCH 8/9] final intake changes --- robotcontainer.py | 6 ++---- subsystems/Intake/constants.py | 23 +++++++++------------- subsystems/intake/__init__.py | 2 +- subsystems/intake/command.py | 34 ++++++++++++++++++++------------- subsystems/intake/subsystem.py | 35 +++++++++++++++++----------------- subsystems/superstructure.py | 14 ++++++-------- 6 files changed, 56 insertions(+), 58 deletions(-) diff --git a/robotcontainer.py b/robotcontainer.py index fed6058..6d0cb2f 100644 --- a/robotcontainer.py +++ b/robotcontainer.py @@ -16,8 +16,6 @@ import autos from utils import math_utils - -from subsystems import * from typing import Callable class RobotContainer: @@ -127,12 +125,12 @@ def configureButtonBindings(self) -> None: # run intake in reverse self.operator_controller.leftTrigger().whileTrue( - ReverseIntake(self.intake).onlyIf(lambda: self.intake.is_at_angle(intake_deploy_angle)) + ReverseIntake(self.intake) ) # retract intake self.operator_controller.leftBumper().onTrue( - SetPivot(self.intake, intake_initial_angle) + RetractIntake(self.intake) ) # deploy climb diff --git a/subsystems/Intake/constants.py b/subsystems/Intake/constants.py index 17c7dd5..c75e0ba 100644 --- a/subsystems/Intake/constants.py +++ b/subsystems/Intake/constants.py @@ -7,16 +7,15 @@ # ids horizontal_motor_id = 25 #placeholder pivot_motor_id = 24 #placeholder -cancoder_id = 26 #placeholder # constants -angle_threshold = 2 #placeholder -fuel_speed = 0.0 #placeholder +angle_threshold = 0.01 #placeholder +fuel_speed = 0.75 #placeholder voltage_out = 3 #placeholder # intake_retract_rotation = 0.25 -intake_deploy_rotation = 0 +intake_deploy_rotation = 0 intake_maximum_rotation = 0.3527 @@ -26,7 +25,10 @@ configs.MotorOutputConfigs() .with_inverted(signals.InvertedValue.CLOCKWISE_POSITIVE) .with_neutral_mode(signals.NeutralModeValue.BRAKE) - ) + ).with_current_limits( + configs.CurrentLimitsConfigs() + .with_stator_current_limit(80) #placeholder + ) ) pivot_motor_configs = ( @@ -37,8 +39,7 @@ .with_neutral_mode(signals.NeutralModeValue.BRAKE) ).with_feedback( configs.FeedbackConfigs() - .with_feedback_remote_sensor_id(pivot_motor_id) - .with_feedback_sensor_source(signals.FeedbackSensorSourceValue.FUSED_CANCODER) + .with_feedback_sensor_source(signals.FeedbackSensorSourceValue.ROTOR_SENSOR) .with_sensor_to_mechanism_ratio(45) ).with_motion_magic( configs.MotionMagicConfigs() @@ -52,15 +53,9 @@ .with_k_v(0) .with_k_a(0) .with_gravity_type(signals.GravityTypeValue.ARM_COSINE) - ).with_software_limit_switch( - configs.SoftwareLimitSwitchConfigs() - .with_reverse_soft_limit_enable(True) - .with_reverse_soft_limit_threshold(0.1) #placeholder - .with_forward_soft_limit_enable(True) - .with_forward_soft_limit_threshold(0.2) #placeholder ).with_current_limits( configs.CurrentLimitsConfigs() - .with_stator_current_limit(0.4) #placeholder found experimentally + .with_stator_current_limit(60) #placeholder found experimentally ) ) \ No newline at end of file diff --git a/subsystems/intake/__init__.py b/subsystems/intake/__init__.py index 99ac893..998bc76 100644 --- a/subsystems/intake/__init__.py +++ b/subsystems/intake/__init__.py @@ -1,3 +1,3 @@ from .subsystem import Intake -from .command import * +from .command import IntakeIndex, RunIntake, DeployIntake, RetractIntake, ReverseIntake from .constants import intake_retract_rotation, intake_deploy_rotation, intake_maximum_rotation \ No newline at end of file diff --git a/subsystems/intake/command.py b/subsystems/intake/command.py index 8d9c7fb..ed695bf 100644 --- a/subsystems/intake/command.py +++ b/subsystems/intake/command.py @@ -3,6 +3,7 @@ from .constants import * from enum import Enum from utils import local_logger +from phoenix6 import units log = local_logger.LocalLogger("intake") @@ -10,7 +11,7 @@ class SetPivot(commands2.Command): """ Setpivot to specificed angle """ - def __init__(self, subsystem: Intake, angle: float): + def __init__(self, subsystem: Intake, angle: units.rotation): super().__init__() self.subsystem = subsystem self.angle = angle @@ -28,7 +29,6 @@ def isFinished(self) -> bool: def end(self, interrupted: bool): if not interrupted: - self.subsystem.stop_pivot() self.subsystem.pivot_running = False else: log.message("intake pivot interrupted") @@ -69,12 +69,13 @@ def isFinished(self) -> bool: return False def end(self, interrupted: bool): - self.subsystem.stop_intake() + self.subsystem.stop_intake() + class SetPivotIn(commands2.Command): """ Set pivot motor to specified angle with voltage in """ - def __init__(self, subsystem: Intake, angle: float): + def __init__(self, subsystem: Intake, angle: units.rotation): super().__init__() self.subsystem = subsystem self.angle = angle @@ -87,25 +88,32 @@ def execute(self): pass def isFinished(self) -> bool: - return self.subsystem.is_at_angle(self.angle) + return self.subsystem.get_pivot_angle() >= self.angle def end(self, interrupted: bool): - if not interrupted: - self.subsystem.stop_pivot() - self.subsystem.pivot_running = False - else: + self.subsystem.stop_pivot() + self.subsystem.pivot_running = False + if interrupted: log.message("intake pivot interrupted") + class RetractIntake(SetPivot): """ - Deploy the intake + Fully retract the intake """ def __init__(self, subsystem: Intake): - super().__init__(subsystem, intake_retract_rotation) + super().__init__(subsystem, intake_maximum_rotation) -class DeployIntakeOut(SetPivotIn): +class DeployIntake(SetPivot): """ - Deploy intake by setting pivot to specified angle with voltagein + Fully deploy intake """ def __init__(self, subsystem: Intake): super().__init__(subsystem, intake_deploy_rotation) +class IntakeIndex(SetPivotIn): + """ + Index with the intake by setting pivot to specified angle with voltagein + """ + def __init__(self, subsystem: Intake): + super().__init__(subsystem, intake_retract_rotation) + diff --git a/subsystems/intake/subsystem.py b/subsystems/intake/subsystem.py index 99aa648..4b0e2f9 100644 --- a/subsystems/intake/subsystem.py +++ b/subsystems/intake/subsystem.py @@ -1,5 +1,5 @@ from phoenix6.hardware import CANcoder -from phoenix6 import StatusSignal, controls, configs, hardware, signals +from phoenix6 import StatusSignal, controls, configs, hardware, signals, units import math import commands2 from .constants import * @@ -12,10 +12,11 @@ def __init__(self): # self.encoder: CANcoder = CANcoder() self.horizontal_motor = hardware.TalonFX(horizontal_motor_id) - self.pivot_motor = hardware.TalonFX(pivot_motor_id) + self.horizontal_motor_out = controls.DutyCycleOut(0) - self.pivot_request = controls.MotionMagicVoltage(0.0) + self.pivot_motion_magic = controls.MotionMagicVoltage(0.0) + self.pivot_voltage = controls.VoltageOut(0) self.target_angle = 0.0 #initial zero @@ -28,7 +29,6 @@ def __init__(self): self.pivot_motor.configurator.apply(pivot_motor_configs) self.table = ntcore.NetworkTableInstance.getDefault().getTable("Intake") self.anglepub = self.table.getDoubleTopic("pivot angle").publish() - # self.zeroedpub = self.table.getBooleanTopic("pivot zeroed").publish() self.targetpub = self.table.getDoubleTopic("target angle").publish() self.pivot_supply_currentpub = self.table.getDoubleTopic("pivot supply current").publish() self.horizontal_motor_currentpub = self.table.getDoubleTopic("horizontal motor current").publish() @@ -74,7 +74,7 @@ def get_horizontal_motor_supply_current(self): """ return self.horizontal_motor.get_supply_current() - def get_pivot_angle(self): + def get_pivot_angle(self) -> units.rotation: """ get rotations of pivot motor """ @@ -84,33 +84,29 @@ def stop_pivot(self): """ stop pivot motor """ - self.pivot_request = controls.MotionMagicDutyCycle(0.0) - self.pivot_motor.set_control(self.pivot_request) + self.pivot_motor.set_control(self.pivot_voltage.with_output(0)) - def set_pivot_motor_in(self, output:float): + def set_pivot_motor_in(self, output: units.volt): """ set pivot motor voltage """ self.output = output - self.pivot_request = controls.VoltageOut(-(self.output)) - self.pivot_motor.set_control(self.pivot_request) + self.pivot_motor.set_control(self.pivot_voltage.with_output(self.output)) - def is_at_angle(self, angle: float): + def is_at_angle(self, angle: units.rotation): """ checks at angle """ - self.angle = self.limit_pivot_angle(angle) - return abs(self.get_pivot_angle() - self.angle) < angle_threshold + return abs(self.get_pivot_angle() - angle) < angle_threshold - def set_pivot(self, angle: float): + def set_pivot(self, angle: units.rotation): """ set pivot motor angle """ self.target_angle = self.limit_pivot_angle(angle) - self.pivot_request = controls.MotionMagicVoltage(angle) - self.pivot_motor.set_control(self.pivot_request) + self.pivot_motor.set_control(self.pivot_motion_magic.with_position(self.target_angle)) - def limit_pivot_angle(self, angle: float): + def limit_pivot_angle(self, angle: units.rotation): """ limit angle request to max pivot motor """ @@ -129,4 +125,7 @@ def update_table(self): self.pivot_supply_currentpub.set(self.get_pivot_motor_supply_current().value) self.intake_runningpub.set(self.intake_running) self.horizontal_motor_currentpub.set(self.get_horizontal_motor_supply_current().value) - self.pivot_stator_currentpub.set(self.get_pivot_motor_stator_current().value) \ No newline at end of file + self.pivot_stator_currentpub.set(self.get_pivot_motor_stator_current().value) + + def periodic(self): + self.update_table() \ No newline at end of file diff --git a/subsystems/superstructure.py b/subsystems/superstructure.py index 96de335..38d6ce2 100644 --- a/subsystems/superstructure.py +++ b/subsystems/superstructure.py @@ -1,12 +1,10 @@ -import commands2 -from subsystems.intake import constants -from subsystems import indexer, intake -from subsystems.intake import SetPivotIn -from subsystems.indexer import RunIndexer +from commands2 import ParallelCommandGroup +from .indexer import RunIndexer, Indexer +from .intake import IntakeIndex, Intake -class Index(commands2.ParallelDeadlineGroup): - def __init__(self, indexer: indexer.Indexer, intake: intake.Intake): +class Index(ParallelCommandGroup): + def __init__(self, indexer: Indexer, intake: Intake): super().__init__( - SetPivotIn(intake, constants.intake_deploy_angle), + IntakeIndex(intake), RunIndexer(indexer) ) \ No newline at end of file From 8564155207c5c3c304438b0e8ce14b5be8953a8c Mon Sep 17 00:00:00 2001 From: e-bauman Date: Mon, 23 Feb 2026 09:37:23 -0500 Subject: [PATCH 9/9] switch indexing command --- robotcontainer.py | 2 +- subsystems/__init__.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/robotcontainer.py b/robotcontainer.py index bd31bb9..1587ca6 100644 --- a/robotcontainer.py +++ b/robotcontainer.py @@ -145,7 +145,7 @@ def configureButtonBindings(self) -> None: ) Trigger(lambda: self.drivetrain.ready_to_shoot and self.shooter.ready_to_shoot()).whileTrue( - RunIndexer(self.indexer) + Index(self.indexer, self.intake) ) # drive in "snake mode" (intake faces direction of travel) diff --git a/subsystems/__init__.py b/subsystems/__init__.py index 8f9504a..93c7372 100644 --- a/subsystems/__init__.py +++ b/subsystems/__init__.py @@ -3,3 +3,4 @@ from .climber import * from .indexer import * from .drivetrain import * +from superstructure import Index \ No newline at end of file