Results 1 to 1 of 1
Thread: Altimeter code
-
07-13-2010, 09:08 AM #1
Altimeter code
Hello guys,
I started to work on an altimeter (real one with rotating numbers) and it uses a DC motor and 2 pots: one pot turns every 2000 ft and the other one makes a full rotation through the whole scale (60k feet).
The pot used for 2000ft scale is a continuous turn pot which electrically operates for 340° so from 0 to 1888 ft instead of 2000 ( I will study how to recover those missing feet later)
I want to make this work as The first one gives a precise position each 2000 ft and the other one should be used as a sort of counter to let sioc understand in which "2000ft segments" it is operating.
I started with the following code but changing the CounterAd value don't make the thing following what I have in mind...do you have a suggestion on how to do that?
Thanks
Code:Var 0000, Value 0 { &AltControl = TIMER 999 ,0 ,2 &AltObj = 0 &AltMotor = 0 } Var 0003, name AltMotor, static, Link USB_DCMOTOR, Device 2, Output 1 // motor control (0-127) 0=Left, +128 = Rig Var 0006, name AltAd, static, Link USB_ANALOGIC, Device 2, Input 1, PosL 0, PosC 127, PosR 255 // Pot value Var 0007, name CounterAd // , static, link USB_ANALOGIC, Device 2, Input 2, PosL 0, PosC 127, PosR 255 // Counter value Var 9001, name AltOffst, Link FSUIPC_IN, Offset $6020, Length 8 { L0 = &AltOffst * 3.28084 // FSUIPC conversion, L0=Altitude &Altitude = L0 L0 = ROUND L0 L2 = L0 IF &CounterAd <= 6 // from 0 to 2000ft { IF L0 <= 0 // Pot 0° { L1 = 0 // pot 0 } ELSE { L2 = L0 - 0 IF L0 <= 1888 // Pot 340° { L1 = L2 / 7.379 // Pot 255 L1 = ROUND L1 } ELSE { IF L0 > 1888 { L1 = 255 // Pot 255 } } } } ELSE { IF &CounterAd <= 12 // from 2000 to 4000 ft { L2 = L0 - 2000 IF L0 <= 0 { L1 = 0 } ELSE { IF L0 <= 1888 { L1 = L2 / 7.379 L1 = ROUND L1 } ELSE { IF L0 > 1888 { L1 = 255 } } } } } &AltObj = L1 } Var 9002, name Altitude Var 9004, name AltControl, Link SUBRUTINE // Subrutine for Control (each 20ms) { L0 = &AltObj - &AltAd L1 = 0 IF L0 < 0 { L1 = 128 } L0 = ABS L0 L2 = &AltVelMax + L1 IF L0 <= &AltAprox8 { L2 = &AltVel8 + L1 } IF L0 <= &AltAprox6 { L2 = &AltVel6 + L1 } IF L0 <= &AltAprox4 { L2 = &AltVel4 + L1 } IF L0 <= &AltAprox2 { L2 = &AltVel2 + L1 } IF L0 <= &AltAproxSlow { L2 = &AltVelMin + L1 } IF L0 = &AltMargen { L2 = 0 } &AltMotor = L2 } Var 9006, name AltObj // objective position Var 9007, name AltMargen, Value 0 // %error Var 9008, name AltAprox8, Value 15 Var 9009, name AltAprox6, Value 12 Var 9010, name AltAprox4, Value 8 Var 9011, name AltAprox2, Value 4 Var 9012, name AltAproxSlow, Value 1 Var 9013, name AltVelMax, Value 24 // Speed for follow objective Var 9014, name AltVel8, Value 20 // Speed for proximity obj Var 9015, name AltVel6, Value 16 Var 9016, name AltVel4, Value 12 Var 9017, name AltVel2, Value 8 Var 9018, name AltVelMin, Value 4 // Speed approaching target
Similar Threads
-
Standby altimeter
By eudoniga in forum PM Boeing GCReplies: 2Last Post: 04-09-2010, 10:42 AM -
USB Altimeter
By bobbosan in forum Computer Hardware SetupReplies: 8Last Post: 05-01-2008, 10:32 PM -
SimKit USB Altimeter
By bobbosan in forum I/O Interfacing Hardware and SoftwareReplies: 2Last Post: 04-28-2008, 09:14 AM -
offset for F/O altimeter STD
By npbosch in forum PM General Q & AReplies: 0Last Post: 12-12-2007, 05:37 PM