EasyManua.ls Logo

ADEEPT PiCar-Pro - Camera Stabilization Code

ADEEPT PiCar-Pro
178 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
167
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.
1. from mpu6050 import mpu6050
2. import Adafruit_PCA9685
3. import time
4.
5. sensor = mpu6050(0x68)
6. pwm = Adafruit_PCA9685.PCA9685()
7.
8. servoPort = 2 #The port number of the servo need to be controlled
9. servoPos = 200 #Control the reference position of the servo
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. '''
5. return int(round(23/9*angleInput))
6.
7. while 1:
8. print('steadyProcessing')
9. xyzGet = sensor.get_accel_data() #Get XYZ reading information from the sensor
10.
11. sGet = xyzGet['x']*10 #Get the X-axis angle information from the angle information
12. #sGet = xyzGet['y']*10 #Get the Y-axis angle information from the angle information
13. #sGet = xyzGet['z']*10 #Get the angle information of the Z-axis from the angle information
14. pwm.set_pwm(2, 0, servoPos+pwmGenOut(sGet*P)) #Control the movement of the servo
15.
16. time.sleep(0.05)

Related product manuals