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
87
# Change the scanned direction
if scanDir == 1: scanDir = -1
elif scanDir == -1: scanDir = 1
# Restore scanned location
scanPos += scanDir*2
print(scanList)
# If the distance of the nearest obstacle in front is less than the threshold
if min(scanList) < rangeKeep:
# If the closest obstacle is on the left
if scanList.index(min(scanList)) == 0:
# Then, turn right
scGear.moveAngle(2, -30)
# If the closest obstacle is right ahead
elif scanList.index(min(scanList)) == 1:
# See the value on the left and right to determine which is larger
if scanList[0] < scanList[2]:
# Full rudder to the right and move
scGear.moveAngle(2, -45)
else:
# Otherwise, full rudder to the left and move
scGear.moveAngle(2, 45)
# If the closest obstacle is on the right
elif scanList.index(min(scanList)) == 2:
# Then, turn left
scGear.moveAngle(2, 30)
if max(scanList) < rangeKeep or min(scanList) < rangeKeep/3:
move.motor_lef(1, 1, 80)
move.motor_right(1, 1, 80)
# If the distance of the nearest obstacle in front is greater than the threshold, the car moves backward
else:
move.motor_left(1, 0, 80)
move.motor_right(1, 0, 80)