Hi,
Can you please explain this part of the code ?
esc_1 = throttle - pid_output_pitch + pid_output_roll - pid_output_yaw; //Calculate the pulse for esc 1 (front-right - CCW)
esc_2 = throttle + pid_output_pitch + pid_output_roll + pid_output_yaw; //Calculate the pulse for esc 2 (rear-right - CW)
esc_3 = throttle + pid_output_pitch - pid_output_roll - pid_output_yaw; //Calculate the pulse for esc 3 (rear-left - CCW)
esc_4 = throttle - pid_output_pitch - pid_output_roll + pid_output_yaw; //Calculate the pulse for esc 4 (front-left - CW)
I didnt get my head around with it.
I didnt understand PID implementation also, but for now iam going with pid library
Thats a very nice question and its very easy to answer, Below is a brief of it.
1. Assume motor positions and directions initially
https://i.ytimg.com/vi/WNqojyFICZQ/maxresdefault.jpg I will take image in link as reference
a. motor 1 -- bottom right rotating CW
b. motor 2 -- top right rotating CCW
c. motor 3 -- bottom left rotating CCW
d. motor 4 -- top left rotating CW
2. Now I will go step by step.
a) w.r.t Throttle:
What is the output of all motors with respect to input? It is proportional output irrespective of position. So throttle is positive i.e
added to outputs
Now output is
m4 = +thr
m2 = +thr
m3 = +thr
m1 = +thr
b) w.r.t Pitch:
When you increase the pitch to forward i.e you want your model to move forward. What actually goes?
motors in front(4,2) will slow a bit and back motors(1,3) will speed up a bit. To increase/decrease add/substract pitch input to/from motor.
m4 = +thr -pitch
m2 = +thr -pitch
m3 = +thr +pitch
m1 = +thr +pitch
c) w.r.t Roll:
When you increase the Roll i.e you want to go right what exactly happens?
Motor on right i.e (2,1) will slow a bit and motors left(3,4) will speed up a bit. To do this follow above step. Add/substract from output of motor.
m4 = +thr -pitch +Roll
m2 = +thr -pitch -Roll
m3 = +thr +pitch +Roll
m1 = +thr +pitch -Roll
d) w.r.t yaw:
I hope you have already understood the entire logic and you won't really read this. So I skip this. sorry
This is the very basic and you may have to sometimes reverse the inputs depending on how the value changes for direction of stick movement. This is called stick reversing or something similar.