ADEEPT PiCar-Pro Manual page 170

Table of Contents

Advertisement

3. Place the car on the prepared patrol track.
4. Click "STEADY CAMERA", PiCarPro has the camera stabilization function.
5. When you want to terminate the camera stabilization function, you can click
"STEADY CAMERA" again.
13.2.2 Main code program
For the complete code, please refer to the file steady.py.
Import dependencies and initialize.
from
import
1.
mpu6050
2.
import
Adafruit_PCA9685
3.
import
time
4.
5.
sensor = mpu6050(0x68)
6.
pwm = Adafruit_PCA9685.PCA9685()
7.
8.
servoPort = 2
9.
servoPos = 200
10.
P = 1
#PID P value setting, proportional control parameter, the higher the faster
Main logic code
1.
def
pwmGenOut(angleInput):
2.
'''''
3.
Convert the angle to PWM
4.
'''
return
5.
int(round(23/9*angleInput))
6.
while
7.
1:
8.
print('steadyProcessing')
9.
xyzGet = sensor.get_accel_data()
10.
11.
sGet = xyzGet['x']*10
12.
#sGet = xyzGet['y']*10
13.
#sGet = xyzGet['z']*10
14.
pwm.set_pwm(2, 0, servoPos+pwmGenOut(sGet*P))
15.
16.
time.sleep(0.05)
mpu6050
#The port number of the servo need to be controlled
#Control the reference position of the servo
#Get XYZ reading information from the sensor
#Get the X-axis angle information from the angle information
#Get the Y-axis angle information from the angle information
#Get the angle information of the Z-axis from the angle information
#Control the movement of the servo
167

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?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF