-
Notifications
You must be signed in to change notification settings - Fork 0
/
drivetrain.py
47 lines (38 loc) · 1.37 KB
/
drivetrain.py
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
import wpilib
import wpilib as wp
from wpilib import Spark, Encoder
import wpilib.drive as drive
from EncoderConstants import EncoderConstants as EC
import romi
class Drivetrain:
def __init__(self):
self.lMotor = Spark(0)
self.rMotor = Spark(1)
self.lEncoder = Encoder(4, 5)
self.rEncoder = Encoder(6, 7)
self.lEncoder.setDistancePerPulse(EC.distancePerTick)
self.rEncoder.setDistancePerPulse(EC.distancePerTick)
self.drivetrain = drive.DifferentialDrive(self.lMotor, self.rMotor)
self.gyro = romi.RomiGyro()
self.accelerometer = wpilib.BuiltInAccelerometer()
def move(self, rotate, forward):
self.drivetrain.arcadeDrive(rotate, forward)
def getLEncoderDistance(self):
return self.lEncoder.getDistance()
def getREncoderDistance(self):
return self.rEncoder.getDistance()
def zeroEncoders(self):
self.lEncoder.reset()
self.rEncoder.reset()
def getAvgDistanceTravelled(self):
totalTravelled = self.lEncoder.getDistance() + self.rEncoder.getDistance()
#convert to decimal precision
return totalTravelled/2.0
def getGyroAngleZ(self):
"""
Give the twist of the robot
:return: the current twist angle in degrees
"""
return self.gyro.getAngleZ()
def resetGyro(self):
self.gyro.reset()