-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrobot.py
executable file
·54 lines (38 loc) · 1.73 KB
/
robot.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
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
import wpilib
from ntcore import NetworkTableInstance
import navx
def run():
raise ValueError()
class MyRobot(wpilib.TimedRobot):
def robotInit(self):
self.sd = NetworkTableInstance.getDefault().getTable("SmartDashboard")
self.timer = wpilib.Timer()
#
# Communicate w/navX MXP via the MXP SPI Bus.
# - Alternatively, use the i2c bus.
# See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface/ for details
#
self.navx = navx.AHRS.create_spi()
# self.navx = navx.AHRS.create_i2c()
# Analog input
# self.analog = wpilib.AnalogInput(navx.pins.getNavxAnalogInChannel(0)) <--It seems as though the analog channel is not currently supported.
def disabledInit(self):
self.logger.info("Entered disabled mode")
self.timer.reset()
self.timer.start()
def disabledPeriodic(self):
if self.timer.advanceIfElapsed(0.5):
self.sd.putNumber("Displacement X", self.navx.getDisplacementX())
self.sd.putNumber("Displacement Y", self.navx.getDisplacementY())
self.sd.putBoolean("IsCalibrating", self.navx.isCalibrating())
self.sd.putBoolean("IsConnected", self.navx.isConnected())
self.sd.putNumber("Angle", self.navx.getAngle())
self.sd.putNumber("Pitch", self.navx.getPitch())
self.sd.putNumber("Yaw", self.navx.getYaw())
print("YAW", self.navx.getYaw())
self.sd.putNumber("Roll", self.navx.getRoll())
# self.sd.putNumber("Analog", self.analog.getVoltage())
self.sd.putNumber("Timestamp", self.navx.getLastSensorTimestamp())
if __name__ == "__main__":
wpilib.run(MyRobot)