SunFounder picar-x
(continued from previous page)
status = 'stop'
Vilib.camera_start(vflip=False,hflip=False)
Vilib.display(local=True,web=True)
sleep(2) # wait for startup
print(manual)
while True:
print("\rstatus: %s , speed: %s "%(status, speed), end='', flush=True)
# readkey
key = readchar.readkey().lower()
# operation
if key in ('wsadfop'):
# throttle
if key == 'o':
if speed <=90:
speed += 10
elif key == 'p':
if speed >=10:
speed -= 10
if speed == 0:
status = 'stop'
# direction
elif key in ('wsad'):
if speed == 0:
speed = 10
if key == 'w':
# Speed limit when reversing,avoid instantaneous current too large
if status != 'forward' and speed > 60:
speed = 60
status = 'forward'
elif key == 'a':
status = 'turn left'
elif key == 's':
if status != 'backward' and speed > 60: # Speed limit when
˓→reversing
speed = 60
status = 'backward'
elif key == 'd':
status = 'turn right'
# stop
elif key == 'f':
status = 'stop'
# move
move(status, speed)
# take photo
elif key == 't':
take_photo()
# quit
elif key == readchar.key.CTRL_C or key in readchar.key.ESCAPE_SEQUENCES:
print('\nquit ...')
px.stop()
Vilib.camera_close()
break
sleep(0.1)
(continues on next page)
4.10. Video Car 73