This tutorial is part of: ชุดอุปกรณ์รถยนต์อัจฉริยะ SunFounder Raspberry Pi Pico Pico 4WD
ไฟล์ที่เกี่ยวข้องกับกลุ่มนี้จะแสดงไว้ด้วยกัน ลิงก์ไปยังวิดีโออื่นๆ อยู่ด้านล่างบทความนี้
Course Lesson 6 of 10: Controlling DC Motors using Raspberry Pi Pico 4WD Smart Car Kit
This project guide is based on Lesson 6 of the Robojax Raspberry Pi Pico Smart Car course. In this session, you will learn how to integrate a servo motor and an ultrasonic sensor to create an intelligent obstacle-avoidance system for your 4WD car. Instead of simply stopping when it detects an object, this project transforms your car into a mini autonomous robot that actively scans its environment, determines the clearest path, and navigates around obstacles.
This isn't just a theoretical exercise; it's a foundational project for building more complex robotics. Here are a few practical applications for this obstacle-avoidance logic:
- Autonomous Exploration Robot: Build a robot that can navigate a room or maze on its own without any remote control.
- Smart Vacuum Cleaner: Use the same logic to create a simple robotic vacuum that can avoid furniture and walls while cleaning a floor.
- Security Patrol Bot: Program the car to patrol a perimeter and use the ultrasonic sensor to detect and navigate around unexpected objects.
- Educational Robotics Platform: Use this as a base to experiment with more advanced pathfinding algorithms and sensor fusion.
The core concept is to use the servo motor to rotate the ultrasonic sensor, acting as a "radar" that scans the area from left to right. By measuring distances at various angles, the car can build a map of its immediate surroundings and make a decision to move forward, turn left, or turn right to find a clear path (in video at 02:47).
Hardware/Components
This project is built around the SunFounder Raspberry Pi Pico 4WD Smart Car Kit. The key components used in this lesson are:
- Raspberry Pi Pico board
- 4WD Smart Car chassis with motors
- Motor driver board (included in the kit)
- Ultrasonic sensor (HC-SR04 type)
- Servo motor
- Battery pack
Wiring Guide
The video mentions that the kit comes with full documentation, step-by-step instructions, and wiring diagrams. The wiring for the servo and ultrasonic sensor is typically connected to the motor driver board, which consolidates the connections for the Pico.
Please refer to the diagram below for the specific pin connections for your kit.
Code Explanation
The video focuses on the logic within the obstacle_avoid.py file. While the full code is available with the kit, this lesson highlights the user-configurable parameters that control the car's behavior. These are the variables you will likely want to adjust to tune your robot's performance.
At the top of the main program, you will find the key settings that define the car's behavior (in video at 13:07):
# Obstacle avoidance settings
RADAR_REFERENCE = 20 # Distance in cm to consider an obstacle
STEP_ANGLE = 10 # Degrees the servo moves for each scan step
FORWARD_SPEED = 30 # Motor speed when moving forward
TURN_SPEED = 50 # Motor speed when turning
FORWARD_SCAN_ANGLE = 50 # Degrees for a quick forward scan
- RADAR_REFERENCE: This is the most crucial setting. It defines the minimum safe distance in centimeters. If the ultrasonic sensor detects an object closer than this value, the car considers it a "danger" and initiates the avoidance routine (in video at 22:03).
- STEP_ANGLE: This determines the resolution of the radar scan. A smaller value (e.g., 10 degrees) makes the scan more precise but slower. A larger value makes it faster but less detailed.
- FORWARD_SPEED & TURN_SPEED: These are the PWM values (0-100) that control the power to the motors. You can adjust these to change how fast the car drives forward and how quickly it turns (in video at 13:33).
- FORWARD_SCAN_ANGLE: After an obstacle is avoided, the car performs a quick scan to ensure the path ahead is clear. This variable sets the angle for that scan. A value of 50 means it scans from -25 to +25 degrees relative to the center (in video at 13:40).
Live Project/Demonstration
In the video, the instructor demonstrates the project in stages. First, he runs a simple test to show how the ultrasonic sensor measures distance and prints the values to the shell, confirming that "0" represents an obstacle and "1" represents a clear path (in video at 03:48).
He then explains the decision-making flowchart, which is the brain of the operation. The car uses a function called get_direction() to analyze the radar data. This function splits the scan data into segments of open space and identifies the widest one. Based on where this wide path is located (left, center, or right), the car decides which way to turn (in video at 11:19).
Finally, the instructor sets up a maze of obstacles and demonstrates the car navigating through it. You can see the car scan left and right, reverse if it gets stuck, and ultimately find a path to drive through the obstacles without any manual control (in video at 22:53).
Chapters
- [00:00] Introduction to Obstacle Avoidance with the Pico Car
- [01:31] Kit Features and Documentation Overview
- [02:47] Demonstrating the Obstacle Avoidance Feature
- [03:48] Testing the Ultrasonic Sensor and Distance Measurement
- [07:45] Explaining the Obstacle Avoidance Algorithm and Flowchart
- [12:49] Analyzing the Main Obstacle Avoidance Code
- [15:50] Live Code Demonstration and Data Interpretation
- [18:11] Deep Dive into the Get Direction and Turning Logic
- [22:53] Final Live Test with a Maze of Obstacles
This tutorial is part of: ชุดอุปกรณ์รถยนต์อัจฉริยะ SunFounder Raspberry Pi Pico Pico 4WD
- Course Lesson 1 of 10: Raspberry Pi Pico 4WD Smart Car Kit from SunFounder by Robojax
- Course Lesson 2 of 10: Basic Python to drive Raspberry Pi Pico 4WD Smart Car Kit
- Course Lesson 3 of 10: Assembling Raspberry Pi Pico 4WD Smart Car Kit from SunFounder by Robojax
- Course Lesson 4 of 10: Raspberry Pi Pico Expansion board for 4WD Smart Car Kit
- Course Lesson 5 of 10: Controlling RGB LED WS2812B Using Raspberry Pi Pico
- Lesson 7 of 10: Line Tracking, Cliff Detection Calibrate Greyscale Sensor Raspberry Pi Pico Car
- Course Lesson 8 of 10: Raspberry Pi Pico Smart Car – Lesson 8: Servo Motor and Object Following
- Course Lesson 9 of 10: Obstacle Avoidance using Raspberry Pi Pico 4WD Smart Car
- Course Lesson 10 of 10: Controlling Raspberry Pi Pico 4WD Smart Car Kit with mobile App
Common Course Links
- Purchase SunFounder Pico 4WD Smart Car Kit from AliExpress
- Purchase SunFounder Pico 4WD Smart Car Kit from eBay
- Amazon Canada: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon France: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon Germany: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon Italy: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon Japan: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon Spain: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon UK: Purchase Pico 4WD Smart Car Kit by SunFounder
- Amazon USA: Purchase Pico 4WD Smart Car Kit buy SunFounder
- Purchase Pico 4WD Smart Car Kit from SunFounder.com
- SunFounder Pico-4wd Car Kit Documentation
- Video Play List of 10 lesson on SunFounder Pico 4WD Smart Car Kit
แหล่งข้อมูลและเอกสารอ้างอิง
ยังไม่มีทรัพยากรเลย
ไฟล์📁
ไม่มีไฟล์ที่พร้อมใช้งาน