PID for gps position hold

Hi there i’m facing a big prbolem due to the position hold quadcopter.
i can stabilize the position of quadcopter if my heading is equal to 0 degree.
because in this degree the longitude is parallel to axis Y and the latitude IS paralel to X axis.

so i do the pitch to correct the Y axis (latitude) and the roll to correct the X axis(longitude).

the problem is when my heading is not equal to 0, for example 120 degree. in that angle the quadcopter don’t hold the position it drift to the right or the left.

i want to know id there a math function that componsate the change of the heading angle with longitude and latitude.
please help
thanks

i want to know id there a math function that componsate the change of the heading angle with longitude and latitude.

sin() and cos(). Post your code if you need help using them.

Yes. Sine and Cosine are the functions you need. Multiply the latitude error by Cosine(heading) to adjust Pitch and by Sine(heading) to adjust Roll. Multiply the longitude error by Cosine(heading - 90) to adjust Roll and by Sine(heading - 90) to adjust Pitch.

For example when you If your current heading is North (0) you would multiply latitude error by 1 (Cosine(0)) to adjust Pitch and by 0 (Sine(0)) to adjust Roll. That should cause you to pitch forward (or back) toward the correct latitude. Similarly you would multiply longitude error by 0 (Cosine(-90)) to adjust Pitch and by -1(Sine(-90)) to adjust Roll. That should cause you to roll left or right toward the correct longitude.

You may need to adjust signs depending on whether positive pitch is forward or back and positive roll is left or right.

North (0) you would multiply latitude error by 1 (Cosine(0)) to adjust Pitch and by 0 (Sine(0)) to adjust Roll. That should cause you to pitch forward (or back) toward the correct latitude. Similarly you would multiply longitude error by 0 (Cosine(-90)) to adjust Pitch and by -1(Sine(-90)) to adjust Roll

Thanks but i don't understand how i can correct the latitude and longitude in same time ??

for example

set_latitude = 1.4311 set_longitude = 43.431

error_lat = 1.4355-set_latitude*(PID); error_lon = 43.451-set_longi*(PID);

error_lat*cos(heading)-----> controling the pitch errol_lat*sin(heading)------> controling roll

//

error_lon*cos(heading-90)-----> controling the pitch errol_lon*sin(heading-90)------> controling roll

in that case i correct just the longitude, the latitude correction will be overwriting by the longitude correction. how do i resolve this problem please thanks

jone31: in that case i correct just the longitude, the latitude correction will be overwriting by the longitude correction. how do i resolve this problem please

Add both corrections to the setpoints for Pitch and Roll.

Add both corrections to the setpoints for Pitch and Roll.

i don't understand, could you please write me some code it will be very fine thanks a lot

i don’t understand, could you please write me some code it will be very fine

Would you understand the code, if forum members wrote it for you?

See the “Gigs and Collaborations” section of the forum.

johnwasser i think i undersatnd now, you want to say error_lat*cos(heading)+error_lon*cos(heading-90)--->control the pitch and errol_lat*sin(heading)+errol_lon*sin(heading-90) control the roll is that what you mean ?? :) for the information , i'm not american or british im' sorry for my english ^^ thanks

Here is how to rotate coordinates in the XY plane. Scroll down to “two dimensions”.

XY_rot.gif

thank you, but this equation will not resolve what i post :)

Note that these adjustments are to the SETPOINT of your PID loops. You use the PID OUTPUT directly.

If you post your current sketch maybe someone will be able to provide more specific help.