This repository has been archived by the owner on Jan 15, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74c78eb
commit 5685e2d
Showing
15 changed files
with
207 additions
and
126 deletions.
There are no files selected for viewing
This file contains 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 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,36 +1,53 @@ | ||
import wpilib | ||
|
||
# Define step numbers for state machine. | ||
START_SPIN = 0 | ||
ARM_DOWN = 1 | ||
ARM_DOWN = 1 | ||
ARM_UP = 2 | ||
|
||
|
||
class intakeBall(): | ||
class IntakeBall(): | ||
def __init__(self, intake): | ||
self.intake = intake | ||
self.is_running = False | ||
self.state = START_SPIN | ||
self.timer = wpilib.Timer() | ||
self.timer.start() | ||
|
||
def get_running(self): | ||
"""Return bool: is intake currently running?""" | ||
return self.is_running | ||
|
||
def doit(self): | ||
|
||
def go(self): | ||
"""Actually intake ball.""" | ||
# Tell program ball intake is running. | ||
self.is_running = True | ||
|
||
|
||
# If state machine is at 0, start spinning intake motor | ||
if self.state == START_SPIN: | ||
# Reset timer | ||
self.timer.reset() | ||
# Start motor | ||
self.intake.intake() | ||
# If time is up, move on to the next step | ||
if self.timer.hasPeriodPassed(1): | ||
self.state = ARM_DOWN | ||
# If state machine is at 1, put arm down | ||
if self.state == ARM_DOWN: | ||
# Move arm to middle position | ||
self.intake.set_arm_middle() | ||
# Spin intake motor | ||
self.intake.intake() | ||
# If time is up, move on to next step | ||
if self.timer.hasPeriodPassed(2): | ||
self.state = ARM_UP | ||
# If state machine is at 2, put arm back up | ||
if self.state == ARM_UP: | ||
# Move arm to top position | ||
self.intake.set_arm_top() | ||
# If arm has reached desired position | ||
if self.intake.on_target(): | ||
# Note that ball intake has finished. | ||
self.is_running = False | ||
self.state = START_SPIN | ||
# Reset statemachine | ||
self.state = 0 |
This file contains 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 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,54 +1,79 @@ | ||
import wpilib | ||
|
||
# Define constants | ||
ARM_DOWN = 1 | ||
DRIVE_ENC = 2 | ||
DRIVE = 3 | ||
ARM_MIDDLE = 4 | ||
ARM_UP = 5 | ||
|
||
|
||
class PortcullisLift: | ||
|
||
def __init__(self, sd, drive, intake, drive_speed=-.5): | ||
self.intake = intake | ||
self.drive = drive | ||
self.sd = sd | ||
|
||
|
||
# Get set speeds from NetworkTables | ||
self.drive_speed = self.sd.getAutoUpdateValue('Portcullis | Drive Speed', .3) | ||
self.drive_reverse_speed = self.sd.getAutoUpdateValue('Portcullis | Reverse Speed', -.05) | ||
self.drive_speed_2 = self.sd.getAutoUpdateValue('Portcullis | Drive Speed_2', .5) | ||
|
||
# By default, not running. | ||
self.is_running = False | ||
# Default state is first. | ||
self.state = ARM_DOWN | ||
|
||
|
||
# Start timer | ||
self.timer = wpilib.Timer() | ||
self.timer.start() | ||
|
||
def get_running(self): | ||
"""Return True if portcullis lift is in progress, False if not""" | ||
return self.is_running | ||
|
||
|
||
def doit(self): | ||
|
||
def go(self): | ||
"""Actually lift portcullis.""" | ||
# Note that process is now running. | ||
self.is_running = True | ||
#Add state machine to put the arm at the bottom first | ||
# If state machine is at 1, put arm at the bottom | ||
# Add state machine to put the arm at the bottom first | ||
if self.state == ARM_DOWN: | ||
# Move arm to lowest position | ||
self.intake.set_arm_bottom() | ||
# If arm has moved to desired position | ||
if self.intake.on_target(): | ||
# Reset the timer | ||
self.timer.reset() | ||
# Move on to the next state | ||
self.state = DRIVE | ||
# If state machine is at 2, drive forward | ||
if self.state == DRIVE: | ||
# Move forward set amount | ||
self.drive.move(self.drive_speed.value, 0) | ||
# If robot is done moving that amount | ||
if self.timer.hasPeriodPassed(1): | ||
# Reset timer and switch to next state | ||
self.timer.reset() | ||
self.state = ARM_MIDDLE | ||
# If on third state, move arm up halfway and move a bit | ||
if self.state == ARM_MIDDLE: | ||
# Move forward predefined amount | ||
self.drive.move(self.drive_reverse_speed.value, 0) | ||
# Move arm to top | ||
self.intake.set_arm_top() | ||
# If halfway done, move to next state | ||
# (the reason it works like this is complicated and not important) | ||
if self.timer.hasPeriodPassed(.5): | ||
self.state = ARM_UP | ||
# If on final state | ||
if self.state == ARM_UP: | ||
# Move arm to top | ||
self.intake.set_arm_top() | ||
#self.drive.move(self.drive_speed_2.value, 0) | ||
# If everything's done | ||
if self.drive.drive_distance(36): | ||
#if #self.intake.on_target(): | ||
# Note that process has finished | ||
self.is_running = False | ||
self.state = ARM_DOWN | ||
|
||
|
||
|
||
# Switch state back to first | ||
self.state = ARM_DOWN |
This file contains 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,27 +1,40 @@ | ||
import components.intake as Intake | ||
from magicbot import StateMachine, state, timed_state | ||
|
||
|
||
class ShootBall(StateMachine): | ||
# Aliases | ||
intake = Intake.Arm | ||
|
||
def on_enable(self): | ||
"""When initiated""" | ||
self.is_running = False | ||
|
||
def get_running(self): | ||
"""Is ball being shot?""" | ||
return self.is_running | ||
|
||
def shoot(self): | ||
"""When called, engage StateMachine to shoot""" | ||
self.engage() | ||
|
||
def stop(self): | ||
"""When called, stop the ball shooting process""" | ||
self.done() | ||
|
||
@state(first = True, must_finish = True) | ||
@state(first=True, must_finish=True) | ||
# First state, lower arm. | ||
def lower_arms(self): | ||
"""Lower arm in preparation for shot""" | ||
# Move arm to middle | ||
self.intake.set_arm_middle() | ||
# If close enough to desired position | ||
if self.intake.get_position() > 2000: | ||
# Move to shooting step | ||
self.next_state('fire') | ||
|
||
@timed_state(duration = 1, must_finish = True) | ||
@timed_state(duration=1, must_finish=True) | ||
def fire(self): | ||
"""Eject ball""" | ||
# Shoot it yo | ||
self.intake.outtake() |
This file contains 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
Oops, something went wrong.