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
86
# Initialize servo angle
pwm = Adafruit_PCA9685.PCA9685()
pwm.set_pwm_freq(50)
pwm0_direction = 1
pwm0_init = num_import_int('init_pwm0 = ')
pwm0_max = 520
pwm0_min = 100
pwm0_pos = pwm0_init
pwm1_direction = 1
pwm1_init = num_import_int('init_pwm1 = ')
pwm1_max = 520
pwm1_min = 100
pwm1_pos = pwm1_init
pwm2_direction = 1
pwm2_init = num_import_int('init_pwm2 = ')
pwm2_max = 520
pwm2_min = 100
pwm2_pos = pwm2_init
while True:
# The pan-tit servo rotates to the left, middle and right directions and uses ultrasonic to scan and record the distance
of obstacles
if scanPos == 1:
pwm.set_pwm(scanServo, 0, pwm1_init + scanRange)
time.sleep(0.3)
scanList[0] = ultra.checkdist()
elif scanPos == 2:
pwm.set_pwm(scanServo, 0, pwm1_init)
time.sleep(0.3)
scanList[1] = ultra.checkdist()
elif scanPos == 3:
pwm.set_pwm(scanServo, 0, pwm1_init - scanRange)
time.sleep(0.3)
scanList[2] = ultra.checkdist()
scanPos += scanDir
# If the scanning angle is not within the set range
if scanPos > scanNum or scanPos < 1: