erinaco/manual_controll.py

73 lines
1.8 KiB
Python
Raw Normal View History

2017-04-15 02:42:23 +02:00
from time import sleep
import getch
from core import Core as CORE
2017-04-16 01:32:58 +02:00
from autopilot import Autopilot as AUTOPILOT
from autopilot import MoveException,RightMoveException,LeftMoveException,ForwardMoveException
from random import randint
core=CORE();
2017-04-16 01:32:58 +02:00
#Enthaelt die Hilfe
def help():
print("MOTION:")
print("Forward: w");
print("Backward: s");
print("Left: a");
print("Right: d");
print("Stop: Space\n")
print("GENERAL:")
print("Help: h\n");
print("MODE:")
print("Automatisch: q")
print("Halbautomatisch: w")
print("Manuell: e")
def autopilot():
2017-04-16 22:27:42 +02:00
try:
core=AUTOPILOT()
#core.start();
while True:
try:
core.printValues();
if core.moveStatus!=1:
core.forward();
2017-04-16 01:32:58 +02:00
else:
2017-04-16 22:27:42 +02:00
core.statusTest();
except ForwardMoveException:
if randint(0,1):
core.backward();
else:
if randint(0,1):
core.turnLeft();
else:
core.turnRight();
except LeftMoveException:
core.turnLeft();
except RightMoveException:
core.turnRight();
sleep(1);
except KeyboardInterrupt:
print("Verlasse Autopilot...")
#core=CORE();
def doIt(order):
switcher = {
'w': lambda: core.forward(),
's': lambda: core.backward(),
'd': lambda: core.turnRight(),
'a': lambda: core.turnLeft(),
' ': lambda: core.stop(),
'i': lambda: core.printValues(),
2017-04-16 01:32:58 +02:00
'h': lambda: help(),
'q': lambda: autopilot(),
}
2017-04-16 01:32:58 +02:00
func = switcher.get(order, lambda: print("Der gewuenschte Befehl steht nicht zur Verfuegung"))
return func();
2017-04-16 01:32:58 +02:00
print("Herzlich Willkommen im manuellen Controll-Interface!\n")
try:
while True:
input=getch.getch();
print("Erinaco>>{0}".format(input))
doIt(input);
2017-04-16 01:32:58 +02:00
except MoveException:
print("Move Exception...")
except KeyboardInterrupt:
print("Verlasse Erinaco...")
2017-04-16 01:32:58 +02:00
core.__del__();