Jump to content
The simFlight Network Forums

Recommended Posts

Posted

This topic has been discussed on this forum but I have difficulty writing a heading to FS. (First converting my Magnetic heading to true.)

My code that works 100% in converting the heading is as follows:

(Where hdg and magv were read from FS, as heading and magnetic variation respectively.)

magv = Round((magv * 360#) / 65536#, 1)
magv = 360 - magv
hdg = Round(((hdg * 360#) / (65536# * 65536#)), 1)
hdg = hdg + magv
If hdg < 0 Then
   hdg = 360 + hdg
ElseIf hdg = 0 Then
   hdg = 360
ElseIf hdg > 360 Then
   hdg = hdg - 360
End If

In Writng the heading I do as follows:

Dim FS_Head As Long

magv = (magv * 360#) / 65536#
magv = 360 - magv
FS_Head = txtHead.Text - magv
FS_Head = (FS_Head * 65536# * 65536#) / 360#
Call FSUIPC_Write(&H580, 4, VarPtr(FS_Head), dwResult)      
Call FSUIPC_Process(dwResult)

Long is 4 Byte integer in VB.

txthead is a text box with my magnetic heading I want.

My problem comes in at converting the magnetic to true.

Please help

Posted
This topic has been discussed on this forum but I have difficulty writing a heading to FS. (First converting my Magnetic heading to true.)

You sent two nearly identical versions of this. I've deleted the earlier one.

I don't understand what you are trying to do the "360-magv" in each case? All you should really do, in all cases, is "normalise" the results you get: Headings have a range of 0-359, MagVars a range of -180 to +179. So you just need to add or subtract 360 untl they are in the correrct range.

In fact, unless you need the separate values, you don't need to do it separately at all. It all simplifies out quite well. Just add the two (when converting MAG to TRUE) or subtract MagVar from Heading (TRUE to MAG) no matter whether either are currently in the correct range, THEN normalise the result by adding or subtracting 360 till in range.

I'm afraid that you are making too much heavy work of something pretty simple. But I cannot show you correct VB code (or whatever it is your are using, which is not C).

Regards

Pete

Posted

Pete

Still no luck. I have tried it a thousand different ways.

In fact, unless you need the separate values, you don't need to do it separately at all. It all simplifies out quite well. Just add the two (when converting MAG to TRUE) or subtract MagVar from Heading (TRUE to MAG) no matter whether either are currently in the correct range, THEN normalise the result by adding or subtracting 360 till in range

This I got thanks Pete. Works fine when reading from FS BUT . . .

If you have a magnetic heading of say 100deg and a magn variation of say 20deg, how would you Write it to 0580. Code in C will be fine. The mathematics will be the same.

Posted
Works fine when reading from FS BUT . . .

What's the difference between reading and writing. Can't you simply reverse the computation?

If you have a magnetic heading of say 100deg and a magn variation of say 20deg, how would you Write it to 0580.

MagVar of +20, not -20 I assume you mean? There's 40 degrees difference!

Why bother with a programming language to show simple arithmetic?

True heading is 100 + 20 = 120 (if you meand -20 Mag Var, then it would be 100 - 20 = 80).

Then just do the conversion to FS units:

120 x 65536 x 65536 / 360 = 1431655765

Write 1431655765 to offset 0580. That's it. A doddle, eh? ;-)

Why don't you play with FSInterrogate a bit, get the feel of all this. It strikes me that you haven't got the hang of it at all at present and you are making very heavy weather of something as simple as A B C.

Regards,

Pete

Posted

Pete

You are clearly misunderstanding me unfortunately. The writing and reading to and from offsets is, as you put it, a doodle.

The only problem I have and persistently plagues me is that the true heading I am writing moves my aircraft incorrectly. The coordinates and altitudes are fine and I only read the magnetic variation after the plane is moved. Ill just play with it a bit more.

MagVar of +20, not -20 I assume you mean? There's 40 degrees difference!

Why bother with a programming language to show simple arithmetic?

Thats why I typed 20 and not -20.

Thanks for the interesting way you answer my questions.

Regards

Posted

You are clearly misunderstanding me unfortunately.

In that case it would be nice if you could explain this in more detail, don't you think?

The only problem I have and persistently plagues me is that the true heading I am writing moves my aircraft incorrectly. The coordinates and altitudes are fine and I only read the magnetic variation after the plane is moved.

ErI'm not understanding that AT ALL! You are trying to orient the heading of the aircraft, andit does what? If you only read the Mag Var AFTER it has been moved how on Earth can you correct a Magnetic heading to a True heading to set the desired heading correctly?

Tell me what you want to do, what you write and what you expect.

Have you considered using FSInterrogate to experiment with all this before embarking upon something you don't fully understand? I'm sure it would help!

Thanks for the interesting way you answer my questions.

Is that meant as sarcasm? If so, please explain yourself. I have tried very hard to explain something which should be obvious. If you are hiding half of the information (like the fact you just stated, that don't even bother to read the Mag Var till too late), you can hardly expect me to provide the answers you desire, now, can you?

Pete

Posted
In that case it would be nice if you could explain this in more detail, don't you think?

For Sure.

Let's start all over, Pete. I hope for the last time.

All I do is the following:

1. Pause FSIM.

2. Write the Position of the plane (Lat, Lon, Altitude, Pitch, Bank angle) to FSUIPC. (The plane now moves to its new location.)

3. Read Magnetic Variation. (magv)

4. Compute True heading by adding the Magnetic Heading I want, to the Magnetic Variation we just Read above in step 3. (Is the Magnetic variation of my new position (I wrote in step 2) not different than at the "old" position of my plane it was in before I moved in it in step 2?)

magv = (magv * 360#) / 65536#
FS_Head = txtHead.Text + magv                    
FS_Head = (FS_Head * 65536# * 65536#) / 360#
If FS_Head < -360 Then
   FS_Head = FS_Head + 720
ElseIf FS_Head < 0 Then
   FS_Head = 360 + FS_Head
ElseIf FS_Head = 0 Then
   FS_Head = 360
ElseIf FS_Head > 360 Then
   FS_Head = FS_Head - 360
End If

5. Write the True Heading to FSUIPC.

6. Finish

I hope that my English, which is not my First language, is understandable.

Clearly the mistake I make is somewhere in converting my Mangnetic Heading to True.

(An interesting thing I saw is that if I write the Pitch angle before the Altitude gets written the Pitch changes significantly. Perhaps this can help someone. It makes sense.)

Perhaps there is a order to write the Position parameters? (Lat, Lon, Alt, Heading, Pitch, Bank angle.)

Posted

FS_Head = (FS_Head * 65536# * 65536#) / 360#

If FS_Head < -360 Then

FS_Head = FS_Head + 720

ElseIf FS_Head < 0 Then

FS_Head = 360 + FS_Head

ElseIf FS_Head = 0 Then

FS_Head = 360

ElseIf FS_Head > 360 Then

FS_Head = FS_Head - 360

End If

Eryou convert the FS_Head value to FS units (which range from -2^31 to +(2^31-1), then add or subtract 720 or 360 depending on the value of this huge number ....? Doesn't that look just a little wrong to you at all? :-(

Try correcting the heading in degrees before converting it into something which is nothing like degrees.

In any case, the correction should be simply (in C, sorry):

while (x &gt;= 360) x -= 360;
while (x &lt; 0) x += 360;

I hope that my English, which is not my First language, is understandable.

Clearly the mistake I make is somewhere in converting my Mangnetic Heading to True.

And in any case you still don't tell me enough. What heading are you trying to write, what MagVar are you reading, and, most important, what is the result in FS? You don't give any information! A complete example would be useful, don't you think, especially this result which you keep saying is in error but don't say how.

Are you saying the heading doesn't change at all, that you end up facing the same way as before? Or TRUE north. Or what?

Why not do something very very simple and much more helpful and definitive? Use the tools available. Switch on IPC read/Write logging in FSUIPC, do whatever it is you do, then look at the log. Show it to me. Tell me what heading you are trying to achieve. I'll be able to see from the log what you are reading and what you are writing.

Regards

Pete

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.