-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (48 loc) · 1.7 KB
/
main.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
import pygame
import argparse
import sys
from robot import Robot
from line import Line
from screen_logger import ScreenLogger
from manual_command_publisher import ManualCommandPublisher
import logging
def main(manual=False):
# for now we will log everything including debug to console
logging.basicConfig(level=logging.DEBUG)
pygame.init()
size = width, height = 1200, 800
screen = pygame.display.set_mode(size)
background = pygame.Surface(screen.get_size())
BACKGROUND_COLOR = (64, 64,100)
background.fill(BACKGROUND_COLOR)
if manual:
logging.info("Using manual command publisher")
manual_command_publisher = ManualCommandPublisher()
# prepare the game objects
screenLogger = ScreenLogger()
robot = Robot((600, 120), screenLogger, BACKGROUND_COLOR)
line = Line((800, 400), BACKGROUND_COLOR, (0,100,0))
allSprites = pygame.sprite.Group(line, robot.sprites())
clock = pygame.time.Clock()
while True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if manual:
manual_command_publisher.process_event(event)
# draw the scene
screen.blit(background, (0,0))
robot.sense(line)
screenLogger.refresh_logs()
screenLogger.log("Line Following Robot")
allSprites.update()
allSprites.draw(screen)
robot.process_environment(line)
screenLogger.draw(screen)
pygame.display.flip()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--manual", action="store_true",
help="set manual flag if you want to manually control the robot, otherwise, custom_controller will be used")
main(parser.parse_args().manual)