ME 405 Romi
Loading...
Searching...
No Matches
ui_old.py
Go to the documentation of this file.
1from pyb import USB_VCP
2
3ser=USB_VSP()
4side = 0
5saved = []
6
7def ui():
8 # hub
9 if state == 0:
10 if ser.any():
11 char_in = ser.read(1).decode()
12 if char_in == "l":
13 side = 0 #0=left
14 state = 1
15 elif char_in == "r":
16 side = 1 #1=right
17 state = 1
18 else:
19 print("Please enter r for right motor, l for left motor")
20 yield 0
21 elif state == 1:
22 if ser.any():
23 char_in = ser.read(1).decode()
24 if char_in == "+":
25 if side == 0:
26 state = 2
27 else:
28 state = 4
29 elif char_in == "-":
30 if side == 0:
31 state = 3
32 else:
33 state = 5
34 yield 1
35
36 elif state ==2: # positive left
37 if ser.any(): # wait for any character
38 char_in = ser.read(1).decode()
39 # 10% Duty Cycle
40 if char_in == "1":
41 PWM_l.put(10)
42 testing_flg = 1
43 # 20% Duty Cycle
44 elif char_in == "2":
45 PWM_l.put(20)
46 testing_flg = 1
47 # 30% Duty Cycle
48 elif char_in == "3":
49 PWM_l.put(30)
50 testing_flg = 1
51 # 40% Duty Cycle
52 elif char_in == "4":
53 PWM_l.put(40)
54 testing_flg = 1
55 # 50% Duty Cycle
56 elif char_in == "5":
57 PWM_l.put(50)
58 testing_flg = 1
59 # 60% Duty Cycle
60 elif char_in == "6":
61 PWM_l.put(60)
62 testing_flg = 1
63 # 70% Duty Cycle
64 elif char_in == "7":
65 PWM_l.put(70)
66 testing_flg = 1
67 # 80% Duty Cycle
68 elif char_in == "8":
69 PWM_l.put(80)
70 testing_flg = 1
71 # 90% Duty Cycle
72 elif char_in == "9":
73 PWM_l.put(90)
74 testing_flg = 1
75 # 100% Duty Cycle
76 elif char_in == "0":
77 PWM_l.put(100)
78 testing_flg = 1
79 yield 2
80
81 elif state == 3: # positive right
82 if ser.any(): # wait for any character
83 char_in = ser.read(1).decode()
84 # 10% Duty Cycle
85 if char_in == "1":
86 PWM_r.put(10)
87 testing_flg = 1
88 # 20% Duty Cycle
89 elif char_in == "2":
90 PWM_r.put(20)
91 testing_flg = 1
92 # 30% Duty Cycle
93 elif char_in == "3":
94 PWM_r.put(30)
95 testing_flg = 1
96 # 40% Duty Cycle
97 elif char_in == "4":
98 PWM_r.put(40)
99 testing_flg = 1
100 # 50% Duty Cycle
101 elif char_in == "5":
102 PWM_r.put(50)
103 testing_flg = 1
104 # 60% Duty Cycle
105 elif char_in == "6":
106 PWM_r.put(60)
107 testing_flg = 1
108 # 70% Duty Cycle
109 elif char_in == "7":
110 PWM_r.put(70)
111 testing_flg = 1
112 # 80% Duty Cycle
113 elif char_in == "8":
114 PWM_r.put(80)
115 testing_flg = 1
116 # 90% Duty Cycle
117 elif char_in == "9":
118 PWM_r.put(90)
119 testing_flg = 1
120 # 100% Duty Cycle
121 elif char_in == "0":
122 PWM_r.put(100)
123 testing_flg = 1
124 yield 3
125
126 elif state == 4: # negative left
127 if ser.any(): # wait for any character
128 char_in = ser.read(1).decode()
129 # 10% Duty Cycle
130 if char_in == "1":
131 PWM_l.put(-10)
132 testing_flg = 1
133 # 20% Duty Cycle
134 elif char_in == "2":
135 PWM_l.put(-20)
136 testing_flg = 1
137 # 30% Duty Cycle
138 elif char_in == "3":
139 PWM_l.put(-30)
140 testing_flg = 1
141 # 40% Duty Cycle
142 elif char_in == "4":
143 PWM_l.put(-40)
144 testing_flg = 1
145 # 50% Duty Cycle
146 elif char_in == "5":
147 PWM_l.put(-50)
148 testing_flg = 1
149 # 60% Duty Cycle
150 elif char_in == "6":
151 PWM_l.put(-60)
152 testing_flg = 1
153 # 70% Duty Cycle
154 elif char_in == "7":
155 PWM_l.put(-70)
156 testing_flg = 1
157 # 80% Duty Cycle
158 elif char_in == "8":
159 PWM_l.put(-80)
160 testing_flg = 1
161 # 90% Duty Cycle
162 elif char_in == "9":
163 PWM_l.put(-90)
164 testing_flg = 1
165 # 100% Duty Cycle
166 elif char_in == "0":
167 PWM_l.put(-100)
168 testing_flg = 1
169 yield 4
170 elif state == 5: # negative right
171 if ser.any(): # wait for any character
172 char_in = ser.read(1).decode()
173 # 10% Duty Cycle
174 if char_in == "1":
175 PWM_r.put(-10)
176 testing_flg = 1
177 # 20% Duty Cycle
178 elif char_in == "2":
179 PWM_r.put(-20)
180 testing_flg = 1
181 # 30% Duty Cycle
182 elif char_in == "3":
183 PWM_r.put(-30)
184 testing_flg = 1
185 # 40% Duty Cycle
186 elif char_in == "4":
187 PWM_r.put(-40)
188 testing_flg = 1
189 # 50% Duty Cycle
190 elif char_in == "5":
191 PWM_r.put(-50)
192 testing_flg = 1
193 # 60% Duty Cycle
194 elif char_in == "6":
195 PWM_r.put(-60)
196 testing_flg = 1
197 # 70% Duty Cycle
198 elif char_in == "7":
199 PWM_r.put(-70)
200 testing_flg = 1
201 # 80% Duty Cycle
202 elif char_in == "8":
203 PWM_r.put(-80)
204 testing_flg = 1
205 # 90% Duty Cycle
206 elif char_in == "9":
207 PWM_r.put(-90)
208 testing_flg = 1
209 # 100% Duty Cycle
210 elif char_in == "0":
211 PWM_r.put(-100)
212 testing_flg = 1
213 yield 5
214 elif state == 6:
215 if testing_flag == 0
216 p
217 yield state
ui()
Definition ui_old.py:7