1
1
#!/usr/bin/env python3
2
2
3
3
from configparser import ConfigParser
4
- from ev3dev2 import sensor
5
4
from ev3dev2 .display import *
6
5
from ev3dev2 .button import *
7
6
from ev3dev2 .sensor import lego
8
- import ev3dev2 .sensor .lego
9
7
from ev3dev2 .motor import *
10
8
import re
9
+ from time import sleep
11
10
12
11
13
12
def configBuilder (configFile = 'robot.cfg' ):
14
13
"""
15
14
Creates a robot config file based on user input and sensor/motor values
16
15
"""
17
16
global lego
17
+ btn = Button ()
18
+ disp = Display ()
18
19
config = ConfigParser ()
19
20
config ['Drivebase' ] = {}
20
21
config ['Sensors' ] = {}
21
22
config ['AuxMotors' ] = {}
22
23
config ['Other' ] = {}
24
+ outPorts = ['OUTPUT_A' , 'OUTPUT_B' , 'OUTPUT_C' , 'OUTPUT_D' ]
23
25
senTypes = ['Color' , 'Gyro' , 'Touch' , 'Ultrasonic' , 'Infrared' ]
24
26
25
27
for i in senTypes :
@@ -28,16 +30,42 @@ def configBuilder(configFile='robot.cfg'):
28
30
mySensor = sensorClass ()
29
31
port = str (mySensor .address )
30
32
port = re .sub ('.*in([0-9]).*' , 'INPUT_\g<1>' , port )
33
+ globals ()[i ] = port
31
34
config ['Sensors' ][i + 'Port' ] = port
32
35
except :
33
36
config ['Sensors' ][i + 'Port' ] = 'None'
34
37
finally :
35
38
mySensor = None
36
39
sensorClass = None
37
40
41
+ for i in outPorts :
42
+ try :
43
+ motor = LargeMotor (eval (i ))
44
+ disp .text_pixels ("Found a Large Motor at " + "port " + i [- 1 ])
45
+ disp .text_pixels ("What kind of motor is this?" , False , 0 , 10 )
46
+ disp .text_pixels ("Press left for left motor," , False , 0 , 20 )
47
+ disp .text_pixels ("right for right motor," , False , 0 , 30 )
48
+ disp .text_pixels ("up for Aux1, or down for Aux2" , False , 0 , 40 )
49
+ disp .update ()
50
+ while not btn .any ():
51
+ pass
52
+ selection = btn .buttons_pressed
53
+ if selection [0 ] == 'left' :
54
+ btn .wait_for_released ('left' )
55
+ lm = motor
56
+ config ['Drivebase' ]['LeftMotorPort' ] = i
57
+ elif selection [0 ] == 'right' :
58
+ btn .wait_for_released ('right' )
59
+ rm = motor
60
+ config ['Drivebase' ]['RightMotorPort' ] = i
61
+
62
+ except :
63
+ pass
64
+
38
65
with open (configFile , 'w' ) as configfile :
39
66
config .write (configfile )
40
67
68
+
41
69
if __name__ == "__main__" :
42
70
configBuilder ('robot2.cfg' )
43
71
0 commit comments