[RESOLVED] Is there a way to tell if youre in a cloud?

seippg
Posts: 34
Joined: Mon May 12, 2014 10:33 pm

[RESOLVED] Is there a way to tell if youre in a cloud?

Postby seippg » Mon Sep 04, 2017 1:33 pm

Hi,

I'm trying to use SimConnect to determine if my aircraft is in a cloud. I've tried...

[*] reading "AMBIENT IN CLOUD" with SimConnect_AddToDataDefinition and then reading the value, which seems to be 0 always.
[*] reading "AMBIENT VISIBILITY", which seems to be either 0 or a large value with no correlation to whether I'm in a cloud or not.
[*] using SimConnect_WeatherRequestCloudState but I only get all 1s or all 0s with no correlation to whether I'm in a cloud or not.

Either I'm doing something wrong or there are certain constraints to calling these functions, or they don't work through SimConnect. I'm also wondering if there's another method, a workaround, etc. that I could use. Seems like the sim must know whether or not an airplane is in a cloud.

Gregg

User avatar
Rob McCarthy
Lockheed Martin
Posts: 915
Joined: Wed Aug 24, 2011 1:37 pm

Re: Is there a way to tell if youre in a cloud?

Postby Rob McCarthy » Wed Sep 06, 2017 12:55 pm

The "AMBIENT IN CLOUD" simvar should be functioning correctly. The TaggedData sample in the SDK is a good example on setting up SimVar reading with SimConnect.

Regards,
Rob McCarthy
Rob McCarthy
Prepar3D® Core Lead

seippg
Posts: 34
Joined: Mon May 12, 2014 10:33 pm

Re: Is there a way to tell if youre in a cloud?

Postby seippg » Wed Sep 06, 2017 5:31 pm

The "AMBIENT IN CLOUD" simvar should be functioning correctly. The TaggedData sample in the SDK is a good example on setting up SimVar reading with SimConnect.

Regards,
Rob McCarthy
Okay, I'll take a look at that example.

seippg
Posts: 34
Joined: Mon May 12, 2014 10:33 pm

Re: Is there a way to tell if youre in a cloud?

Postby seippg » Thu Sep 07, 2017 3:41 am

The "AMBIENT IN CLOUD" simvar should be functioning correctly. The TaggedData sample in the SDK is a good example on setting up SimVar reading with SimConnect.

Regards,
Rob McCarthy
Hmmm...

Looking at that code, I did mine a little different. I created a structure...

struct Struct_7
{
double latitude;
double longitude;
double altitude;
double heading;
double wingSpan;
double altAGL; //feet
double gForce;
double cruiseSpeed;
double weight;
double windVelocity;
bool inCloud;
int metersVisibility;
};

I then do this...

hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Plane Latitude", "degrees");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Plane Longitude", "degrees");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Plane Altitude", "feet");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "PLANE HEADING DEGREES TRUE", "degrees");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Wing Span", "feet");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Plane Alt Above Ground", "feet");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "G Force", "GForce");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Estimated Cruise Speed", "feet per second");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Total Weight", "Pounds");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Ambient Wind Velocity", "knots");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "AMBIENT IN CLOUD", "BOOL");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "AMBIENT VISIBILITY", "METERS");

I subscribe to the 6Hz event:

hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_6HZ_TIMER, "6Hz");

and then, inside the 6Hz event I request the LLA:

hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_LLA, DEFINITION_LLA, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_ONCE, 0, 0, 0, 0);

and then inside the callback...

case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
{
SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;

switch (pObjData->dwRequestID)
{
case REQUEST_LLA:
{
Struct_7 *pS = (Struct_7*)&pObjData->dwData;

When I read pS, all the values above pS->inCloud are filled in correctly. Is there any reason that wouldn't work? Do I need to separate out the smaller request as is done in the TaggedData example?

Gregg

User avatar
Rob McCarthy
Lockheed Martin
Posts: 915
Joined: Wed Aug 24, 2011 1:37 pm

Re: Is there a way to tell if youre in a cloud?

Postby Rob McCarthy » Thu Sep 07, 2017 2:57 pm

That should function correctly. You may need to specify the SIMCONNECT_DATATYPE. The DataHarvester sample sets things up similar to how you're doing here.

Regards,
Rob McCarthy
Rob McCarthy
Prepar3D® Core Lead

Naruto-kun
Posts: 183
Joined: Mon Jan 09, 2012 6:44 pm

Re: Is there a way to tell if youre in a cloud?

Postby Naruto-kun » Thu Sep 07, 2017 3:33 pm

Try using non capital letters for the unit type? I don't think it is case sensitive but try anyway.

seippg
Posts: 34
Joined: Mon May 12, 2014 10:33 pm

Re: Is there a way to tell if youre in a cloud?

Postby seippg » Thu Sep 07, 2017 8:28 pm

That should function correctly. You may need to specify the SIMCONNECT_DATATYPE. The DataHarvester sample sets things up similar to how you're doing here.

Regards,
Rob McCarthy
Okay I tried a simple change that didn't work. I modified my inCloud variable inside the struct to be an int and then changed the IN CLOUD line to add SIMCONNECT_DATATYPE_INT32. Loaded up the sim in a major thunderstorm and flew through several large or very large clouds. inCloud stayed 0. I will try a simpler request, isolating IN CLOUD.

Gregg

seippg
Posts: 34
Joined: Mon May 12, 2014 10:33 pm

Re: Is there a way to tell if youre in a cloud?

Postby seippg » Sat Sep 09, 2017 6:23 pm

That should function correctly. You may need to specify the SIMCONNECT_DATATYPE. The DataHarvester sample sets things up similar to how you're doing here.

Regards,
Rob McCarthy
Still no joy. I broke out the request for AMBIENT IN CLOUD into it's own request, it's on definition and it's own datastructer. As per Dataharvester, I requested a 'bool' but set the type to FLOAT32. I used the same options...once per sec but only if it changes. Checked the HR to make sure everything was working. I got a single call to my handler with the value set to -1 NaN. No other calls come through.

I then tried to use the TAGGED method used in DataHarvester and I do get calls...the value never changes...either 1 or 0. It doesn't only call when the value changes...it calls constantly, even though I specified to only send i if it changes. Flying into or out of a cloud with either method does not reflect the value sent.

Gregg

Naruto-kun
Posts: 183
Joined: Mon Jan 09, 2012 6:44 pm

Re: Is there a way to tell if youre in a cloud?

Postby Naruto-kun » Sun Sep 10, 2017 8:57 am

All simvars, including those of the bool unit type, are of type FLOAT64 aka double, except for strings and structs.

seippg
Posts: 34
Joined: Mon May 12, 2014 10:33 pm

Re: Is there a way to tell if youre in a cloud?

Postby seippg » Sun Sep 10, 2017 11:36 am

All simvars, including those of the bool unit type, are of type FLOAT64 aka double, except for strings and structs.
I changed it to FLOAT64...still no change. I'm in the middle of a large CB and the value is zero.

Clifton Crane
Lockheed Martin
Posts: 755
Joined: Tue Sep 25, 2012 2:34 pm

Re: Is there a way to tell if youre in a cloud?

Postby Clifton Crane » Wed Sep 13, 2017 10:39 pm

Hi Gregg,

The SimConnect_AddToDataDefinition functions need to align with the struct you have defined. This includes order as well as data type size. By default, the function sets the data type to FLOAT64. This does not align with the last two members of you struct. Also, the boolean value is only 16 bits which does not have a corresponding SIMCONNECT_DATA_TYPE enumeration. You can replace that boolean with an int for example and use the SIMCONNECT_DATA_TYPE_INT32 in the call to SimConnect_AddToDataDefiniton.

Hope this helps!
Clifton Crane
Prepar3D® Software Engineer

seippg
Posts: 34
Joined: Mon May 12, 2014 10:33 pm

Re: Is there a way to tell if youre in a cloud?

Postby seippg » Thu Sep 14, 2017 3:41 pm

Hi Gregg,

The SimConnect_AddToDataDefinition functions need to align with the struct you have defined. This includes order as well as data type size. By default, the function sets the data type to FLOAT64. This does not align with the last two members of you struct. Also, the boolean value is only 16 bits which does not have a corresponding SIMCONNECT_DATA_TYPE enumeration. You can replace that boolean with an int for example and use the SIMCONNECT_DATA_TYPE_INT32 in the call to SimConnect_AddToDataDefiniton.

Hope this helps!
Hi Clifton,

I think I tried that but I'll definitely give it another try to be sure. I'll report back.

Gregg

seippg
Posts: 34
Joined: Mon May 12, 2014 10:33 pm

Re: Is there a way to tell if youre in a cloud?

Postby seippg » Fri Sep 15, 2017 1:04 am

Hi Gregg,

The SimConnect_AddToDataDefinition functions need to align with the struct you have defined. This includes order as well as data type size. By default, the function sets the data type to FLOAT64. This does not align with the last two members of you struct. Also, the boolean value is only 16 bits which does not have a corresponding SIMCONNECT_DATA_TYPE enumeration. You can replace that boolean with an int for example and use the SIMCONNECT_DATA_TYPE_INT32 in the call to SimConnect_AddToDataDefiniton.

Hope this helps!
Yeah, I checked and that's the last thing I tried. Here's my struct:
struct Struct_7
{
double latitude;
double longitude;
double altitude;
double heading;
double wingSpan;
double altAGL; //feet
double gForce;
double cruiseSpeed;
double weight;
double windVelocity;
int inCloud;
int metersVisibility;
};
In my timer event I make these calls....
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Plane Latitude", "degrees");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Plane Longitude", "degrees");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Plane Altitude", "feet");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "PLANE HEADING DEGREES TRUE", "degrees");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Wing Span", "feet");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Plane Alt Above Ground", "feet");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "G Force", "GForce");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Estimated Cruise Speed", "feet per second");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Total Weight", "Pounds");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "Ambient Wind Velocity", "knots");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "AMBIENT IN CLOUD", "BOOL", SIMCONNECT_DATATYPE_INT32);
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "AMBIENT VISIBILITY", "METERS");
...everything fills in pefectly down to and including windVelocity.

I read the entire data structure here...
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
{
SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;

switch (pObjData->dwRequestID)
{
case REQUEST_LLA:
{
Struct_7 *pS = (Struct_7*)&pObjData->dwData;
I started my app and was flying below a broken layer and it was 1...I climbed up and went in and out of clouds clouds and it stayed 1. I restarted my app and it started at 0 and stayed at 0.

seippg
Posts: 34
Joined: Mon May 12, 2014 10:33 pm

Re: Is there a way to tell if youre in a cloud?

Postby seippg » Sun Sep 17, 2017 12:20 am

I got some success today. What I did was move the inCloud variable to the top of my structure.

struct Struct_7
{
int inCloud;
double latitude;
double longitude;
double altitude;
double heading;
double wingSpan;
double altAGL; //feet
double cruiseSpeed;
double weight;
double windVelocity;
};

and then made this call...

hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "AMBIENT IN CLOUD", "BOOL", SIMCONNECT_DATATYPE_INT32);

That threw all the variables below inCloud off so I knew something was up. I then changed inCloud to a double and changed the call to...

hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LLA, "AMBIENT IN CLOUD", "BOOL", SIMCONNECT_DATATYPE_FLOAT64);

Everything went back in line...all the variables look right again. So, moving the variable inside the structure and making it FLOAT64, as someone mentioned above, seemed to have solved it. After I got it working, I monitored the sim and the variable. It doesn't seem to be very accurate. Seems to say I'm in clouds much more than I am. Still, better than nothing. I think this item can mark it solved.

Gregg


Return to “Software Development Kit (SDK) Questions”

Who is online

Users browsing this forum: No registered users and 1 guest