-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat/intake #16
Feat/intake #16
Changes from 6 commits
b2475fa
bba22e0
217c195
be9fb57
ccafef6
81904a6
af1a428
1250463
7c11e12
7a7d1de
a3c1940
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from command.intake import * |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import config | ||
import wpilib | ||
from robotpy_toolkit_7407 import SubsystemCommand | ||
from oi.keymap import Controllers | ||
from subsystem import Intake | ||
from robotpy_toolkit_7407.utils.units import radians | ||
|
||
|
||
class SetIntake(SubsystemCommand[Intake]): | ||
def __init__(self, subsystem: Intake, intake_active: bool, go_cube: bool, go_cone: bool): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also when you implement the wrist functionality, make sure to add it to this command and not create a new one, since we can only run one command per subsystem at a time |
||
super().__init__(subsystem) | ||
self.intake_active = intake_active | ||
self.finished = False | ||
self.go_cube = go_cube | ||
self.go_cone = go_cone | ||
|
||
def initialize(self) -> None: | ||
""" | ||
Sets the intake to the desired state | ||
:return: | ||
""" | ||
if self.intake_active and self.go_cube: | ||
self.subsystem.grab_cube() | ||
elif self.intake_active and self.go_cone: | ||
self.subsystem.grab_cone() | ||
else: | ||
self.subsystem.set_lower_output(0.025) | ||
self.subsystem.set_upper_output(0.025) | ||
|
||
def execute(self) -> None: | ||
""" | ||
Checks if the intake has detected a game piece | ||
:return: | ||
""" | ||
if self.go_cube and self.subsystem.get_cube_detected(): | ||
self.finished = True | ||
Controllers.OPERATOR_CONTROLLER.setRumble(wpilib.Joystick.RumbleType.kBothRumble, 0.5) | ||
elif self.go_cone and self.subsystem.get_cone_detected(): | ||
self.finished = True | ||
Controllers.OPERATOR_CONTROLLER.setRumble(wpilib.Joystick.RumbleType.kBothRumble, 0.5) | ||
elif self.go_cube and self.subsystem.get_no_grab_cube_detected(): | ||
self.finished = True | ||
Controllers.OPERATOR_CONTROLLER.setRumble(wpilib.Joystick.RumbleType.kBothRumble, 0.5) | ||
|
||
def isFinished(self) -> bool: | ||
""" | ||
Checks if the intake has finished | ||
:return: | ||
""" | ||
return self.finished |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
left_intake_motor_id = 15 # change this to the left intake motor id | ||
right_intake_motor_id = 16 # change this to the right intake motor id | ||
default_intake_speed = 0.5 # change this to the default intake speed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from subsystem.intake import Intake |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from robotpy_toolkit_7407 import Subsystem | ||
from robotpy_toolkit_7407.motors.rev_motors import SparkMax, SparkMaxConfig | ||
from robotpy_toolkit_7407.utils.units import radians | ||
import config | ||
import rev | ||
import wpilib | ||
|
||
INTAKE_CONFIG = SparkMaxConfig(k_P=1, k_I=1, k_D=1, k_F=1) | ||
|
||
|
||
class Intake(Subsystem): | ||
# left = lower roller, right = upper roller | ||
# lower_back_dist_sensor: rev.AnalogInput() = None | ||
# upper_back_dist_sensor: rev.AnalogInput() = None | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.lower_intake_motor = SparkMax( | ||
can_id=config.left_intake_motor_id, | ||
config=INTAKE_CONFIG | ||
) | ||
self.upper_intake_motor = SparkMax( | ||
can_id=config.right_intake_motor_id, | ||
config=INTAKE_CONFIG | ||
) | ||
self.intake_speed = config.default_intake_speed | ||
|
||
def init(self): | ||
self.lower_intake_motor.init() | ||
self.upper_intake_motor.init() | ||
self.upper_back_dist_sensor = self.right_intake_motor.motor.getAnalog() | ||
self.lower_back_dist_sensor = self.left_intake_motor.motor.getAnalog() | ||
|
||
# Modified version of Sid's game piece detection code, change values on testing | ||
def get_no_grab_cube_detected(self): | ||
avg_voltage = self.lower_back_dist_sensor.getVoltage() | ||
return 0.3 < avg_voltage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably dont need this |
||
|
||
def get_cube_detected(self): | ||
avg_voltage = self.lower_back_dist_sensor.getVoltage() | ||
return 0.7 < avg_voltage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure to take the distance sensor values and put them into the config file |
||
|
||
def get_cone_detected(self): | ||
avg_voltage = self.upper_back_dist_sensor.getVoltage() + self.lower_back_dist_sensor.getVoltage() / 2 | ||
return 0.6 < avg_voltage | ||
|
||
def get_double_station_detected(self): | ||
avg_voltage = self.upper_back_dist_sensor.getVoltage() + self.lower_back_dist_sensor.getVoltage() / 2 | ||
return 0.7 < avg_voltage | ||
|
||
def set_upper_output(self, speed: float): | ||
self.upper_intake_motor.set_raw_output(speed) | ||
|
||
def set_lower_output(self, speed: float): | ||
self.lower_intake_motor.set_raw_output(speed) | ||
|
||
def grab_cube(self): | ||
self.set_lower_output(self.intake_speed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is fine for now, but just know you might need to include that upper motor to control. I would refer to the videos i sent you. |
||
|
||
def grab_cone(self): | ||
self.set_lower_output(self.intake_speed) | ||
self.set_upper_output(self.intake_speed) | ||
|
||
def eject_piece(self): | ||
self.set_lower_output(-self.intake_speed) | ||
self.set_upper_output(-self.intake_speed) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need both |
||
def disengage(self): | ||
self.set_lower_output(0.05) | ||
self.set_upper_output(0.05) | ||
|
||
def stop(self): | ||
self.lower_intake_motor.set_raw_output(0) | ||
self.upper_intake_motor.set_raw_output(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of
go_cube
andgo_cone
, use a dictionary likegame_piece
and in constants:
game_piece = { 'cone':0 'cube':1 }
then use this inside the command