8000 Started a config file builder; · WesleyJ-128/FLL_Python_Codebase@58933cc · GitHub
[go: up one dir, main page]

Skip to content

Commit 58933cc

Browse files
committed
Started a config file builder;
currently gets sensor ports robot2.cfg is the auto-generated file.
1 parent 5ad6b1e commit 58933cc

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

FLLMaster/AutoConfigBuilder.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
3+
from configparser import ConfigParser
4+
from ev3dev2 import sensor
5+
from ev3dev2.display import *
6+
from ev3dev2.button import *
7+
from ev3dev2.sensor import lego
8+
import ev3dev2.sensor.lego
9+
from ev3dev2.motor import *
10+
import re
11+
12+
13+
def configBuilder(configFile='robot.cfg'):
14+
"""
15+
Creates a robot config file based on user input and sensor/motor values
16+
"""
17+
global lego
18+
config = ConfigParser()
19+
config['Drivebase'] = {}
20+
config['Sensors'] = {}
21+
config['AuxMotors'] = {}
22+
config['Other'] = {}
23+
senTypes = ['Color', 'Gyro', 'Touch', 'Ultrasonic', 'Infrared']
24+
25+
for i in senTypes:
26+
try:
27+
sensorClass = getattr(lego, i + 'Sensor')
28+
mySensor = sensorClass()
29+
port = str(mySensor.address)
30+
port = re.sub('.*in([0-9]).*', 'INPUT_\g<1>', port)
31+
config['Sensors'][i + 'Port'] = port
32+
except:
33+
config['Sensors'][i + 'Port'] = 'None'
34+
finally:
35+
mySensor < 10000 span class=pl-c1>= None
36+
sensorClass = None
37+
38+
with open(configFile, 'w') as configfile:
39+
config.write(configfile)
40+
41+
if __name__ == "__main__":
42+
configBuilder('robot2.cfg')
43+

FLLMaster/robot.cfg

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ ki = 0
1111
kd = 0.5
1212

1313
[Sensors]
14-
ColorPort=INPUT_1
15-
GyroPort=INPUT_2
16-
InfraredPort=INPUT_4
17-
TouchPort= None
18-
UltrasonicPort=INPUT_3
14+
ColorPort = INPUT_1
15+
GyroPort = INPUT_2
16+
InfraredPort = INPUT_4
17+
TouchPort = None
18+
UltrasonicPort = INPUT_3
1919
kpLine = 0.45
2020
kiLine = 0.01163
2121
kdLine = 2.528

FLLMaster/robot2.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Drivebase]
2+
3+
[Sensors]
4+
colorport = INPUT_1
5+
gyroport = INPUT_2
6+
touchport = None
7+
ultrasonicport = INPUT_3
8+
infraredport = INPUT_4
9+
10+
[AuxMotors]
11+
12+
[Other]
13+

0 commit comments

Comments
 (0)
0