PDA

View Full Version : How do you set the altitude for AP?



jmig
11-21-2009, 10:11 PM
I have been trying for two weeks to use an encoder to set the autopilot's altitude. Currently I have a Go-Flight AP which allows me to set the altitude and see it on LED displays.

I want to eventually get rid of the go-flight AP for a custom one. The first step is using an encoder to set the altitude. I have tried using parts of MEC scripts. Peter gave me some ideas and I have tried to use his info to build my script. It looks to me like it should work. It doesn't.

Using IPConsole I can see the altitude change ad the offset change with the Go-Flight dial. Not with my encoder. The encoder is working so the problem is in my scripts. Any help appreciated. Here is the latest code.

Var 3050, name AP_ALT, Link FSUIPC_INOUT, Offset $07D4, Length 4
{
L0 = &ROAP_ALT * -1 // turn clockwise to increase

IF L0 > 0
{
L0 = L0 + 100

}
ELSE
{
L0 = L0 -100
}

&AP_ALT = ROTATE 0, 80000, L0 // Increase or Decrease altitude
}

Var 3053, name ROAP_ALT, Link IOCARD_ENCODER, Input 43, Aceleration 6, Type 2

I tried // out the ROTATE function line. It didn't help.

deering
11-22-2009, 12:46 AM
Hello, Peter.

As written, your script does nothing with inputs from the encoder.
You want to execute some SIOC commands as a result of changes to variable 3053 so

{
L0 = &ROAP_ALT * -1 // turn clockwise to increase
.
.
should be placed after that declaration.

Then you would have to make adjustments to deal with the fact that $7D4 is "Autopilot altitude value, as metres*65536". So to add 100 ft you need to convert that to metres and then multiply by 65536. It will take a lot of turns of your encoder to get there in fractions of a centimetre, as you are doing.

A better method is to let FS (or Peter Dowson) do the work for you via offset $3110. FS has a bunch of functions built-in which are available to application programmers as FS Controls. The FSUIPC package puts the list in your Modules folder. You'll see there two controls of immediate interest:

65892 AP_ALT_VAR_INC
65893 AP_ALT_VAR_DEC

These are two of the functions you want with their associated control numbers. FSUIPC will invoke those functions on your behalf if you stuff the appropriate control number into offset $3110. [You just need length 4 for your
AP_ALT functions as they do not need a parameter]

Those two give you 100ft increments/decrements. To get 1000ft steps, look at the FSUIPC guide for Advanced Users where you will find that Peter has augmented the FS list with "Additional 'FS' Controls" - including:

1016 Ap Alt Var Dec Fast (–1000)
1017 Ap Alt Var Inc Fast (+1000)

So your script using this solution might be::

-----------------------------------------------------------

Var 3050, name FS_Controls, Link FSUIPC_OUT, Offset $3110, Length 4
Var 3053, name ROAP_ALT, Link IOCARD_ENCODER, Input 43, Aceleration 6, Type 2
{
IF &ROAP_ALT > 0
{
...IF &ROAP_ALT > 1
......{
.......&FS_Controls = 1017 // Ap Alt Var Inc Fast
.......}
...ELSE
......{
.......&FS_Controls = 65892 // AP_ALT_VAR_INC
......}
}
ELSE
{
...IF &ROAP_ALT < -1
......{
.......&FS_Controls = 1016 // Ap Alt Var Dec Fast
......}
...ELSE
......{
.......&FS_Controls = 65893 // AP_ALT_VAR_DEC
......}
}
&FS_Controls = DELAY 0 ,5 // Pause to allow FSUIPC to work
// Then clear the offset for the next time.
}

-----------------------------------------------------------

Some other observations:



L0 = &ROAP_ALT * -1 // turn clockwise to increase


Looks like you've reversed the wiring on your encoder. I assumed you would fix that in my script.




&AP_ALT = ROTATE 0, 80000, L0 // Increase or Decrease altitude



You wanted the LIMIT function here...with the appropriate changes for metres*65536. That's all taken care of in the FS Control routines.

G'night.

Jim

Peter Dowson
11-22-2009, 04:58 AM
I have been trying for two weeks to use an encoder to set the autopilot's altitude.
...
Offset $07D4, Length 4

I'm afraid I can't help with your script code (don't know it at all), but you should note that the A/P target altitude at offset 07D4 is in units of 1/65536ths of a metre. so you probably have some arithmetic to do at some place in the script.

[Ah, I see Jim's already clarified that point for you ... Tks!]

Pete

jmig
11-22-2009, 06:07 PM
Woooooohhhhhooooooooo! It works!!!

Thanks a Million to everyone who helped me. I may not be a programmer but, with help like this even I can get SIOC to do what I want it to do.

:D