Yes i remember when it was so cheap and then i was still planning my cockpit and was buying screens and then i missed the "bus" and the price went up TOO much for me.
Printable View
Stefan,
Shearder and myself are having some issues (one anyway) with the MCP code and hope that you can take a look at it. Here is the problem, when intercepting the ILS vectors, we press the APP button which turns off the AP HDG and stays horizonatally aligned with the runway, but it does not follow the glide slope down to the runway, the ALT remains on and the aircraft maintains it's altitude. We have both gone over the code and cannot identify why this is happening. Without FSBus running, the software (FSX) does exactly as it should.
Here is the .cpp file for the MCP (I will only post the case and not the declarations and Mk code)
Thanks
David
Code:void cbModecontrolpanel (int oid, int val, double dval)
{
int x;
switch (oid)
{
case C_RCOURSELR:
//EventHandler(S_RHEADING, 0, 0); // sound rotary
Course -= val; // val can be >1 or <-1
while (Course > 360) // wrapped forward
Course -= 360; // full circle back
while (Course <= 0) // wrapped backward
Course += 360; // full circle forward
FsWriteInt(FS_NAV1OBS, Course); // to FS
FsbusWrite(C_DCOURSEL, Course); // to cockpit display
FsbusWrite(C_DCOURSER, Course);
FsbusWrite(C_OBS_DISPLAY, Course);
break;
case C_RIAS:
//EventHandler(S_RHEADING, 0, 0); // sound rotary
if (MachSpeed == 0)
{
Airspeed -= val;
if (Airspeed < 100) // minimum 100 knts
Airspeed = 100;
if (Airspeed > 340) // maximum 340 knts
Airspeed = 340;
FsWriteInt(FS_AP_AIRSPEED, Airspeed); // to FS
FsbusWrite(C_DIAS, Airspeed);
}
else
{
Mach -= val;
if (Mach > 70)
Mach = 70;
if (Mach < 10)
Mach = 10;
FsWriteInt(FS_AP_MACH, Mach * 65536 / 100);
FsbusWrite(C_DIAS, Mach);
}
break;
case C_RHEADING: // APHeading range: 1..360
//EventHandler(S_RHEADING, 0, 0); // sound rotary
APHeading -= val; // val can be >1 or <-1
while (APHeading > 360) // wrapped forward
APHeading -= 360; // full circle back
while (APHeading <= 0) // wrapped backward
APHeading += 360; // full circle forward
x = (APHeading % 360) * 65536 / 360 + 1; // (+1 is for rounding)
FsWriteInt(FS_AP_HEADING, x); // to FS
FsbusWrite(C_DHEADING, APHeading); // to cockpit display
break;
case C_RALTITUDE:
apalt += val*100;
if (apalt < 0)
apalt = 0;
if (apalt > 39000)
apalt = 39000;
FsbusWrite (C_DALTITUDE, apalt);
FsWriteInt(FS_AP_ALTITUDE, apalt*19975);
break;
//EventHandler(S_RHEADING, 0, 0); // sound rotary
/*Altitude += val * 10000 / 100;// // val can be >1 or <-1
// printf("Altitude %d\n", Altitude);
FsbusWrite(C_DALTITUDE, Altitude);
FsWriteInt(FS_AP_ALTITUDE, Altitude); // to Fs
break;*/
case C_RVSPEED:
//EventHandler(S_RHEADING, 0, 0); // sound rotary
Vertspeed += val * 10000 / 100; // update
if (Vertspeed < -7600)
Vertspeed = -7600; // Max decend
if (Vertspeed > 6000)
Vertspeed = 6000; // Max climb
FsbusWrite(C_DVSPEED, Vertspeed);
FsWriteInt(FS_AP_VS, Vertspeed); // to FS
break;
case C_SFLIGHTDIRL:
if (val == 0) //here you write if 1 active or 0
{
printf("DIRL0, val=%d\n", val);
FsbusWrite(C_LFLIGHTDIRL, 1);
FsbusWrite(C_LMASTFLIGHTL, 1);
FsWriteInt(FS_FLIGHTDIRECTOR,1);
}
else
{
// printf("DIRL1, val=%d\n", val);
FsbusWrite(C_LFLIGHTDIRL, 0);
FsbusWrite(C_LMASTFLIGHTL, 0);
FsWriteInt(FS_FLIGHTDIRECTOR, 0);
}
break;
case C_SAUTOTHROTTLEARM:
CockpitATArmed = (val == 0) ? 1 : 0;
if (bSynchronised) // pass only when in sync
FsWriteInt(FS_AUTOTHROTTLEARM, (val == 0) ? 1 : 0);
FsbusWrite(C_LATARMED, CockpitATArmed);
printf("C_SAUTOTHROTTLEARM event, CockpitATarmed %d\n", CockpitATArmed);
if (CockpitATArmed == 0)
{
AirspeedHold = 0;
MachHold = 0;
}
break;
case C_SN1:
if ((val == 0) & (CockpitATArmed == 1)) // button push only
{ // AT on
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
EngN1 = (EngN1 == 0) ? 1 : 0; // toggle
if (MachSpeed == 0)
FsWriteInt(FS_AP_AIRSPEEDHOLD, EngN1); // to FS
else
FsWriteInt(FS_AP_MACHHOLD, EngN1);
if (EngN1 == 1)
AirspeedHold = 0;
FsbusWrite(C_LN1, EngN1);
FsbusWrite(C_LAIRSPEEDHOLD, AirspeedHold);
FsWriteInt(FS_ENGINE1N1, EngN1);
FsWriteInt(FS_ENGINE1N2, EngN1);
}
break;
case C_SSPDHLD:
if ( (val == 0) && (CockpitATArmed == 1) ) // button push only
{
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
AirspeedHold = (AirspeedHold == 0) ? 1 : 0; // toggle
FsbusWrite(C_LAIRSPEEDHOLD, AirspeedHold);
if (AirspeedHold == 1)
{
EngN1 = 0;
FsbusWrite(C_LN1, EngN1);
if (MachSpeed == 0)
FsWriteInt(FS_AP_AIRSPEEDHOLD, 1);
else
FsWriteInt(FS_AP_MACHHOLD, 1);
}
else
{
FsWriteInt(FS_AP_AIRSPEEDHOLD, 0);
FsWriteInt(FS_AP_MACHHOLD, 0);
}
//FsWriteInt(FS_ENGINE1N1, EngN1);
//FsWriteInt(FS_ENGINE1N2, EngN1);
}
break;
case C_SSPDINTV:
break;
case C_SCHANGEOVER:
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
if (val == 0) // button push only
{
MachSpeed = (MachSpeed == 0) ? 1 : 0; // toggle
if (MachSpeed == 1) // Mach indication
{
DisplayOptions(C_DIAS, 3, 0, TRUE, 3);
FsbusWrite(C_DIAS, Mach);
FsWriteInt(FS_AP_MACHHOLD, 1);
}
else // IAS indication
{
DisplayOptions(C_DIAS, 4, 0, FALSE, 0); // Fsbus bug (p5=0)
FsbusWrite(C_DIAS, Airspeed);
FsWriteInt (FS_AP_AIRSPEEDHOLD, 1);
}
}
break;
case C_SVNAV:
break;
case C_SLNAV:
break;
case C_SLVLCHG:
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
if ((val == 0) && // button push
(abs(ActAlt - Altitude) > 200) && // delta in ft
((AirspeedHold == 1) || (EngN1 == 1)))
{
LvlChg = (LvlChg == 0) ? 1 : 0; // toggle
if (LvlChg == 1) // level change
{
AltitudeLock = 0; // off
FsWriteInt(FS_AP_ALTITUDELOCK, LvlChg); // activate
x = Altitude * 65536 / 100 * 3048; // in meters * 65536
AltitudeSave = Altitude; // save for AltInt
FsWriteInt(FS_AP_ALTITUDE, x * 19975);
FsWriteInt(FS_AP_VSHOLD, 0);
FsbusWrite(C_LLVLCHG, LvlChg); // sync lvl change
if (ActAlt < Altitude) // climbing
{
EngN1 = 0; // force N1 off
//EventHandler(C_SN1, 0, 0); // toggle -> on
FsWriteInt(FS_AP_VS, 800); // default climb speed
}
else // descending
{
AirspeedHold = 0; // force IAS off
//EventHandler(C_SSPDHLD, 0, 0); // toggle -> on
FsWriteInt(FS_AP_VS, -800); // default desc. speed
}
}
else // no level change
{
AltitudeLock = 1; // on
FsbusWrite(C_LLVLCHG, LvlChg); // lvl-swtch
}
FsbusWrite(C_LALTITUDELOCK, AltitudeLock); // update altitude lock
}
break;
case C_SHEADINGLOCK:
if (val == 0) // button push only
{
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
HeadingLock = (HeadingLock == 0) ? 1 : 0; // toggle
FsWriteInt(FS_AP_HEADINGLOCK, HeadingLock);
}
break;
case C_SVORLOC:
break;
case C_SAPP:
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
if (val == 0) // button push only
{
ApproachHold = (ApproachHold == 0) ? 1 : 0; // toggle
FsWriteInt(FS_AP_APPROACHHOLD, ApproachHold);
}
break;
case C_SALTHLD:
if (val == 0)
{
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
AltitudeLock = (AltitudeLock == 0) ? 1 : 0; // toggle
FsWriteInt(FS_AP_ALTITUDELOCK, AltitudeLock);
printf("C_SALTHLD AltitudeLock=%d\n", AltitudeLock);
FsbusWrite(C_LALTITUDELOCK, AltitudeLock);
}
break;
case C_SALTINTV:
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
if (val == 0) // button push only
{
if (AltitudeSave != Altitude) // changed by pilot
{
AltitudeSave = Altitude; // save for AltInt
x = Altitude * 65536 / 10000 * 3048; // in meters * 65536
}
else // unchanged
{
AltitudeSave = ActAlt; // save for AltInt
x = (ActAlt + 50) / 100 * 100; // round to 100
x = x * 65536 / 10000 * 3048; // in meters * 65536
AltitudeLock = 1;
FsbusWrite(C_LALTITUDELOCK, AltitudeLock);
LvlChg = 0;
FsbusWrite(C_LLVLCHG, LvlChg);
}
FsWriteInt(FS_AP_ALTITUDE, x); // new AP altitude
}
break;
case C_SVSPEEDHLD:
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
if (val == 0) // button push only
{
VertspeedHold = (VertspeedHold == 0) ? 1 : 0; // toggle
FsWriteInt(FS_AP_VSHOLD, VertspeedHold);
}
break;
case C_SCMDA:
if ((val==0) && (Disengage == 0)) // button push only
{
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
Cmda = (Cmda == 0) ? 1 : 0; // toggle
if (Cmda == 0)
FsbusWrite(C_LCMDA, 0);
else
{
FsbusWrite(C_LCMDA, 1);
FsbusWrite(C_LCMDB, 0);
FsbusWrite(C_LCWSA, 0);
FsbusWrite(C_LCWSB, 0);
FsWriteInt(FS_AP_MASTER, 1);
}
}
break;
case C_SCMDB:
if ((val==0) && (Disengage == 0)) // button push only
{
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
Cmdb = (Cmdb == 0) ? 1 : 0; // toggle
if (Cmdb == 0)
FsbusWrite(C_LCMDB, 0);
else
{
FsbusWrite(C_LCMDB, 1);
FsbusWrite(C_LCWSA, 0);
FsbusWrite(C_LCWSB, 0);
FsWriteInt(FS_AP_MASTER, 1);
}
}
break;
case C_SCWSA:
if ((val==0) && (Disengage == 0)) // button push only
{
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
Cwsa = (Cwsa == 0) ? 1 : 0; // toggle
if (Cwsa == 0)
FsbusWrite(C_LCWSA, 0);
else
{
FsbusWrite(C_LCMDA, 0);
FsbusWrite(C_LCMDB, 0);
FsbusWrite(C_LCWSA, 1);
FsbusWrite(C_LCWSB, 0);
FsWriteInt(FS_AP_MASTER, 1);
}
}
break;
case C_SCWSB:
if ((val==0) && (Disengage == 0)) // button push only
{
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
Cwsb = (Cwsb == 0) ? 1 : 0; // toggle
if (Cwsb == 0)
FsbusWrite(C_LCWSB, 0);
else
{
FsbusWrite(C_LCMDA, 0);
FsbusWrite(C_LCMDB, 0);
FsbusWrite(C_LCWSA, 0);
FsbusWrite(C_LCWSB, 1);
FsWriteInt(FS_AP_MASTER, 1);
}
}
break;
case C_SAPDISENGAGE:
if (val==0) // button push only
{
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
Disengage = (Disengage == 0) ? 1 : 0; // toggle
if (Disengage == 0)
{
FsbusWrite(C_LAPDISENGAGEL, 0);
FsbusWrite(C_LAPDISENGAGER, 0);
}
else
{
FsbusWrite(C_LAPDISENGAGEL, 1);
FsbusWrite(C_LAPDISENGAGER, 1);
FsbusWrite(C_LCMDA, 0);
FsbusWrite(C_LCMDB, 0);
FsbusWrite(C_LCWSA, 0);
FsbusWrite(C_LCWSB, 0);
FsWriteInt(FS_AP_MASTER, 0);
}
}
break;
case FS_AP_MASTER:
break;
case FS_AP_WINGLEVELER:
break;
case FS_AP_NAV1LOCK:
break;
case FS_AP_HEADINGLOCK:
HeadingLock = val;
FsbusWrite(C_LHEADINGLOCK, val);
break;
case FS_AP_HEADING:
APHeading = (val + 1) * 360 / 65536; // (+1 for rounding)
if (APHeading == 0)
APHeading = 360;
FsbusWrite(C_DHEADING, APHeading);
break;
case FS_NAV1OBS:
Course = val;
if (Course == 0)
Course = 360;
FsbusWrite(C_DCOURSEL, Course);
FsbusWrite(C_DCOURSER, Course);
break;
case FS_AP_ALTITUDELOCK:
AltitudeLock = val;
FsbusWrite(C_LALTITUDELOCK, val);
break;
case FS_AP_ALTITUDE:
Altitude = (val / 3048 * 2500 + 8192) / 16384; // to feet
FsbusWrite(C_DALTITUDE, Altitude);
break;
case FS_ALTITUDE:
ActAlt = val * 10000 / 3048; // to feet
if ((ActAlt > 25500) && (ActAlt < 26500))
{
if ((MachSpeed == 0) && (ActAlt > 26000))
cbModecontrolpanel(C_SCHANGEOVER,0,0);
else if ((MachSpeed == 1) && (ActAlt < 26000))
cbModecontrolpanel(C_SCHANGEOVER,0,0);
}
if (abs(Altitude - ActAlt) < 10)
{
LvlChg = 0;
FsbusWrite (C_LLVLCHG , LvlChg);
FsbusWrite (C_LALTITUDELOCK , 1);
}
break;
case FS_AP_VS:
Vertspeed = val;
FsbusWrite(C_DVSPEED, Vertspeed);
break;
case FS_AP_RPMHOLD:
break;
case FS_AP_RPM:
break;
case FS_AP_GLIDESLOPEHOLD:
break;
case FS_AP_APPROACHHOLD:
ApproachHold = val;
FsbusWrite(C_LAPP, ApproachHold);
break;
case FS_FLIGHTDIRECTOR:
if (bSynchronised == false)
{
if (val == 1)
{ printf("C_SFLIGHTDIRL event, ValFlightDir=%d\n", ValFlightDir);
FsbusWrite(C_LFLIGHTDIRL, 1);
FsbusWrite(C_LMASTFLIGHTL, 1);
FsbusWrite(C_LFLIGHTDIRR, 0);
FsbusWrite(C_LMASTFLIGHTR, 0);
// FsWrite(FS_FLIGHTDIRECTOR,1);
ValFlightDir = 1;
}
else
{
FsbusWrite(C_LFLIGHTDIRL, 0);
FsbusWrite(C_LMASTFLIGHTL, 0);
FsbusWrite(C_LFLIGHTDIRR, 0);
FsbusWrite(C_LMASTFLIGHTR, 0);
// FsWrite(FS_FLIGHTDIRECTOR,0);
ValFlightDir = 0;
}
}
break;
case FS_ENGINE1N1:
Engine1N1 = val * 100 / 16384;
break;
case FS_ENGINE1N2:
Engine1N2 = val * 100 / 16384;
break;
}
}
Ok, what Aircraft do you use?
Do you press the VorLoc befor you press the App?
Can you compare alle the MCP Offsets with FSinterogate, test one Software panel only, second test with hardware.
I donīt know your code. It looks like FS default but without knowing the offset i canīt say anything.
But as first, i also told that Shearder via skype there is no VORLOC funktion.
That is the App, it only writes 0 or 1 to an offset, the fsbus code donīt makes more. The rest do only the aircraft by it self.Code:case C_SAPP:
//EventHandler(S_SADFSWAP, 0, 0); // sound small switch
if (val == 0) // button push only
{
ApproachHold = (ApproachHold == 0) ? 1 : 0; // toggle
FsWriteInt(FS_AP_APPROACHHOLD, ApproachHold);
}
break;
I would start writing the a new MCP code.
Stefan
Stefan,
I am testing this in a 737.
When I just use FSX, it works fine and I don't push VOR LOC it intercepts the GS and holds runway heading (basically lands itself).
With FSInterrogate, here are my findings:
When just using FSX (this can be with FSBus running, but pressing the buttons in the VC with the mouse)
When you select APP, 07C8 (APHeadingHold) turns off (goes from a 1 to a 0) as it intercepts the ILS (horizontal) and then 07D0 (APAltitude Hold) turns off as it intersects the glideslope. Also at the same time as pressing APP, the following two offsets turn on: 07FC (AP GSHold), and 0800 (AP Approach Hold).
Same situation, this time just using the buttons on my MCP through FSBUS:
When you select APP, 07C8 (APHeadingHold) turns off (goes from a 1 to a 0) as it intercepts the ILS (horizontal) but 07D0 (APAltitude Hold) does not turn off as it intersects the glideslope. Also at the same time as pressing APP, the following offset turn on: 0800 (AP Approach Hold).
07FC (AP GSHold) does not turn on, which I think is why APAltitude Hold does not turn off as it intersects the glideslope.
Does this give any clarity?
Here is the code I have relating to the last two offsets:
case FS_AP_GLIDESLOPEHOLD:
break;
case FS_AP_APPROACHHOLD:
ApproachHold = val;
FsbusWrite(C_LAPP, ApproachHold);
break;
Thanks
David
PS I hope this makes sense.
I would write the MCP new, if you use the default 737 use that MCP as sample.
Ok, after much testing, here is the solution!!!
Add this at the top with the rest of the static int:
Then uncomment out:Code:static int GlideslopeHold = 0;
Then change this:Code:MkFsObject(FS_AP_GLIDESLOPEHOLD, "",cbModecontrolpanel, 0x07FC, 4, TP_UI32, FS_NORMAL, 0);
to this:Code:case C_SAPP:
if (val == 0) // button push only
{
ApproachHold = (ApproachHold == 0) ? 1 : 0; // toggle
FsWriteInt(FS_AP_APPROACHHOLD, ApproachHold);
}
break;
Have tested and works for me.Code:case C_SAPP:
if (val == 0) // button push only
{
ApproachHold = (ApproachHold == 0) ? 1 : 0; // toggle
FsWriteInt(FS_AP_APPROACHHOLD, ApproachHold);
GlideslopeHold = (GlideslopeHold == 0) ? 1 : 0;
FsWriteInt(FS_AP_GLIDESLOPEHOLD, GlideslopeHold);
}
break;
Let me know if it works for you too.
David
Need your help again Stefan.
I am programming a stepper driven ADF/RMI.
I just need help with the details in the code. I have pasted the basic template below and would be very gratefull for your help to complete.
It is driven by 2 stepper motors, one for the ADF Dial Heading(compass card) and the other motor drives the ADF Relative Bearing indicator needle.
I also have a rotary to adjust the compass card.
I have also layed it out using Dirk's example of using only one file which is the .cpp if I understand correctly and do not need the .h file.
Thanks as always.
David
Code:#include "stdafx.h"
#include "fsbus.h"
void cbSteppergauges(int oid, int val, double dval);
#define FS_ADF1RELATIVEBEARING 1
#define FS_ADF1DIALBEARING 2
#define C_ADFCOMPASSCARD 3
#define C_ADFBEARINGNEEDLE 4
#define C_ADFROSEADJUST 5
void cbSteppergaugesBuildObjects()
{
MkFsObject(FS_ADF1RELATIVEBEARING,"ADF Needle", cbSteppergauges, 0x0C6A, 2, TP_I16, FS_NORMAL,0);
MkFsObject(FS_ADF1DIALBEARING,"ADF Compass Card", cbSteppergauges, 0x0C6C, 2, TP_I16, FS_NORMAL,0);
MkFsbusObject(BTP_V_OUT, C_ADFCOMPASSCARD,"",NULL,30,80,0);
MkFsbusObject(BTP_V_OUT, C_ADFBEARINGNEEDLE,"",NULL,29,80,0);
MkFsbusObject(BTP_ROTARY, C_ADFROSEADJUST, "",cbModecontrolpanel, 27, 14, 0);
}
{
switch(oid)
{
case FS_ADF1RELATIVEBEARING:
FsbusWrite(C_ADFBEARINGNEEDLE, ????);//should this be FsbusWriteFmtVar()
break;
case FS_ADF1DIALBEARING:
FsbusWrite(C_ADFCOMPASSCARD, ????);//should this be FsbusWriteFmtVar()
break;
case C_ADFROSEADJUST:
// this rotary will move the compass rose left or right (FS_ADF1DIALBEARING)
FsWriteInt(FS_ADF1DIALBEARING, val??);
break;
}
}
Hi David,
The stepper outputs use the FsbusWriteFmtVar(cid,rid,value) function.
You donīt need to define a stepper.
Stefan
Ok, is this getting closer?
Also is my rotary code correct?
Also, is this written correctly (do I need to have more than just 'val' there:
case FS_ADF1RELATIVEBEARING:
FsbusWriteFmtVar(29,80,val);
break;
Thanks
David
Code:#include "stdafx.h"
#include "fsbus.h"
void cbSteppergauges(int oid, int val, double dval);
#define FS_ADF1RELATIVEBEARING 1
#define FS_ADF1DIALBEARING 2
//#define C_ADFCOMPASSCARD 3 / not needed
//#define C_ADFBEARINGNEEDLE 4 / not needed
#define C_RADFROSEADJUST 5
static int ADFroseadjust = 0;
void cbSteppergaugesBuildObjects()
{
MkFsObject(FS_ADF1RELATIVEBEARING,"ADF Needle", cbSteppergauges, 0x0C6A, 2, TP_I16, FS_NORMAL,0);
MkFsObject(FS_ADF1DIALBEARING,"ADF Compass Card", cbSteppergauges, 0x0C6C, 2, TP_I16, FS_NORMAL,0);
//MkFsbusObject(BTP_V_OUT, C_ADFCOMPASSCARD,"",NULL,30,80,0);Not needed
//MkFsbusObject(BTP_V_OUT, C_ADFBEARINGNEEDLE,"",NULL,29,80,0);Not needed
MkFsbusObject(BTP_ROTARY, C_RADFROSEADJUST, "",cbModecontrolpanel, 27, 26, 0);
}
{
switch(oid)
{
case FS_ADF1RELATIVEBEARING:
FsbusWriteFmtVar(29,80,val);
break;
case FS_ADF1DIALBEARING:
FsbusWriteFmtVar(30,80,val);
break;
case C_RADFROSEADJUST:
ADFroseadjust -= val;
while (ADFroseadjust > 360)
ADFroseadjust -= 360;
while (ADFroseadjust <=0)
ADFroseadjust += 360;
x = (ADFroseadjust % 360)
FsWriteInt(FS_ADF1DIALBEARING,x);
break;
}
}
Did you write a small programm to test your steppers wih the stepper board?
Here my programm:
Code:#include "stdafx.h"
#include "fsbus.h"
int _tmain(int argc, _TCHAR* argv[])
{
CheckIn();
BOOL b = FsbusOpen("COM3");
FsbusWriteFmtVar(29, 80, 0);
FsbusMux(2000);
FsbusWriteFmtVar(29, 80, 2000);
FsbusMux(2000);
FsbusWriteFmtVar(29, 80, 0);
FsbusMux(2000);
CheckOut();
return 0;
}
I tested the stepper boards when Dirk sent through some sample code some time ago (He used v1 of the dll to test it though, I think you pointed that out).
So, I know the boards work.
This was what I used (pretty well just minor changes to your code)
So, how am I doing with the code I've written so far for the ADF.Code:#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
CheckIn();
BOOL b = FsbusOpen("COM1");
FsbusWriteFmtVar(29, 80, 0);
FsbusMux(2000);
FsbusWriteFmtVar(29, 80, 100);
FsbusMux(2000);
FsbusWriteFmtVar(29, 80, 0);
FsbusMux(2000);
CheckOut();
return 0;
}
I am getting 1 compiling error though: steppergauges.cpp(22) : error C2447: '{' : missing function header (old-style formal list?)
This is the code exactly to this minute that is producing the error:
Once I get it to compile, should I just test it with the gauge and see what happens?Code:#include "stdafx.h"
#include "fsbus.h"
void cbSteppergauges(int oid, int val, double dval);
#define FS_ADF1RELATIVEBEARING 1
#define FS_ADF1DIALBEARING 2
//#define C_ADFCOMPASSCARD 3
//#define C_ADFBEARINGNEEDLE 4
#define C_RADFROSEADJUST 5
static int ADFroseadjust = 0;
void cbSteppergaugesBuildObjects()
{
MkFsObject(FS_ADF1RELATIVEBEARING,"ADF Needle", cbSteppergauges, 0x0C6A, 2, TP_I16, FS_NORMAL,0);
MkFsObject(FS_ADF1DIALBEARING,"ADF Compass Card", cbSteppergauges, 0x0C6C, 2, TP_I16, FS_NORMAL,0);
//MkFsbusObject(BTP_V_OUT, C_ADFCOMPASSCARD,"",NULL,30,80,0);
//MkFsbusObject(BTP_V_OUT, C_ADFBEARINGNEEDLE,"",NULL,29,80,0);
MkFsbusObject(BTP_ROTARY, C_RADFROSEADJUST, "",cbModecontrolpanel, 27, 26, 0);
}
void cbSteppergauges(int oid, int val, double dval);
{
int x;
switch(oid)
{
case FS_ADF1RELATIVEBEARING:
FsbusWriteFmtVar(29,80,val);
break;
case FS_ADF1DIALBEARING:
FsbusWriteFmtVar(30,80,val);
break;
case C_RADFROSEADJUST:
ADFroseadjust -= val;
while (ADFroseadjust > 360)
ADFroseadjust -= 360;
while (ADFroseadjust <=0)
ADFroseadjust += 360;
x = (ADFroseadjust % 360);
FsWriteInt(FS_ADF1DIALBEARING,x);
break;
}
}
David
try that test with the V3 dll. that works in my sample.
Edit: donīt!!!
void cbSteppergauges(int oid, int val, double dval);
has to be
void cbSteppergauges(int oid, int val, double dval)
Great, compiles now.
So looking back at some code you worked with me on for my Altitude gauge, I can see how 'val' is worked out.
So for the 'val' in the ADF code, I need to work out the number of steps to 360 deg, and divide the value by that as in the sample above. Am I correct?Code:case FS_ALTIMETERFEET:
val=val/5; // 1000feet for 360° are 200 steps (1000/200)
//printf("Altimeter Feet %d\n", val);
FsbusWriteFmtVar(8, 80,val);
break;
Thanks
sounds perfect. if you have a gear dont forget it.
A 200step neadle on a 360° scale donīt perfect.
I do have gears so I will work it out.
I am trying to print the value of the ADF needle and the ADF rose face, and I don't seem to be getting anything.
Here's what I have (I have the same for the altitude and it prints it fine):
case FS_ADF1RELATIVEBEARING:
val=val/1; // 360° are ? steps
printf("ADF relative bearing %d\n", val);
FsbusWriteFmtVar(29,80,val);
break;
if i understand that right, you whant to have a output like:Quote:
I am trying to print the value of the ADF needle and the ADF rose face, and I don't seem to be getting anything.
Input value: 12345 Needle Position: 67890
right??
Well, it's not really important to have as I can get these figures from FSInterrogate. I was just wondering why it isn't printing any value at all when I move the needle or the dial face.
Also, the ADF Dial heading works on a simple 0 - 360, but the Needle works on -179.9 to 0 to 179.9 0 being at the top, -179 being to the left and +179 to the right. Will I need to write the needle differently?
Yes, but i woudl try somethink like
case that with the -179 to 179:
val = val + 179;
than you have your 0 in the -179 positon.
but!!
if (val >=0)
{
val = ( val+1);
}
Ah ha, then I can use the 360degress divided by how many steps the motor has in 360deg. I would never have thought of that.
Thank you.
So now I have:
case FS_ADF1RELATIVEBEARING:
val = val + 179;
if (val >=0)
{
val = (val+1);
}
printf("ADF relative bearing %d\n", val);
FsbusWriteFmtVar(29,80,val);
break;
Any idea why it's still not showing anything is the DOS box for the print function?
is a change on FS_ADF1RELATIVEBEARING?
Yes, when I input the NDB frequency, the needle swings around. In FSInterrogate, this produces changes. My understanding is that there should be a value to print somewhere between -179.9 to 179.9 that should be displayed. (it should be between 0 and 360 with the changes you suggested).
Yes it has to show something between 0 and 360.
Why it donīt do it, i donīt know. The code looks ok. but i donīt test it with a compiler.
Stefan
Can't get my head around why it won't show anything either. Perhaps it's because it's after midnight here and I think my brain is fried for the night. I will look at again in the morning and see if I can make any sense of it.
Thanks again.
Stefan,
The steppers I have are 7.5 deg (48 steps) with the gearing I have, it takes 12 revolutions of the stepper for 360 degrees on both the needle and the rose face, so by my understanding, there are 576 steps for 360 deg.
So how would I reflect this in the code?
Thanks
For the ADF compass rose, I have this code:
Then for the ADF relative Bearing needle:Code:case FS_ADF1DIALBEARING:
val=val/0.625; // 360° are 576 steps (48 steps for 1 revolution on the stepper, and 12 revolution for 360 deg) (360/576) **this is line (38) in the warning message below
printf("ADF dial bearing, val=%d\n", val);
FsbusWriteFmtVar(30,80,val);
break;
Is this correct? Also, I am getting two warnings (still compling)(obviously it's not right or I guess I wouldn't be getting these messages):Code:case FS_ADF1RELATIVEBEARING:
x = val + 179;
if (x >=0)
{
x = (x+1);
}
printf("%d\n", val);
FsbusWriteFmtVar(29,80,x/0.625);// This is line (33) in the warning below
break;
steppergauges.cpp(33) : warning C4244: 'argument' : conversion from 'double' to 'int', possible loss of data
steppergauges.cpp(38) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
Linking...
Thanks
David
That is my Code Idea for case FS_ADF1RELATIVEBEARING.
Non tested!!!!!Code:static int ADF1RelDataIn;
static int ADF1RelDataSave;
static int ADF1RelDataDif;
static int ADF1RelNeedlegoto;
static int ADF1RelNeedleSave;
static int ADF1RelNeedleDif;
static int ADF1RelNeedleMulti;
static int ADF1RelNeedleDeg = 360;
static int ADF1RelNeedleStep = 576;
case FS_ADF1RELATIVEBEARING:
ADF1RelNeedleMulti = ADF1RelNeedleDeg / ADF1RelNeedleStep;
ADF1RelDataIn = val + 179;
if (ADF1RelDataIn >=0)
{
ADF1RelDataIn = (ADF1RelDataIn+1);
}
ADF1RelDataDif = ADF1RelDataIn - ADF1RelDataSave;
ADF1RelNeedleDif = ADF1RelDataDif / ADF1RelNeedleMulti;
ADF1RelNeedlegoto = ADF1RelNeedleSave + ADF1RelNeedleDif;
FsbusWriteFmtVar(29,80,ADF1RelNeedlegoto);
ADF1RelNeedleSave = ADF1RelNeedlegoto;
ADF1RelDataSave = ADF1RelDataIn;
break;
Wow, that's a lot more complex.
I'm looking forward to trying it out.
I'll let you know as soon as I can test it.
One question: Why is there the two lines of code after the FsbusWriteFmtVar line ie:
ADF1RelNeedleSave = ADF1RelNeedlegoto;
ADF1RelDataSave = ADF1RelDataIn;
break;
I can understand (I think) the rest of the code (very clever!).
Thanks Stefan.
David
i calculate the difference to the last event, so i dont have problems with back turning on a change from 355° to 010° and other situations.
With the last two lines i save the current status.
Stefan
Hi Stefan,
I've put the code into my project, compiles fine.
I still cannot get a value using printf. My concern is that there is no value being read (FSInterrogate shows the value changing as the needle moves, but the FsBus Dos box does not show any value.
Does this indicate that there is 'no' value coming into the code for it to be used?
So I am getting no value for either of the two offsets I'm using:
MkFsObject(FS_ADF1RELATIVEBEARING,"ADF Needle", cbSteppergauges, 0x0C6A, 2, TP_I16, FS_NORMAL,0);
MkFsObject(FS_ADF1DIALBEARING,"ADF Compass Card", cbSteppergauges, 0x0C6C, 2, TP_I16, FS_NORMAL,0);
So I feel something is wrong in the code that it is showing no value.
Thanks
David
Just another point, in the DOS box when FsBus is running, it now displays the following:
FSBUS.DLL (take out the version number)
www.fsbus.de
FS objects ......... 62
enabled .................... 62
disabled ................... 0
polling .................... lazy:0, normal:55, quick:4
FSBUS objects ...... 128
enabled .................... 128
disabled ................... 0
button,switch .............. 47
rotary ..................... 13
analog in .................. 0
led, digital out ........... 35
7 segment display .......... 18
servo, analog out .......... 15
stepper .................... 0
Timer objects ...... 0
Sound objects ...... 0
running ...Altimeter Feet 5
press any key to exit ...
It now shows what is connected. Is this information gathered from the code? If so, it doesn't seem to recognise that I have 3 steppers attached.
Also, just to be sure the steppers were working, I redid the little motor test code, and it all worked fine.
David
Here's just another bit of info that may help.
I did some experimenting with printf.
If I put a basic line like: printf("whiskeycompass"); in any other .cpp file, it displays it in the dos box, when I put it into the Stepper gauges .cpp file, it does not show it in the dos box. (hope that makes sense). It is almost like the steppergauges.cpp file is not being included in the project.
Does that help any?
Wrong!
void cbSteppergauges(int oid, int val, double dval);
Right!!!
void cbSteppergauges(int oid, int val, double dval)
With the ";" you close the function.
Hmmm, I've had some success.
I've taken the code out of the steppergauges.cpp files and put it into gauges.cpp (which I know works, and the printf works)
So this is the code I have so far in this file:
case FS_ALTIMETERFEET:
val=val/5; // 1000feet for 360° are 200 steps (1000/200)
printf("Altimeter Feet %d\n", val);
FsbusWriteFmtVar(8, 80,val);
break;
case FS_ADF1DIALBEARING:
x=0.625;(I have 576 steps to 360 degrees, which means for each degree it's 0.6 of a step)
val=val/x; (When I do it like this, I have a compiling warning, so obviously this is wrong)
FsbusWriteFmtVar(30,80,val);
printf("ADF Dial Bearing %d/n",val);
break;
So now I'm getting data with the printf.
The stepper for the Altitude does not correlate with the altimeter on the screen, and it's randomly moving forwards and backwards. When it zeros itself on start up, the stepper is smooth and accurate to the zero. Any thoughts?
yes analyse the data and build a calibration.
Edit:
case FS_ADF1DIALBEARING:
Work like the same code that i send if my code workes.
Some feedback from the code you put together for me:
case FS_ADF1RELATIVEBEARING:
ADF1RelNeedleMulti = ADF1RelNeedleDeg / ADF1RelNeedleStep;
ADF1RelDataIn = val + 179;
if (ADF1RelDataIn >=0)
{
ADF1RelDataIn = (ADF1RelDataIn+1);
}
ADF1RelDataDif = ADF1RelDataIn - ADF1RelDataSave;
ADF1RelNeedleDif = ADF1RelDataDif / ADF1RelNeedleMulti;
ADF1RelNeedlegoto = ADF1RelNeedleSave + ADF1RelNeedleDif;
FsbusWriteFmtVar(29,80,ADF1RelNeedlegoto);
printf("Relative Bearing %d/n",ADF1RelNeedlegoto);
ADF1RelNeedleSave = ADF1RelNeedlegoto;
ADF1RelDataSave = ADF1RelDataIn;
break;
I am getting an error: > Davids Flight sim.exe!cbGauges(int oid=510, int val=6140, double dval=0.00000000000000000) Line 209 + 0x6 bytes C++
Line 209 is: ADF1RelNeedleDif = ADF1RelDataDif / ADF1RelNeedleMulti;
I am getting data in, here is the datum:
ADF1RelDataDif 6320 int
ADF1RelDataIn 6320 int
ADF1RelDataSave 0 int
ADF1RelNeedleDif 0 int
ADF1RelNeedleMulti 0 int
Unhandled exception at 0x0041282d in Davids Flight sim.exe: 0xC0000094: Integer division by zero.
Next question is how do I use the calibrate function in this situation using steppers?
Yes, that is stupid.Quote:
Integer division by zero.
you said that the data range is -179 to 179 but the read value is 6140 or 6320.
Please find the right data range in fsuipc.
Than we can start to fix the code.Code:case FS_ADF1RELATIVEBEARING:
printf("Data in: %d/n",val);
break;
like servos, Analog In or Out.Quote:
Next question is how do I use the calibrate function in this situation using steppers?
But not at looping situations, like Compas, RMI,.....
Stefan
It's giving a different range using the printf than in FSInterrogate.
at 12 o'clock = 0
at 3 o'clock = 16400
at 6 o'clock =-32780 or 32780
at 9 o'clock = -16400
As for the calibrate function, all these gauges are looping types.
The ADF compass rose face is producing this data with the printf:
North 360/0
E 90
S 180
W 270
So 360 degrees and I have 576 steps for this one too.
Try code like that to stop the division by Zero.
Code:case FS_ADF1RELATIVEBEARING:
ADF1RelNeedleMulti = (1000 * ADF1RelNeedleDeg) / ADF1RelNeedleStep;
ADF1RelDataIn = val + 32780;
// if (ADF1RelDataIn >=0)
// {
// ADF1RelDataIn = (ADF1RelDataIn+1);
// }
ADF1RelDataDif = ADF1RelDataIn - ADF1RelDataSave;
ADF1RelNeedleDif = (ADF1RelDataDif * 1000) / ADF1RelNeedleMulti;
ADF1RelNeedlegoto = ADF1RelNeedleSave + ADF1RelNeedleDif;
FsbusWriteFmtVar(29,80,ADF1RelNeedlegoto/1000);
ADF1RelNeedleSave = ADF1RelNeedlegoto;
ADF1RelDataSave = ADF1RelDataIn;
break;
Implemented the changed code and the printf produces '26' regardless of the needle position.
Odd!