erinaco/manual_controll.py

77 lines
2.0 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:
2017-04-16 23:44:12 +02:00
autopilot=AUTOPILOT()
while True:
try:
try:
autopilot.setSensorValues();
autopilot.printValues();
print("Richtung: {0}".format(autopilot.moveStatus));
if autopilot.moveStatus!=1:
autopilot.forward();
2017-04-16 22:27:42 +02:00
else:
2017-04-16 23:44:12 +02:00
autopilot.statusTest();
except ForwardMoveException:
if randint(0,1):
autopilot.backward();
else:
if randint(0,1):
autopilot.turnLeft();
else:
autopilot.turnRight();
except LeftMoveException:
core.turnLeft();
except RightMoveException:
core.turnRight();
except MoveException:
autopilot.stop();
sleep(0.5);
2017-04-16 22:27:42 +02:00
except KeyboardInterrupt:
print("Verlasse Autopilot...")
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-17 21:35:56 +02:00
'x': lambda: core.turnDegree(int(input("Grad:"))),
'w': lambda: core.runCm(int(input("cm:"))),
}
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:
2017-04-16 23:44:12 +02:00
core.setSensorValues()
2017-04-17 21:35:56 +02:00
modus=getch.getch();
print("Erinaco>>{0}".format(modus))
doIt(modus);
except KeyboardInterrupt:
print("Verlasse Erinaco...")
2017-04-16 01:32:58 +02:00
core.__del__();