EasyManua.ls Logo

SunFounder PiCar-X Kit - Cliff Detection

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.forward(px_power)
elif gm_state == 'right':
px.set_dir_servo_angle(-offset)
px.forward(px_power)
else:
outHandle()
Safety and Cleanup:
The try...finally block ensures the car stops when the script is interrupted or finished.
finally:
px.stop()
print("stop and exit")
sleep(0.1)
In summary, the script uses grayscale sensors to navigate the Picarx robot car. It continuously reads the sensor data
to determine the direction and adjusts the car’s movement and steering accordingly. The outHandle function provides
additional logic for situations where the car needs to adjust its path significantly.
Note: Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook!
Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
Ready to explore and create with us? Click [] and join today!
4.8 6. Cliff Detection
Let us give PiCar-X a little self-protection awareness and let it learn to use its own grayscale module to avoid rushing
down the cliff.
In this example, the car will be dormant. If you push it to a cliff, it will be awakened urgently, then back up, and say
“danger”.
Run the Code
cd ~/picar-x/example
sudo python3 6.cliff_detection.py
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.
64 Chapter 4. Play with Python

Table of Contents

Related product manuals