Skip to content

Commit 6525d50

Browse files
committed
Commented Main.py
1 parent 5c9dbd3 commit 6525d50

File tree

2 files changed

+70
-36
lines changed

2 files changed

+70
-36
lines changed

FLLMaster/Main.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,74 @@
11
#!/usr/bin/env python3
22

3+
# Initialize loopIndex variable, used in displaySensor()
34
loopIndex = 0
45

6+
# Import only the functions required for setup;
7+
# MenuLib needs them run before importing other things
58
from MenuLib import init, initthread
9+
# Used for printing to the VS Code output window
610
from sys import stderr
711

12+
# Run the init function from MenuLib, config file name,
13+
# used to instatiate the robot object
814
init('robot.cfg')
15+
# Create the mission process used for running the current mission
916
initthread()
17+
# Now that setup has finished, import everything else from MenuLib
1018
from MenuLib import *
19+
20+
# Calibrate the gyro
1121
calibrate()
22+
# Calibrate the color sensor
1223
robot.reflectCal()
24+
# Initialization has finished, print status message to VS Code output window
1325
print("Finished Init", file=stderr)
1426

27+
# Define the functions for button presses
1528
def left():
29+
# Make sure there is no mission process running; if it is not, decrease count and update the display
30+
# Otherwise, abort the current mission
1631
if not mission.is_alive():
1732
minusCount()
1833
display()
1934
else:
2035
abort()
2136
def right():
37+
# Make sure there is no mission process running; if it is not, increase count and update the display
38+
# Otherwise, abort the current mission
2239
if not mission.is_alive():
2340
addCount()
2441
display()
2542
else:
2643
abort()
2744
def down():
45+
# Make sure there is no mission process running; if it is not, recalibrate the gyro
46+
# Otherwise, abort the current mission
2847
if not mission.is_alive():
2948
calibrate()
3049
else:
3150
abort()
3251
def up():
52+
# Make sure there is no mission process running; if it is not, recalibrate the color sensor
53+
# Otherwise, abort the current mission
3354
if not mission.is_alive():
3455
robot.reflectCal()
3556
else:
3657
abort()
3758
def enter():
59+
# Make sure there is no mission process running; if it is not, run the current mission, increase count, and update the display
60+
# Otherwise, abort the current mission
3861
if not mission.is_alive():
3962
run()
4063
addCount()
4164
display()
4265
else:
4366
abort()
4467

68+
# Print to the VS Code window that the button functions have been defined
4569
print("Functions Defined", file=stderr)
4670

71+
# Define a dictionary for calling the functions defined above based on the names for the buttons
4772
buttonMap = {
4873
'left': left,
4974
'right': right,
@@ -52,14 +77,22 @@ def enter():
5277
'down': down
5378
}
5479

80+
# Print to the VS Code window that the button dictionary has been defined
5581
print("Map Defined", file=stderr)
5682

83+
# Start the infinite menu loop
5784
while True:
85+
# This updates the status and process id of the mission process every loop cycle
5886
from MenuLib import mission
87+
# Store the list of buttons currently pressed as buttonlist
5988
buttonlist = robot.btn.buttons_pressed
89+
# Check if there are any buttons pressed; if there is, run the corresponding function
6090
if buttonlist:
6191
buttonMap[buttonlist[0]]()
92+
# Increment loopIndex and reset to zero every hundreth loop
6293
loopIndex = (loopIndex + 1) % 100
94+
# Make sure there is no mission running (to prevent resource conflicts),
95+
# and if there is none, display the sensor values and update the light color based on the gyro sensor
6396
if not mission.is_alive():
6497
checkDrift()
6598
displaySensor()

FLLMaster/Missions.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
if __name__ == "__main__":
2-
from DriveLibraries import *
3-
robot = Robot('robot.cfg')
4-
else:
5-
from MenuLib import robot
6-
# Write Mission Programs Here ----------------------
7-
8-
# Mission Names should be prefaced with a##, where ## is two numbers. These
9-
# numbers will not show up on the display, and tell the program what order the
10-
# missions should be in; a00 is first, followed by a01, and so on. It is
11-
# reccomended that spaces are left between the numbers (a00, a05, a10...), to
12-
# allow for future missions.
13-
14-
def a00Star():
15-
# Drives a simple 4-pointed star, with arced sides
16-
robot.ArcTurn(-90, 30, 30)
17-
robot.ArcTurn(-90, 30, -30)
18-
robot.ArcTurn(-90, 30, 30)
19-
robot.ArcTurn(-90, 30, -30)
20-
21-
def a05LineFollow():
22-
# Follows a line for 50 cm, at 50% speed, stopping at end
23-
robot.LineFollow(50, 50, True)
24-
25-
def a10Command_Key():
26-
# Drives in a pattern similar to the Apple command key
27-
# o_o
28-
# | |
29-
# o‾o
30-
robot.DriveAtHeading(0, 50, 30, False)
31-
robot.ArcTurn(270, 10, 30)
32-
robot.DriveAtHeading(270, 50, 30, False)
33-
robot.ArcTurn(270, 10, 30)
34-
robot.DriveAtHeading(270 * 2, 50, 30, False)
35-
robot.ArcTurn(270, 10, 30)
36-
robot.DriveAtHeading(270 * 3, 50, 30, True)
1+
if __name__ == "__main__":
2+
from DriveLibraries import *
3+
robot = Robot('robot.cfg')
4+
else:
5+
from MenuLib import robot
6+
7+
# Mission Names should be prefaced with a##, where ## is two numbers. These
8+
# numbers will not show up on the display, and tell the program what order the
9+
# missions should be in; a00 is first, followed by a01, and so on. It is
10+
# reccomended that spaces are left between the numbers (a00, a05, a10...), to
11+
# allow for future missions.
12+
13+
# Write Mission Programs Here ----------------------
14+
15+
def a00Star():
16+
# Drives a simple 4-pointed star, with arced sides
17+
robot.ArcTurn(-90, 30, 30)
18+
robot.ArcTurn(-90, 30, -30)
19+
robot.ArcTurn(-90, 30, 30)
20+
robot.ArcTurn(-90, 30, -30)
21+
22+
def a05LineFollow():
23+
# Follows a line for 50 cm, at 50% speed, stopping at end
24+
robot.LineFollow(50, 50, True)
25+
26+
def a10Command_Key():
27+
# Drives in a pattern similar to the Apple command key
28+
# o_o
29+
# | |
30+
# o‾o
31+
robot.DriveAtHeading(0, 50, 30, False)
32+
robot.ArcTurn(270, 10, 30)
33+
robot.DriveAtHeading(270, 50, 30, False)
34+
robot.ArcTurn(270, 10, 30)
35+
robot.DriveAtHeading(270 * 2, 50, 30, False)
36+
robot.ArcTurn(270, 10, 30)
37+
robot.DriveAtHeading(270 * 3, 50, 30, True)
3738
robot.GyroTurn(0)

0 commit comments

Comments
 (0)