EasyManua.ls Logo

SunFounder PiCar-X Kit - Page 56

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 = Picarx()
show_info()
while True:
key = readchar.readkey()
key = key.lower()
if key in('wsadikjl'):
if 'w' == key:
px.set_dir_servo_angle(0)
px.forward(80)
elif 's' == key:
px.set_dir_servo_angle(0)
px.backward(80)
elif 'a' == key:
px.set_dir_servo_angle(-35)
px.forward(80)
elif 'd' == key:
px.set_dir_servo_angle(35)
px.forward(80)
elif 'i' == key:
tilt_angle+=5
if tilt_angle>35:
tilt_angle=35
elif 'k' == key:
tilt_angle-=5
if tilt_angle<-35:
tilt_angle=-35
elif 'l' == key:
pan_angle+=5
if pan_angle>35:
pan_angle=35
elif 'j' == key:
pan_angle-=5
if pan_angle<-35:
pan_angle=-35
px.set_cam_tilt_angle(tilt_angle)
px.set_cam_pan_angle(pan_angle)
show_info()
sleep(0.5)
px.forward(0)
elif key == readchar.key.CTRL_C:
print("\n Quit")
break
finally:
px.set_cam_tilt_angle(0)
px.set_cam_pan_angle(0)
px.set_dir_servo_angle(0)
px.stop()
sleep(.2)
How it works?
52 Chapter 4. Play with Python

Table of Contents

Related product manuals