EasyManua.ls Logo

SunFounder PiCar-X Kit - Let Picar-X Move

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
4.3 1. Let PiCar-X Move
This is the first project, let’s test the basic movement of Picar-X.
Run the Code
cd ~/picar-x/example
sudo python3 1.move.py
After running the code, PiCar-X will move forward, turn in an S-shape, stop and shake its head.
Code
Note: You can Modify/Reset/Copy/Run/Stop the code below. But before that, you need to go to source code path
like picar-x/example. After modifying the code, you can run it directly to see the effect.
from picarx import Picarx
import time
if __name__ == "__main__":
try:
px = Picarx()
px.forward(30)
time.sleep(0.5)
for angle in range(0,35):
px.set_dir_servo_angle(angle)
time.sleep(0.01)
for angle in range(35,-35,-1):
px.set_dir_servo_angle(angle)
time.sleep(0.01)
for angle in range(-35,0):
px.set_dir_servo_angle(angle)
time.sleep(0.01)
px.forward(0)
time.sleep(1)
for angle in range(0,35):
px.set_camera_servo1_angle(angle)
time.sleep(0.01)
for angle in range(35,-35,-1):
px.set_camera_servo1_angle(angle)
time.sleep(0.01)
for angle in range(-35,0):
px.set_camera_servo1_angle(angle)
time.sleep(0.01)
for angle in range(0,35):
px.set_camera_servo2_angle(angle)
time.sleep(0.01)
for angle in range(35,-35,-1):
px.set_camera_servo2_angle(angle)
time.sleep(0.01)
(continues on next page)
48 Chapter 4. Play with Python

Table of Contents

Related product manuals