ADEEPT PiCar-Pro Manual page 167

Table of Contents

Advertisement

9.
#Servo pin. Set as the pin of the servo on your product that can control the left
and right rotation of the ultrasonic module.
10.
servoPin = 1
11.
12.
GPIO.setmode(GPIO.BCM)
13.
GPIO.setup(UPin1, GPIO.OUT,initial=GPIO.LOW)
14.
GPIO.setup(Upin2, GPIO.IN)
15.
16.
pwm = Adafruit_PCA9685.PCA9685()
17.
pwm.set_pwm_freq(50)
18.
19.
pwm0_init = 300
20.
pwm0_max
= 450
21.
pwm0_min
= 150
22.
pwm0_pos
= pwm0_init
Define scan function.
1.
checkdist():
def
2.
''' Refer to the basic module to control ultra.Py '''
3.
4.
radarScan():
def
5.
pwm0_pos
global
6.
scan_speed = 3
7.
8.
# Move the servo to the maximum angle
9.
pwm0_pos = pwm0_max
10.
pwm.set_pwm(servoPin, 0, pwm0_pos)
11.
time.sleep(0.5)
12.
13.
# Rotate the servo and continuously measure the distance during the period
until it reaches the minimum angle.
14.
print(str(checkdist()), 'm')
15.
pwm0_pos>pwm0_min:
while
16.
pwm0_pos-=scan_speed
17.
pwm.set_pwm(servoPin, 0, pwm0_pos)
18.
print(str(checkdist()), 'm')
19.
20.
# Reply
21.
pwm.set_pwm(servoPin, 0, pwm0_init)
# Set the maximum scanning angle
# Set the minimum scanning angle
# Main function of ultrasonic scanning function
# Scanning speed
164

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the PiCar-Pro and is the answer not in the manual?

Table of Contents

Save PDF