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