-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathintake.py
More file actions
63 lines (45 loc) · 1.81 KB
/
Copy pathintake.py
File metadata and controls
63 lines (45 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from phoenix5 import WPI_VictorSPX, ControlMode
from commands2 import Subsystem, Command
from wpilib import Timer, SmartDashboard
import constants
class Intake(Subsystem):
def __init__(self) -> None:
self.pivot = WPI_VictorSPX(constants.kIntakeAngleId)
self.roller = WPI_VictorSPX(constants.kIntakeTrackId)
self.pivotUp = False
self.lastBurstTime = 0.0
self.setDefaultCommand(self.stopGamePieceCollector())
def isPivotUp(self) -> bool:
return self.pivotUp
def periodic(self) -> None:
elapsed = Timer.getFPGATimestamp() - self.lastBurstTime
percent = 0
kPivotTimeUp = 1.2
kPivotTimeDown = 0.5
if self.pivotUp:
percent = 0.5 if elapsed < kPivotTimeUp else 0
else:
percent = -0.7 if elapsed < kPivotTimeDown else 0
self.pivot.set(ControlMode.PercentOutput, percent)
def startPivotUp(self) -> None:
if self.pivotUp:
return
self.pivotUp = True
self.lastBurstTime = Timer.getFPGATimestamp()
def stopPivot(self) -> None:
self.pivot.set(0)
def startPivotDown(self) -> None:
if not self.pivotUp:
return
self.pivotUp = False
self.lastBurstTime = Timer.getFPGATimestamp()
def up(self) -> Command:
return self.run(lambda: self.startPivotUp())
def down(self) -> Command:
return self.run(lambda: self.startPivotDown())
def releaseGamePiece(self) -> Command:
return self.run(lambda: self.roller.set(ControlMode.PercentOutput, -1))
def stopGamePieceCollector(self) -> Command:
return self.run(lambda: self.roller.set(ControlMode.PercentOutput, 0))
def colectGamePiece(self) -> Command:
return self.run(lambda: self.roller.set(ControlMode.PercentOutput, 1))