8000 Config builder now detects drive motors. · WesleyJ-128/FLL_Python_Codebase@878d867 · GitHub
[go: up one dir, main page]

Skip to content

Commit 878d867

Browse files
committed
Config builder now detects drive motors.
1 parent 58933cc commit 878d867

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

FLLMaster/AutoConfigBuilder.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
#!/usr/bin/env python3
22

33
from configparser import ConfigParser
4-
from ev3dev2 import sensor
54
from ev3dev2.display import *
65
from ev3dev2.button import *
76
from ev3dev2.sensor import lego
8-
import ev3dev2.sensor.lego
97
from ev3dev2.motor import *
108
import re
9+
from time import sleep
1110

1211

1312
def configBuilder(configFile='robot.cfg'):
1413
"""
1514
Creates a robot config file based on user input and sensor/motor values
1615
"""
1716
global lego
17+
btn = Button()
18+
disp = Display()
1819
config = ConfigParser()
1920
config['Drivebase'] = {}
2021
config['Sensors'] = {}
2122
config['AuxMotors'] = {}
2223
config['Other'] = {}
24+
outPorts = ['OUTPUT_A', 'OUTPUT_B', 'OUTPUT_C', 'OUTPUT_D']
2325
senTypes = ['Color', 'Gyro', 'Touch', 'Ultrasonic', 'Infrared']
2426

2527
for i in senTypes:
@@ -28,16 +30,42 @@ def configBuilder(configFile='robot.cfg'):
2830
mySensor = sensorClass()
2931
port = str(mySensor.address)
3032
port = re.sub('.*in([0-9]).*', 'INPUT_\g<1>', port)
33+
globals()[i] = port
3134
config['Sensors'][i + 'Port'] = port
3235
except:
3336
config['Sensors'][i + 'Port'] = 'None'
3437
finally:
3538
mySensor = None
3639
sensorClass = None
3740

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+
3865
with open(configFile, 'w') as configfile:
3966
config.write(configfile)
4067

68+
4169
if __name__ == "__main__":
4270
configBuilder('robot2.cfg')
4371

FLLMaster/robot2.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[Drivebase]
2+
leftmotorport = OUTPUT_B
3+
rightmotorport = OUTPUT_C
24

35
[Sensors]
46
colorport = INPUT_1

0 commit comments

Comments
 (0)
0