EasyManua.ls Logo

SunFounder PiCar-X Kit - Page 85

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
code
#!/usr/bin/env python3
from robot_hat.utils import reset_mcu
from picarx import Picarx
from vilib import Vilib
from time import sleep, time, strftime, localtime
import readchar
import os
user = os.getlogin()
user_home = os.path.expanduser(f'~{user}')
reset_mcu()
sleep(0.2)
manual = '''
Press key to call the function(non-case sensitive):
O: speed up
P: speed down
W: forward
S: backward
A: turn left
D: turn right
F: stop
T: take photo
Ctrl+C: quit
'''
px = Picarx()
def take_photo():
_time = strftime('%Y-%m-%d-%H-%M-%S',localtime(time()))
name = 'photo_%s'%_time
path = f"{user_home}/Pictures/picar-x/"
Vilib.take_photo(name, path)
print('\nphoto save as %s%s.jpg'%(path,name))
def move(operate:str, speed):
if operate == 'stop':
px.stop()
else:
if operate == 'forward':
px.set_dir_servo_angle(0)
px.forward(speed)
elif operate == 'backward':
px.set_dir_servo_angle(0)
(continues on next page)
4.13. 11. Video Car 81

Table of Contents

Related product manuals