EasyManua.ls Logo

SunFounder PiCar-X Kit - Page 86

Default Icon
181 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder PiCar-X Kit
(continued from previous page)
px.backward(speed)
elif operate == 'turn left':
px.set_dir_servo_angle(-30)
px.forward(speed)
elif operate == 'turn right':
px.set_dir_servo_angle(30)
px.forward(speed)
def main():
speed = 0
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
(continues on next page)
82 Chapter 4. Play with Python

Table of Contents

Related product manuals