forked from commaai/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tune.py
143 lines (112 loc) · 5.46 KB
/
tune.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from selfdrive.kegman_conf import kegman_conf
import subprocess
import os
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../"))
letters = { "a":[ "###", "# #", "###", "# #", "# #"], "b":[ "###", "# #", "###", "# #", "###"], "c":[ "###", "#", "#", "#", "###"], "d":[ "##", "# #", "# #", "# #", "##"], "e":[ "###", "#", "###", "#", "###"], "f":[ "###", "#", "###", "#", "#"], "g":[ "###", "# #", "###", " #", "###"], "h":[ "# #", "# #", "###", "# #", "# #"], "i":[ "###", " #", " #", " #", "###"], "j":[ "###", " #", " #", " #", "##"], "k":[ "# #", "##", "#", "##", "# #"], "l":[ "#", "#", "#", "#", "###"], "m":[ "# #", "###", "###", "# #", "# #"], "n":[ "###", "# #", "# #", "# #", "# #"], "o":[ "###", "# #", "# #", "# #", "###"], "p":[ "###", "# #", "###", "#", "#"], "q":[ "###", "# #", "###", " #", " #"], "r":[ "###", "# #", "##", "# #", "# #"], "s":[ "###", "#", "###", " #", "###"], "t":[ "###", " #", " #", " #", " #"], "u":[ "# #", "# #", "# #", "# #", "###"], "v":[ "# #", "# #", "# #", "# #", " #"], "w":[ "# #", "# #", "# #", "###", "###"], "x":[ "# #", " #", " #", " #", "# #"], "y":[ "# #", "# #", "###", " #", "###"], "z":[ "###", " #", " #", "#", "###"], " ":[ " "], "1":[ " #", "##", " #", " #", "###"], "2":[ "###", " #", "###", "#", "###"], "3":[ "###", " #", "###", " #", "###"], "4":[ "#", "#", "# #", "###", " #"], "5":[ "###", "#", "###", " #", "###"], "6":[ "###", "#", "###", "# #", "###"], "7":[ "###", " # ", " #", " #", "#"], "8":[ "###", "# #", "###", "# #", "###"], "9":[ "###", "# #", "###", " #", "###"], "0":[ "###", "# #", "# #", "# #", "###"], "!":[ " # ", " # ", " # ", " ", " # "], "?":[ "###", " #", " ##", " ", " # "], ".":[ " ", " ", " ", " ", " # "], "]":[ " ", " ", " ", " #", " # "], "/":[ " #", " #", " # ", "# ", "# "], ":":[ " ", " # ", " ", " # ", " "], "@":[ "###", "# #", "## ", "# ", "###"], "'":[ " # ", " # ", " ", " ", " "], "#":[ " # ", "###", " # ", "###", " # "], "-":[ " ", " ","###"," "," "] }
# letters stolen from here: http://www.stuffaboutcode.com/2013/08/raspberry-pi-minecraft-twitter.html
def print_letters(text):
bigletters = []
for i in text:
bigletters.append(letters.get(i.lower(),letters[' ']))
output = ['']*5
for i in range(5):
for j in bigletters:
temp = ' '
try:
temp = j[i]
except:
pass
temp += ' '*(5-len(temp))
temp = temp.replace(' ',' ')
temp = temp.replace('#','@')
output[i] += temp
return '\n'.join(output)
import sys, termios, tty, os, time
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
button_delay = 0.2
kegman = kegman_conf()
#kegman.conf['tuneGernby'] = "1"
#kegman.write_config(kegman.conf)
param = ["tuneGernby", "liveParams", "Kp", "Ki"]
j = 0
while True:
print ""
print print_letters(param[j][0:9])
print ""
print print_letters(kegman.conf[param[j]])
print ""
print ("1, 3, 5, 7 to incr 0.1, 0.05, 0.01, 0.001")
print ("a, d, g, j to decr 0.1, 0.05, 0.01, 0.001")
print ("0 / L to make the value 0 / 1")
print ("press SPACE / m for next /prev parameter")
print ("press z to quit")
char = getch()
write_json = False
if (char == "7"):
kegman.conf[param[j]] = str(float(kegman.conf[param[j]]) + 0.001)
write_json = True
if (char == "5"):
kegman.conf[param[j]] = str(float(kegman.conf[param[j]]) + 0.01)
write_json = True
elif (char == "3"):
kegman.conf[param[j]] = str(float(kegman.conf[param[j]]) + 0.05)
write_json = True
elif (char == "1"):
kegman.conf[param[j]] = str(float(kegman.conf[param[j]]) + 0.1)
write_json = True
elif (char == "j"):
kegman.conf[param[j]] = str(float(kegman.conf[param[j]]) - 0.001)
write_json = True
elif (char == "g"):
kegman.conf[param[j]] = str(float(kegman.conf[param[j]]) - 0.01)
write_json = True
elif (char == "d"):
kegman.conf[param[j]] = str(float(kegman.conf[param[j]]) - 0.05)
write_json = True
elif (char == "a"):
kegman.conf[param[j]] = str(float(kegman.conf[param[j]]) - 0.1)
write_json = True
elif (char == "0"):
kegman.conf[param[j]] = "0"
write_json = True
elif (char == "l"):
kegman.conf[param[j]] = "1"
write_json = True
elif (char == " "):
if j < len(param) - 1:
j = j + 1
else:
j = 0
elif (char == "m"):
if j > 0:
j = j - 1
else:
j = len(param) - 1
elif (char == "z"):
process.kill()
break
if float(kegman.conf['tuneGernby']) != 1 and float(kegman.conf['tuneGernby']) != 0:
kegman.conf['tuneGernby'] = "1"
if float(kegman.conf['Ki']) < 0 and float(kegman.conf['Ki']) != -1:
kegman.conf['Ki'] = "0"
if float(kegman.conf['Ki']) > 2:
kegman.conf['Ki'] = "2"
if float(kegman.conf['Kp']) < 0 and float(kegman.conf['Kp']) != -1:
kegman.conf['Kp'] = "0"
if float(kegman.conf['Kp']) > 3:
kegman.conf['Kp'] = "3"
if kegman.conf['liveParams'] != "1" and kegman.conf['liveParams'] != "0":
kegman.conf['liveParams'] = "1"
if write_json:
kegman.write_config(kegman.conf)
time.sleep(button_delay)
else:
process.kill()