Commit ba10a877 authored by Benoit ZERR's avatar Benoit ZERR
Browse files

porting on windows 10

parent fdcd5744
class GetKey:
def __init__(self):
import tty, sys, termios # import termios now or else you'll get the Unix version on the Mac
import platform
self.system = "Linux"
if platform.system() == "Windows":
self.system = "Windows"
if self.system == "Windows":
import msvcrt # no termios neither tty on Windows10 , use msvcrt instead
elif self.system == "Linux":
import tty, sys, termios # import termios and sys not tesetd on MacOs
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
if self.system == "Windows":
import msvcrt
ch=chr(0)
if msvcrt.kbhit():
ch = msvcrt.getch()
if self.system == "Linux":
import tty, sys, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
if __name__ == "__main__":
import time
getkey = GetKey()
while True:
......@@ -21,7 +34,8 @@ if __name__ == "__main__":
ich = ord(ch)
if ich>=32:
print (ch,ich,"%2.2X"%(ich))
else:
elif ich>0:
print (ich,"%2.2X"%(ich))
if ich == 27 or ich==3: # 3 = CTRL+C
break
time.sleep(0.05)
......@@ -34,39 +34,44 @@ if __name__ == "__main__":
while True:
ch = getkey()
ich = ord(ch)
if ich==27 or ich==3:
break
if ch=="g":
goforward()
elif ch=="b":
gobackward()
elif ch=="f":
turnleft()
elif ch=="h":
turnright()
elif ch=="1":
ispd=0
elif ch=="2":
ispd=1
elif ch=="3":
ispd=2
elif ch=="4":
idur=0
elif ch=="5":
idur=1
elif ch=="6":
idur=2
elif ch=="7":
idur=3
print ("speed go",tspdgo[ispd],"speed turn",tspdturn[ispd],"duration",tdur[idur])
print ("cardinal sonars")
print (mybot.get_cardinal_sonars())
print ("diagonal sonars")
print (mybot.get_diagonal_sonars())
print ("front odometers")
print (mybot.get_front_odos())
print ("rear odometers")
print (mybot.get_rear_odos())
if ch != 0:
print (ch,ich,ch==b'b')
if ich==27 or ich==3:
break
if ch=="g":
goforward()
elif ch==b"b":
gobackward()
elif ch=="f":
turnleft()
elif ch=="h":
turnright()
elif ch=="1":
ispd=0
elif ch=="2":
ispd=1
elif ch=="3":
ispd=2
elif ch=="4":
idur=0
elif ch=="5":
idur=1
elif ch=="6":
idur=2
elif ch=="7":
idur=3
"""
print ("speed go",tspdgo[ispd],"speed turn",tspdturn[ispd],"duration",tdur[idur])
print ("cardinal sonars")
print (mybot.get_cardinal_sonars())
print ("diagonal sonars")
print (mybot.get_diagonal_sonars())
print ("front odometers")
print (mybot.get_front_odos())
print ("rear odometers")
print (mybot.get_rear_odos())
"""
time.sleep(0.05)
mybot.end() # clean end of the robot mission
......@@ -9,7 +9,7 @@ tSimVar={"vSimTime" : 0.0,
"vMagX" : 0.0,
"vMagY" : 0.0,
"vMagZ" : 0.0,
"vDoLog" : 1.0,
"vDoLog" : 0.0, # vDoLog = 0.0 because of sometimes permission error occurs when creating log file in Windows
"vCmdSpeedLeft" : 0.0,
"vCmdSpeedRight" : 0.0,
"vCmdSpeedNew" : 0.0,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment