generated from Choate-Robotics/7407-DriveCode-Template-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/intake&hopper #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
414dbec
comment to test
theA-Train caa6722
Co-authored-by: achung28 <achung28@users.noreply.github.com>
theA-Train 9596e83
move to constants and cached
theA-Train b837dc7
network tables added
theA-Train c8d6d8a
commands + comments fix
theA-Train d2c627b
runIntake conditional
theA-Train c2140d9
button configs
theA-Train 1246ecc
Merge branch 'dev' into feat/intake&hopper
theA-Train 4ea5daa
proper imports
theA-Train adc1530
softlimit switches for autozeroing
theA-Train d547abc
minor fixes
e-bauman 4f5c468
voltageout command
theA-Train 40707dc
stator current limits
theA-Train 6982090
Merge branch 'dev' into feat/intake&hopper
theA-Train 9d3e92e
Merge branch 'dev' into feat/intake&hopper
e-bauman fdb0094
cleaned up merge and made some small changes to imports and OI
e-bauman 2df22d7
missed one import
e-bauman 70c07aa
Merge branch 'dev' into feat/intake&hopper
e-bauman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| from unittest import signals | ||
| from phoenix6 import StatusSignal, controls, configs, hardware, signals | ||
| from phoenix6.signals import FeedbackSensorSourceValue | ||
| from phoenix6.hardware import TalonFX | ||
| from phoenix6.configs import TalonFXConfiguration | ||
|
|
||
| horizontal_motor_id = 25 #placeholder | ||
| pivot_motor_id = 24 #placeholder | ||
| cancoder_id = 26 #placeholder | ||
| angle_threshold = 2 #placeholder | ||
| fuel_speed = 0.0 #placeholder | ||
| intake_deploy_angle = 45 #placeholder | ||
| intake_initial_angle = 0 #placeholder | ||
| voltage_out = 3 #placeholder | ||
|
|
||
| horizontal_motor_configs = ( | ||
| configs.TalonFXConfiguration() | ||
| .with_motor_output( | ||
| configs.MotorOutputConfigs() | ||
| .with_inverted(signals.InvertedValue.CLOCKWISE_POSITIVE) | ||
| .with_neutral_mode(signals.NeutralModeValue.BRAKE) | ||
|
|
||
| ) | ||
| ) | ||
|
|
||
| pivot_motor_configs = ( | ||
| configs.TalonFXConfiguration() | ||
| .with_motor_output( | ||
| configs.MotorOutputConfigs() | ||
| .with_inverted(signals.InvertedValue.CLOCKWISE_POSITIVE) | ||
| .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_sensor_to_mechanism_ratio(5) # placeholder | ||
| ).with_motion_magic( | ||
| configs.MotionMagicConfigs() | ||
| # .with_motion_magic_cruise_velocity(0) placeholder | ||
| ).with_slot0( | ||
| configs.Slot0Configs() | ||
| .with_k_p(0.0) | ||
| .with_k_i(0.0) | ||
| .with_k_d(0.0) | ||
| .with_k_s(0.0) | ||
| .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 | ||
| ) | ||
|
|
||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from .intake import * | ||
| from .shooter import * | ||
| from .climber import * | ||
| from .indexer import * | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from .subsystem import Intake | ||
| from .command import SetPivot, RunIntake, ReverseIntake, DeployIntake | ||
| from .constants import intake_initial_angle, intake_deploy_angle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| from .subsystem import Intake | ||
| import commands2 | ||
| from .constants import * | ||
| from enum import Enum | ||
| from utils import local_logger | ||
|
|
||
| log = local_logger.LocalLogger("intake") | ||
|
|
||
| class SetPivot(commands2.Command): | ||
| """ | ||
| Setpivot to specificed angle | ||
| """ | ||
| def __init__(self, subsystem: Intake, angle: float): | ||
| super().__init__() | ||
| self.subsystem = subsystem | ||
| self.angle = angle | ||
| self.addRequirements(self.subsystem) | ||
|
|
||
| def initialize(self): | ||
| self.subsystem.set_pivot(self.angle) | ||
| self.subsystem.pivot_running = True | ||
|
|
||
| def execute(self): | ||
| pass | ||
|
|
||
| def isFinished(self) -> bool: | ||
| return self.subsystem.is_at_angle(self.angle) | ||
|
|
||
| def end(self, interrupted: bool): | ||
| if not interrupted: | ||
| self.subsystem.stop_pivot() | ||
| self.subsystem.pivot_running = False | ||
| else: | ||
| log.message("intake pivot interrupted") | ||
|
|
||
| class RunIntake(commands2.Command): | ||
| """ | ||
| Run intake | ||
| """ | ||
| def __init__(self, subsystem: Intake): | ||
| super().__init__() | ||
| self.subsystem = subsystem | ||
| self.addRequirements(self.subsystem) | ||
|
|
||
| def initialize(self): | ||
| self.subsystem.intake_fuel() | ||
|
|
||
| def isFinished(self) -> bool: | ||
| "command expected to be interrupted" | ||
| return False | ||
|
|
||
| def end(self, interrupted: bool): | ||
| self.subsystem.stop_intake() | ||
|
|
||
| class ReverseIntake(commands2.Command): | ||
| """ | ||
| Reverse intake | ||
| """ | ||
| def __init__(self, subsystem: Intake): | ||
| super().__init__() | ||
| self.subsystem = subsystem | ||
| self.addRequirements(self.subsystem) | ||
|
|
||
| def initialize(self): | ||
| self.subsystem.reverse_intake() | ||
|
|
||
| def isFinished(self) -> bool: | ||
| "command expected to be interrupted" | ||
| return False | ||
|
|
||
| def end(self, interrupted: bool): | ||
| self.subsystem.stop_intake() | ||
|
|
||
| class SetPivotOut(commands2.Command): | ||
| """ | ||
| Set pivot motor to specified angle with voltage out | ||
| """ | ||
| def __init__(self, subsystem: Intake, voltage:float, 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.pivot_running = True | ||
|
|
||
| def execute(self): | ||
| pass | ||
|
|
||
| def isFinished(self) -> bool: | ||
| return self.subsystem.is_at_angle(self.angle) | ||
|
|
||
| def end(self, interrupted: bool): | ||
| if not interrupted: | ||
| self.subsystem.stop_pivot() | ||
| self.subsystem.pivot_running = False | ||
| else: | ||
| log.message("intake pivot interrupted") | ||
|
|
||
| class DeployIntake(commands2.SequentialCommandGroup): | ||
| """ | ||
| 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) | ||
| ) | ||
|
|
||
| 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) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| from phoenix6.hardware import CANcoder | ||
| from phoenix6 import StatusSignal, controls, configs, hardware, signals | ||
| import math | ||
| import commands2 | ||
| from .constants import * | ||
| import ntcore | ||
|
|
||
|
|
||
| class Intake(commands2.Subsystem): | ||
| def __init__(self): | ||
| super().__init__() | ||
| # 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.target_angle = 0.0 | ||
|
|
||
| self.pivot_motor.set_position(0.0) | ||
| self.intake_running = False | ||
| self.pivot_running = False | ||
|
|
||
| self.horizontal_motor.configurator.apply(horizontal_motor_configs) | ||
| 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() | ||
| self.intake_runningpub = self.table.getBooleanTopic("intake running").publish() | ||
| self.pivot_stator_currentpub = self.table.getDoubleTopic("pivot stator current").publish() | ||
|
|
||
| def intake_fuel(self): | ||
| """ | ||
| run intake | ||
| """ | ||
| self.horizontal_motor.set_control(self.horizontal_motor_out.with_output(fuel_speed)) | ||
| self.intake_running = True | ||
|
|
||
| def reverse_intake(self): | ||
| """ | ||
| reverse intake | ||
| """ | ||
| self.horizontal_motor.set_control(self.horizontal_motor_out.with_output(-fuel_speed)) | ||
| self.intake_running = True | ||
|
|
||
| def stop_intake(self): | ||
| """ | ||
| stop intake | ||
| """ | ||
| self.horizontal_motor.set_control(self.horizontal_motor_out.with_output(0.0)) | ||
theA-Train marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.intake_running = False | ||
|
|
||
| def get_pivot_motor_supply_current(self): | ||
| """ | ||
| get SUPPLY current of pivot motor | ||
| """ | ||
| return self.pivot_motor.get_supply_current() | ||
|
|
||
| def get_pivot_motor_stator_current(self): | ||
| """ | ||
| get STATOR current of pivot motor | ||
| """ | ||
| return self.pivot_motor.get_stator_current() | ||
|
|
||
| def get_horizontal_motor_supply_current(self): | ||
| """ | ||
| get SUPPLY current of horizontal motor | ||
| """ | ||
| return self.horizontal_motor.get_supply_current() | ||
theA-Train marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def get_pivot_angle(self): | ||
theA-Train marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| get rotations of pivot motor | ||
| """ | ||
| return (self.pivot_motor.get_position().value) | ||
|
|
||
| def stop_pivot(self): | ||
| """ | ||
| stop pivot motor | ||
| """ | ||
| self.pivot_request = controls.MotionMagicDutyCycle(0.0) | ||
| self.pivot_motor.set_control(self.pivot_request) | ||
|
|
||
| def set_pivot_out(self, output:float): | ||
| """ | ||
| set pivot motor voltage | ||
| """ | ||
| self.output = output | ||
| self.pivot_request = controls.VoltageOut(self.output) | ||
| self.pivot_motor.set_control(self.pivot_request) | ||
|
|
||
| def is_at_angle(self, angle: float): | ||
| """ | ||
| checks at angle | ||
| """ | ||
| return abs(self.get_pivot_angle() - angle) < angle_threshold | ||
|
|
||
| def set_pivot(self, angle: float): | ||
| """ | ||
| set pivot motor angle | ||
| """ | ||
| self.target_angle = angle | ||
| self.pivot_request = controls.MotionMagicVoltage(angle) | ||
| self.pivot_motor.set_control(self.pivot_request) | ||
|
|
||
| def update_table(self): | ||
| """ | ||
| update network tables | ||
| """ | ||
| self.anglepub.set(self.get_pivot_angle()) | ||
| self.targetpub.set(self.target_angle) | ||
| 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) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.