Panel Cookies
yt_link
insta_link
fb_link
twitter_link

Servo gimbal
page 2/2


Servo based gimbal project

Help me by sharing this post



PART 2 - The code

The code is not that complicated. This is how it works. The gimbal moves, the IMU detects the angle change and it changes the PID values. The PID is used to fast react at the angle change. The PID will change the PWM width of the signals connected to the motors in order to keep the same angle. Usually, gimbals have a joystick to change the desired angle. In this case the desired angle will be always 0 till future versions.

servo gimbal Arduino based homemade


Downlaod full code:







	/*We know taht the min value of PWM signal is -90 (usingservo.write) and the max is 90. So that
    tells us that the PID value can/s oscilate more than -90 and 90 so we constrain those values below*/
    if(roll_PID < -90){roll_PID = -90;}
    if(roll_PID > 90) {roll_PID = 90; }
    if(pitch_PID < -90){pitch_PID = -90;}
    if(pitch_PID > 90) {pitch_PID = 90;}

I map the values to a range between -90 and 90 degrees. But you could change that value. Also, my gimbal had a maximum of -/+20 degrees for thr X axis and -/+50 degrees for the y axis. Then we write these values using the analogWrite() function and control the servos.









Go back ←

Help me by sharing this post








Affiliate Disclosure

ADVERTISERS



PCBWAY PCB service





Curso Arduino Online nivel bajo