1+ from DriveLibraries import *
2+ import multiprocessing
3+ import Missions
4+ from time import sleep
5+ mission = None
6+ robot = None
7+ programs = []
8+ numPrograms = 0
9+ count = 1
10+ loopIndex = 0
11+
12+ def init ():
13+ global programs
14+ global numPrograms
15+ global robot
16+ robot = Robot ('robot.cfg' )
17+ programs = dir (Missions )
18+ i = 0
19+ index = - 1
20+
21+ length = len (programs )
22+ while i < length :
23+ if not ((programs [index ][0 ] == "a" ) and (programs [index ][1 ].isnumeric ()) and (programs [index ][2 ].isnumeric ())):
24+ programs .pop (index )
25+ else :
26+ index -= 1
27+ i += 1
28+ numPrograms = len (programs )
29+
30+ robot .disp .clear ()
31+ robot .disp .text_grid (programs [0 ][3 :], font = robot .fonts .load ('timR24' ))
32+
33+ def runCurrentMission ():
34+ method_to_call = getattr (Missions , programs [count - 1 ])
35+ method_to_call ()
36+ robot .rm .off (brake = False )
37+ robot .lm .off (brake = False )
38+
39+ def run ():
40+ robot .zeroGyro ()
41+ global mission
42+ mission = multiprocessing .Process (target = runCurrentMission )
43+ mission .start ()
44+
45+ def display ():
46+ name = programs [count - 1 ][3 :]
47+ robot .disp .text_grid (name , font = robot .fonts .load ('timR24' ))
48+
49+ def abort ():
50+ mission .terminate ()
51+ mission .join ()
52+ robot .lm .off (brake = False )
53+ robot .rm .off (brake = False )
54+
55+ def addCount ():
56+ global count
57+ count = (count % numPrograms ) + 1
58+
59+ def minusCount ():
60+ global count
61+ count = ((count + (numPrograms - 2 )) % numPrograms ) + 1
62+
63+ def checkDrift ():
64+ ar = robot .gs .angle_and_rate
65+ rate = ar [1 ]
66+ if rate < - 0.5 or rate > 0.5 :
67+ robot .led .all_off ()
68+ robot .led .set_color ('LEFT' , 'RED' )
69+ robot .led .set_color ('RIGHT' , 'RED' )
70+ else :
71+ robot .led .reset ()
72+
73+ def displaySensor ():
74+ if loopIndex == 0 :
75+ robot .disp .rectangle (False , 0 , 89 , 177 , 120 , 'white' , 'white' )
76+ robot .disp .update
77+ robot .cs ._ensure_mode (robot .cs .MODE_COL_REFLECT )
78+ robot .disp .text_pixels ("P1, Color:" + str (robot .correctedRLI ), False , 40 , 90 , font = robot .fonts .load ('courR10' ))
79+ robot .disp .text_pixels ("P2, Gyro:" + str (robot .correctedAngle ), False , 40 , 100 , font = robot .fonts .load ('courR10' ))
80+ robot .disp .update ()
81+
82+ def calibrate ():
83+ robot .led .all_off ()
84+ robot .led .set_color ('LEFT' , 'YELLOW' )
85+ robot .led .set_color ('RIGHT' , 'YELLOW' )
86+ robot .spkr .beep ('-f 369.99' )
87+ robot .gs .calibrate ()
88+ sleep (1 )
89+ robot .spkr .beep ()
90+ robot .led .reset ()
0 commit comments