Tutorial
Table Of Contents
- 1. Premise
- 2. Raspberry Pi System Installation and Developmen
- 3 Log In to The Raspberry Pi and Install The App
- 4 Assembly and Precautions
- 5 Controlling Robot via WEB App
- 6 Common Problems and Solutions(Q&A)
- 7 Set The Program to Start Automatically
- 8 Remote Operation of Raspberry Pi Via MobaXterm
- 9 How to Control WS2812 RGB LED
- 10 How to Control The Servo
- 11 How to Control DC Motor
- 12 Ultrasonic Module
- 13 Line Tracking
- 14 Make A Police Light or Breathing Light
- 15 Real-Time Video Transmission
- 16 Automatic Obstacle Avoidance
- 17 Why OpenCV Uses Multi-threading to Process Vide
- 18 OpenCV Learn to Use OpenCV
- 19 Using OpenCV to Realize Color Recognition and T
- 20 Machine Line Tracking Based on OpenCV
- 21 Create A WiFi Hotspot on The Raspberry Pi
- 22 Install GUI Dependent Item under Window
- 23 How to Use GUI
- 24 Control The WS2812 LED via GUI
- 25 Real-time Video Transmission Based on OpenCV
- 26 Use OpenCV to Process Video Frames on The PC
- 27 Enable UART
- 28 Control Your AWR with An Android Device
- Conclusion
85
16 Automatic Obstacle Avoidance
●The ultrasonic module of this product can only move up and down with the camera, and the left and right
movement can only rotate with the body of the body, and can not move left and right relative to the body, so the
obstacle avoidance function of this robot is relatively simple, as long as there is an obstacle in front Turn left
and retreat if the obstacle is too close, and move forward if the obstacle is far away or there is no obstacle.
●The automatic obstacle avoidance function is based on the ultrasonic ranging module, so before writing
your project, you must first put ultra.py RPIservo.py and copy move.py to the same file directory as your
project, and then use the following code to use the automatic obstacle avoidance function.
import ultra
import move
import time
import Adafruit_PCA9685
import RPIservo
# Get the initial data of pwm
def num_import_int(initial):
global r
with open(thisPath+"/RPIservo.py") as f:
for line in f.readlines():
if(line.find(initial) == 0):
r=line
begin=len(list(initial))
snum=r[begin:]
n=int(snum)
return n
scGear = RPIservo.ServoCtrl() # servo control
scanNum = 3 # The car will scan the three parts in front of it, namely left, middle and right, that is, 1
represents left, 2 represents middle, and 3 represents right
scanPos = 1 # The next position to be scanned by the car, the value can be 1, 2, and 3 corresponding to left,
middle and right
scanDir = 1 # The direction of the car scanning, 1 is the leftmost, -1 is the rightmost
scanList = [] # Record the distance of obstacles in three directions that are scanned
scanServo = 1 # Pan-tit servo number
scanRange = 100 # The range of the angle scanned by servo
rangeKeep = 0.7 # Threshold, if it is less than it, turns; if it is greater than it, go back