Nivekk / KOS

Fully programmable autopilot mod for KSP.
Other
80 stars 30 forks source link

identical facing and up+R(x,x,x) don't match up at higher lats when close to the horizon. #260

Open weissel opened 10 years ago

weissel commented 10 years ago

Near KSC:

lock steering to up + R(-70,0,-180).
set dir to up + R(-70,0,-180).
// wait until the craft is stable and well on course
print facing.
R(288.191,304.643,0)
print dir.
R(287.851,304.645,-180)          
// HMMM ... roll doesn't match!  But the rest works ...

just north of KSC

Now go to 45-50° north.

lock steering to up + R(-70,0,-180).
set dir to up + R(-70,0,-180).
// wait until the craft is stable and well on course
print facing.
R(299.347,124.684,0)
print dir.
R(240.655,304.702,-180)
// HMMM ... NOTHING matches up???

At around 45-50° north

(Yeah, I used some unlimited fuel and hack gravity, as I landed dry.)

It DOES work at near vertical, though, it only fails when having a rather shallow angle.

This is causing me grief when trying to find out if my craft (jet engine with tanks --- no proper wings yet, so flying at 20-30° pitch up) is pitched like it should be pitched by comparing facing:pitch with dir:pitch.

JoCRaM commented 10 years ago

From memory you need to use R(p,r,y) * up (or it may be up * R(p,y,r) (fixed formatting)

JoCRaM commented 10 years ago

ksp 2013-11-20 21-25-19-71 yes, it stole my *

firstly... you're moving, so use LOCK dir TO .... so that you get the current value of UP whenever you evaluate it.

you want to use

LOCK dir TO UP * R(-70,0,180).

WAIT UNTIL ABS(dir:PITCH - FACING:PITCH) < 0.5
  AND ABS(dir:YAW- FACING:YAW) < 0.5.

beware of gimble lock - don't know it it's a problem (will only be an issue when pitch nearly straight up or down).

Gimble lock is an issue R(90,90,0) is the same as R(90,0,-90), but doesn't cause a problem as it is normalised out as long as you compare up*dir against facing.

JoCRaM commented 10 years ago

and as a final note @weissel theres the edge case where you're heading due south, so you need to check for yaw > 359.5.

I hope it normalises, otherwise it starts to get messy....

baloan commented 10 years ago

I actually use

wait until abs(sin(fset:pitch) - sin(facing:pitch)) < tolerance and abs(sin(fset:yaw) - sin(facing:yaw)) < tolerance.

to solve issues when yaw or pitch > 360 which I have observed. Normalisation does not work in some cases. Also if fset:pitch is set to 0 and facing:pitch is 359.5 then sin will get you around it nicely.

JoCRaM commented 10 years ago

I had a hunt around and couldn't find anywhere where the normalisation didn't work - could you give an example so I can test my routines @baloan ?

weissel commented 10 years ago

@JoCRaM Yep, multiplication works. Unfortunately, everyone and their dog (official documentation and KOS Wiki, for example) seems to use/advocate up + R(...), not up * R(...) or similar.

JoCRaM commented 10 years ago

Yes, using Eulers, as long as UP is close to R(0,Y,R) adding the angles is pretty much the same as doing it properly - and most stuff people do is either near KSC, or an equatroial orbit, so the little bit of error that creeps in gets cancelled by fudges and control loops.