MagneticHeading bulma - 41linea41 - 30-08-2021
Merhaba
Manyetik Kuzeyi bulmak istiyorum. Orientation sensörde ilgili özellikleriden değer dönmüyor ."NAN" sonucunu alıyorum.
OrientationSensor1.Sensor.MagHeading
OrientationSensor1.Sensor.TrueHeading
Manyetik kuzey ile ilgili google armasından da sadece Sensor fusion github projesine ulaşilabildim. Manyetik Kuzeyi bulma çalışıyorum. Bu konu da bir örnek yada başlama yeri ne tavsiye edersiniz.
İyi Çalışmalar.
Cvp: MagneticHeading bulma - 41linea41 - 02-09-2021
(30-08-2021, Saat: 18:22)41linea41 Adlı Kullanıcıdan Alıntı: Merhaba
Manyetik Kuzeyi bulmak istiyorum. Orientation sensörde ilgili özellikleriden değer dönmüyor ."NAN" sonucunu alıyorum.
OrientationSensor1.Sensor.MagHeading
OrientationSensor1.Sensor.TrueHeading
Manyetik kuzey ile ilgili google armasından da sadece Sensor fusion github projesine ulaşilabildim. Manyetik Kuzeyi bulma çalışıyorum. Bu konu da bir örnek yada başlama yeri ne tavsiye edersiniz.
İyi Çalışmalar.
Yukarıdaki github projesinin sahibi stackoverflow da soruya cevap olarak hesaplamayı vermiş ama bu hesaplamada baz yönlerde 40-45 derece bazı yönlerde ise çok daha fazla sapma var.
// this function x,y,z axis for the phone in vertical orientation (portrait)
function calcTiltCompensatedMagneticHeading(const {acel}aGx,aGy,aGz,{mag} aMx,aMy,aMz:double ):double; //return heading in degrees
var Phi,Theta,cosPhi,sinPhi,Gz2,By2,Bz2,Bx3 ouble;
begin
Result := NaN; //=invalid
// https://www.st.com/content/ccc/resource/technical/document/design_tip/group0/56/9a/e4/04/4b/6c/44/ef/DM00269987/files/DM00269987.pdf/jcr:content/translations/en.DM00269987.pdf
Phi := ArcTan2(aGy,aGz); //calc Roll (Phi)
cosPhi := Cos(Phi); //memoise phi trigs
sinPhi := Sin(Phi);
Gz2 := aGy*sinPhi+aGz*cosPhi;
if (Gz2<>0) then
begin
Theta := Arctan(-aGx/Gz2); // Theta = Pitch
By2 := aMz * sinPhi - aMy * cosPhi;
Bz2 := aMy * sinPhi + aMz * cosPhi;
Bx3 := aMx * Cos(Theta) + Bz2 * Sin(Theta);
Result := ArcTan2(By2,Bx3)*180/Pi-90; //convert to degrees and then add 90 for North based heading (Psi)
end;
end;
//usage
{$IFDEF ANDROID}
mx := MagSensor1.HeadingX; //in mTeslas
my := MagSensor1.HeadingY;
mz := MagSensor1.HeadingZ;
aGx := MotionSensor1.Sensor.AccelerationX; //get acceleration sensor
aGy := MotionSensor1.Sensor.AccelerationY;
aGz := MotionSensor1.Sensor.AccelerationZ;
aMagHeading:=0;
if IsLandscapeMode then //landscape phone orientation
begin
aMagHeading := calcTiltCompensatedMagneticHeading({acel}aGy,-aGx,aGz,{mag} my,-mx,mz); //rotated 90 in z axis
end
else begin //portrait orientation
aMagHeading := calcTiltCompensatedMagneticHeading({acel}aGx,aGy,aGz,{mag} mx,my,mz); // normal portrait orientation
end;
{$ENDIF ANDROID}
|