Add normalized control surface positions to net_fdm.hxx structure.
Convert several double values to float since the extra precision is not needed and it just wastes network bandwidth.
This commit is contained in:
parent
14bb4cce37
commit
a47f8cabab
3 changed files with 153 additions and 99 deletions
src/Network
|
@ -152,7 +152,7 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
|
||||||
tempnode = fgGetNode("/controls/gear", true);
|
tempnode = fgGetNode("/controls/gear", true);
|
||||||
for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
|
for ( i = 0; i < FGNetCtrls::FG_MAX_WHEELS; ++i ) {
|
||||||
node = fgGetNode("/controls/gear/wheel", i);
|
node = fgGetNode("/controls/gear/wheel", i);
|
||||||
if ( node->getChild("brake") != 0 ) {
|
if ( node->getChild("brake") != NULL ) {
|
||||||
if ( tempnode->getChild("parking-brake")->getDoubleValue() > 0.0 ) {
|
if ( tempnode->getChild("parking-brake")->getDoubleValue() > 0.0 ) {
|
||||||
net->brake[i] = 1.0;
|
net->brake[i] = 1.0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -165,9 +165,18 @@ void FGProps2NetCtrls( FGNetCtrls *net, bool net_byte_order ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
node = fgGetNode("/controls/switches", true);
|
node = fgGetNode("/controls/switches", true);
|
||||||
net->master_bat = node->getChild("master-bat")->getBoolValue();
|
tempnode = node->getChild("master-bat");
|
||||||
net->master_alt = node->getChild("master-alt")->getBoolValue();
|
if ( tempnode != NULL ) {
|
||||||
net->master_avionics = node->getChild("master-avionics")->getBoolValue();
|
net->master_bat = tempnode->getBoolValue();
|
||||||
|
}
|
||||||
|
tempnode = node->getChild("master-alt");
|
||||||
|
if ( tempnode != NULL ) {
|
||||||
|
net->master_alt = tempnode->getBoolValue();
|
||||||
|
}
|
||||||
|
tempnode = node->getChild("master-avionics");
|
||||||
|
if ( tempnode != NULL ) {
|
||||||
|
net->master_avionics = tempnode->getBoolValue();
|
||||||
|
}
|
||||||
|
|
||||||
net->wind_speed_kt = fgGetDouble("/environment/wind-speed-kt");
|
net->wind_speed_kt = fgGetDouble("/environment/wind-speed-kt");
|
||||||
net->wind_dir_deg = fgGetDouble("/environment/wind-from-heading-deg");
|
net->wind_dir_deg = fgGetDouble("/environment/wind-from-heading-deg");
|
||||||
|
|
|
@ -70,6 +70,22 @@ static void htond (double &x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Float version
|
||||||
|
static void htonf (float &x)
|
||||||
|
{
|
||||||
|
if ( sgIsLittleEndian() ) {
|
||||||
|
int *Float_Overlay;
|
||||||
|
int Holding_Buffer;
|
||||||
|
|
||||||
|
Float_Overlay = (int *) &x;
|
||||||
|
Holding_Buffer = Float_Overlay [0];
|
||||||
|
|
||||||
|
Float_Overlay [0] = htonl (Holding_Buffer);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FGNativeFDM::FGNativeFDM() {
|
FGNativeFDM::FGNativeFDM() {
|
||||||
}
|
}
|
||||||
|
@ -168,14 +184,21 @@ void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
|
||||||
net->wow[i] = node->getDoubleValue("wow");
|
net->wow[i] = node->getDoubleValue("wow");
|
||||||
}
|
}
|
||||||
|
|
||||||
// cout << "Flap deflection = " << aero->dflap << endl;
|
|
||||||
net->flap_deflection = fgGetDouble("/surface-positions/flap-pos-norm" );
|
|
||||||
|
|
||||||
// the following really aren't used in this context
|
// the following really aren't used in this context
|
||||||
net->cur_time = globals->get_time_params()->get_cur_time();
|
net->cur_time = globals->get_time_params()->get_cur_time();
|
||||||
net->warp = globals->get_warp();
|
net->warp = globals->get_warp();
|
||||||
net->visibility = fgGetDouble("/environment/visibility-m");
|
net->visibility = fgGetDouble("/environment/visibility-m");
|
||||||
|
|
||||||
|
// Control surface positions
|
||||||
|
SGPropertyNode *node = fgGetNode("/surface-positions", true);
|
||||||
|
net->elevator = node->getDoubleValue( "elevator-pos-norm" );
|
||||||
|
net->flaps = node->getDoubleValue( "flap-pos-norm" );
|
||||||
|
net->left_aileron = node->getDoubleValue( "left-aileron-pos-norm" );
|
||||||
|
net->right_aileron = node->getDoubleValue( "right-aileron-pos-norm" );
|
||||||
|
net->rudder = node->getDoubleValue( "rudder-pos-norm" );
|
||||||
|
net->speedbrake = node->getDoubleValue( "speedbrake-pos-norm" );
|
||||||
|
net->spoilers = node->getDoubleValue( "spoilers-pos-norm" );
|
||||||
|
|
||||||
if ( net_byte_order ) {
|
if ( net_byte_order ) {
|
||||||
// Convert the net buffer to network format
|
// Convert the net buffer to network format
|
||||||
net->version = htonl(net->version);
|
net->version = htonl(net->version);
|
||||||
|
@ -183,39 +206,40 @@ void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
|
||||||
htond(net->longitude);
|
htond(net->longitude);
|
||||||
htond(net->latitude);
|
htond(net->latitude);
|
||||||
htond(net->altitude);
|
htond(net->altitude);
|
||||||
htond(net->phi);
|
htonf(net->agl);
|
||||||
htond(net->theta);
|
htonf(net->phi);
|
||||||
htond(net->psi);
|
htonf(net->theta);
|
||||||
|
htonf(net->psi);
|
||||||
|
|
||||||
htond(net->phidot);
|
htonf(net->phidot);
|
||||||
htond(net->thetadot);
|
htonf(net->thetadot);
|
||||||
htond(net->psidot);
|
htonf(net->psidot);
|
||||||
htond(net->vcas);
|
htonf(net->vcas);
|
||||||
htond(net->climb_rate);
|
htonf(net->climb_rate);
|
||||||
htond(net->v_north);
|
htonf(net->v_north);
|
||||||
htond(net->v_east);
|
htonf(net->v_east);
|
||||||
htond(net->v_down);
|
htonf(net->v_down);
|
||||||
htond(net->v_wind_body_north);
|
htonf(net->v_wind_body_north);
|
||||||
htond(net->v_wind_body_east);
|
htonf(net->v_wind_body_east);
|
||||||
htond(net->v_wind_body_down);
|
htonf(net->v_wind_body_down);
|
||||||
htond(net->stall_warning);
|
htonf(net->stall_warning);
|
||||||
|
|
||||||
htond(net->A_X_pilot);
|
htonf(net->A_X_pilot);
|
||||||
htond(net->A_Y_pilot);
|
htonf(net->A_Y_pilot);
|
||||||
htond(net->A_Z_pilot);
|
htonf(net->A_Z_pilot);
|
||||||
|
|
||||||
for ( i = 0; i < net->num_engines; ++i ) {
|
for ( i = 0; i < net->num_engines; ++i ) {
|
||||||
htonl(net->eng_state[i]);
|
htonl(net->eng_state[i]);
|
||||||
htond(net->rpm[i]);
|
htonf(net->rpm[i]);
|
||||||
htond(net->fuel_flow[i]);
|
htonf(net->fuel_flow[i]);
|
||||||
htond(net->EGT[i]);
|
htonf(net->EGT[i]);
|
||||||
htond(net->oil_temp[i]);
|
htonf(net->oil_temp[i]);
|
||||||
htond(net->oil_px[i]);
|
htonf(net->oil_px[i]);
|
||||||
}
|
}
|
||||||
net->num_engines = htonl(net->num_engines);
|
net->num_engines = htonl(net->num_engines);
|
||||||
|
|
||||||
for ( i = 0; i < net->num_tanks; ++i ) {
|
for ( i = 0; i < net->num_tanks; ++i ) {
|
||||||
htond(net->fuel_quantity[i]);
|
htonf(net->fuel_quantity[i]);
|
||||||
}
|
}
|
||||||
net->num_tanks = htonl(net->num_tanks);
|
net->num_tanks = htonl(net->num_tanks);
|
||||||
|
|
||||||
|
@ -223,11 +247,18 @@ void FGProps2NetFDM( FGNetFDM *net, bool net_byte_order ) {
|
||||||
net->wow[i] = htonl(net->wow[i]);
|
net->wow[i] = htonl(net->wow[i]);
|
||||||
}
|
}
|
||||||
net->num_wheels = htonl(net->num_wheels);
|
net->num_wheels = htonl(net->num_wheels);
|
||||||
htond(net->flap_deflection);
|
|
||||||
|
|
||||||
net->cur_time = htonl( net->cur_time );
|
net->cur_time = htonl( net->cur_time );
|
||||||
net->warp = htonl( net->warp );
|
net->warp = htonl( net->warp );
|
||||||
htond(net->visibility);
|
htonf(net->visibility);
|
||||||
|
|
||||||
|
htonf(net->elevator);
|
||||||
|
htonf(net->flaps);
|
||||||
|
htonf(net->left_aileron);
|
||||||
|
htonf(net->right_aileron);
|
||||||
|
htonf(net->rudder);
|
||||||
|
htonf(net->speedbrake);
|
||||||
|
htonf(net->spoilers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,50 +273,58 @@ void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order ) {
|
||||||
htond(net->longitude);
|
htond(net->longitude);
|
||||||
htond(net->latitude);
|
htond(net->latitude);
|
||||||
htond(net->altitude);
|
htond(net->altitude);
|
||||||
htond(net->phi);
|
htonf(net->agl);
|
||||||
htond(net->theta);
|
htonf(net->phi);
|
||||||
htond(net->psi);
|
htonf(net->theta);
|
||||||
|
htonf(net->psi);
|
||||||
|
|
||||||
htond(net->phidot);
|
htonf(net->phidot);
|
||||||
htond(net->thetadot);
|
htonf(net->thetadot);
|
||||||
htond(net->psidot);
|
htonf(net->psidot);
|
||||||
htond(net->vcas);
|
htonf(net->vcas);
|
||||||
htond(net->climb_rate);
|
htonf(net->climb_rate);
|
||||||
htond(net->v_north);
|
htonf(net->v_north);
|
||||||
htond(net->v_east);
|
htonf(net->v_east);
|
||||||
htond(net->v_down);
|
htonf(net->v_down);
|
||||||
htond(net->v_wind_body_north);
|
htonf(net->v_wind_body_north);
|
||||||
htond(net->v_wind_body_east);
|
htonf(net->v_wind_body_east);
|
||||||
htond(net->v_wind_body_down);
|
htonf(net->v_wind_body_down);
|
||||||
htond(net->stall_warning);
|
htonf(net->stall_warning);
|
||||||
|
|
||||||
htond(net->A_X_pilot);
|
htonf(net->A_X_pilot);
|
||||||
htond(net->A_Y_pilot);
|
htonf(net->A_Y_pilot);
|
||||||
htond(net->A_Z_pilot);
|
htonf(net->A_Z_pilot);
|
||||||
|
|
||||||
net->num_engines = htonl(net->num_engines);
|
net->num_engines = htonl(net->num_engines);
|
||||||
for ( i = 0; i < net->num_engines; ++i ) {
|
for ( i = 0; i < net->num_engines; ++i ) {
|
||||||
htonl(net->eng_state[i]);
|
htonl(net->eng_state[i]);
|
||||||
htond(net->rpm[i]);
|
htonf(net->rpm[i]);
|
||||||
htond(net->fuel_flow[i]);
|
htonf(net->fuel_flow[i]);
|
||||||
htond(net->EGT[i]);
|
htonf(net->EGT[i]);
|
||||||
htond(net->oil_temp[i]);
|
htonf(net->oil_temp[i]);
|
||||||
htond(net->oil_px[i]);
|
htonf(net->oil_px[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
net->num_tanks = htonl(net->num_tanks);
|
net->num_tanks = htonl(net->num_tanks);
|
||||||
for ( i = 0; i < net->num_tanks; ++i ) {
|
for ( i = 0; i < net->num_tanks; ++i ) {
|
||||||
htond(net->fuel_quantity[i]);
|
htonf(net->fuel_quantity[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
net->num_wheels = htonl(net->num_wheels);
|
net->num_wheels = htonl(net->num_wheels);
|
||||||
// I don't need to convert the Wow flags, since they are one
|
// I don't need to convert the Wow flags, since they are one
|
||||||
// byte in size
|
// byte in size
|
||||||
htond(net->flap_deflection);
|
|
||||||
|
|
||||||
net->cur_time = ntohl(net->cur_time);
|
net->cur_time = ntohl(net->cur_time);
|
||||||
net->warp = ntohl(net->warp);
|
net->warp = ntohl(net->warp);
|
||||||
htond(net->visibility);
|
htonf(net->visibility);
|
||||||
|
|
||||||
|
htonf(net->elevator);
|
||||||
|
htonf(net->flaps);
|
||||||
|
htonf(net->left_aileron);
|
||||||
|
htonf(net->right_aileron);
|
||||||
|
htonf(net->rudder);
|
||||||
|
htonf(net->speedbrake);
|
||||||
|
htonf(net->spoilers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( net->version == FG_NET_FDM_VERSION ) {
|
if ( net->version == FG_NET_FDM_VERSION ) {
|
||||||
|
@ -353,17 +392,6 @@ void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order ) {
|
||||||
node->setDoubleValue("wow", net->wow[i] );
|
node->setDoubleValue("wow", net->wow[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
fgSetDouble("/surface-positions/flap-pos-norm", net->flap_deflection);
|
|
||||||
SGPropertyNode * node = fgGetNode("/controls", true);
|
|
||||||
fgSetDouble("/surface-positions/elevator-pos-norm",
|
|
||||||
node->getDoubleValue( "elevator" ));
|
|
||||||
fgSetDouble("/surface-positions/rudder-pos-norm",
|
|
||||||
node->getDoubleValue( "rudder" ));
|
|
||||||
fgSetDouble("/surface-positions/left-aileron-pos-norm",
|
|
||||||
node->getDoubleValue( "aileron" ));
|
|
||||||
fgSetDouble("/surface-positions/right-aileron-pos-norm",
|
|
||||||
-node->getDoubleValue( "aileron" ));
|
|
||||||
|
|
||||||
/* these are ignored for now ... */
|
/* these are ignored for now ... */
|
||||||
/*
|
/*
|
||||||
if ( net->cur_time ) {
|
if ( net->cur_time ) {
|
||||||
|
@ -373,6 +401,15 @@ void FGNetFDM2Props( FGNetFDM *net, bool net_byte_order ) {
|
||||||
globals->set_warp( net->warp );
|
globals->set_warp( net->warp );
|
||||||
last_warp = net->warp;
|
last_warp = net->warp;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
SGPropertyNode *node = fgGetNode("/surface-positions", true);
|
||||||
|
node->setDoubleValue("elevator-pos-norm", net->elevator);
|
||||||
|
node->setDoubleValue("flap-pos-norm", net->flaps);
|
||||||
|
node->setDoubleValue("left-aileron-pos-norm", net->left_aileron);
|
||||||
|
node->setDoubleValue("right-aileron-pos-norm", net->right_aileron);
|
||||||
|
node->setDoubleValue("rudder-pos-norm", net->rudder);
|
||||||
|
node->setDoubleValue("speedbrake-pos-norm", net->speedbrake);
|
||||||
|
node->setDoubleValue("spoilers-pos-norm", net->spoilers);
|
||||||
} else {
|
} else {
|
||||||
SG_LOG( SG_IO, SG_ALERT,
|
SG_LOG( SG_IO, SG_ALERT,
|
||||||
"Error: version mismatch in FGNetFDM2Props()" );
|
"Error: version mismatch in FGNetFDM2Props()" );
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#include <time.h> // time_t
|
#include <time.h> // time_t
|
||||||
|
|
||||||
const int FG_NET_FDM_VERSION = 11;
|
const int FG_NET_FDM_VERSION = 12;
|
||||||
|
|
||||||
|
|
||||||
// Define a structure containing the top level flight dynamics model
|
// Define a structure containing the top level flight dynamics model
|
||||||
|
@ -58,59 +58,67 @@ public:
|
||||||
double longitude; // geodetic (radians)
|
double longitude; // geodetic (radians)
|
||||||
double latitude; // geodetic (radians)
|
double latitude; // geodetic (radians)
|
||||||
double altitude; // above sea level (meters)
|
double altitude; // above sea level (meters)
|
||||||
double agl; // above ground level (meters)
|
float agl; // above ground level (meters)
|
||||||
double phi; // roll (radians)
|
float phi; // roll (radians)
|
||||||
double theta; // pitch (radians)
|
float theta; // pitch (radians)
|
||||||
double psi; // yaw or true heading (radians)
|
float psi; // yaw or true heading (radians)
|
||||||
|
|
||||||
// Velocities
|
// Velocities
|
||||||
double phidot; // roll rate (radians/sec)
|
float phidot; // roll rate (radians/sec)
|
||||||
double thetadot; // pitch rate (radians/sec)
|
float thetadot; // pitch rate (radians/sec)
|
||||||
double psidot; // yaw rate (radians/sec)
|
float psidot; // yaw rate (radians/sec)
|
||||||
double vcas; // calibrated airspeed
|
float vcas; // calibrated airspeed
|
||||||
double climb_rate; // feet per second
|
float climb_rate; // feet per second
|
||||||
double v_north; // north velocity in local/body frame, fps
|
float v_north; // north velocity in local/body frame, fps
|
||||||
double v_east; // east velocity in local/body frame, fps
|
float v_east; // east velocity in local/body frame, fps
|
||||||
double v_down; // down/vertical velocity in local/body frame, fps
|
float v_down; // down/vertical velocity in local/body frame, fps
|
||||||
double v_wind_body_north; // north velocity in local/body frame
|
float v_wind_body_north; // north velocity in local/body frame
|
||||||
// relative to local airmass, fps
|
// relative to local airmass, fps
|
||||||
double v_wind_body_east; // east velocity in local/body frame
|
float v_wind_body_east; // east velocity in local/body frame
|
||||||
// relative to local airmass, fps
|
// relative to local airmass, fps
|
||||||
double v_wind_body_down; // down/vertical velocity in local/body
|
float v_wind_body_down; // down/vertical velocity in local/body
|
||||||
// frame relative to local airmass, fps
|
// frame relative to local airmass, fps
|
||||||
|
|
||||||
// Stall
|
// Stall
|
||||||
double stall_warning; // 0.0 - 1.0 indicating the amount of stall
|
float stall_warning; // 0.0 - 1.0 indicating the amount of stall
|
||||||
|
|
||||||
// Accelerations
|
// Accelerations
|
||||||
double A_X_pilot; // X accel in body frame ft/sec^2
|
float A_X_pilot; // X accel in body frame ft/sec^2
|
||||||
double A_Y_pilot; // Y accel in body frame ft/sec^2
|
float A_Y_pilot; // Y accel in body frame ft/sec^2
|
||||||
double A_Z_pilot; // Z accel in body frame ft/sec^2
|
float A_Z_pilot; // Z accel in body frame ft/sec^2
|
||||||
|
|
||||||
// Pressure
|
// Pressure
|
||||||
|
|
||||||
// Engine status
|
// Engine status
|
||||||
int num_engines; // Number of valid engines
|
int num_engines; // Number of valid engines
|
||||||
int eng_state[FG_MAX_ENGINES]; // Engine state (off, cranking, running)
|
int eng_state[FG_MAX_ENGINES]; // Engine state (off, cranking, running)
|
||||||
double rpm[FG_MAX_ENGINES]; // Engine RPM rev/min
|
float rpm[FG_MAX_ENGINES]; // Engine RPM rev/min
|
||||||
double fuel_flow[FG_MAX_ENGINES]; // Fuel flow gallons/hr
|
float fuel_flow[FG_MAX_ENGINES]; // Fuel flow gallons/hr
|
||||||
double EGT[FG_MAX_ENGINES]; // Exhuast gas temp deg F
|
float EGT[FG_MAX_ENGINES]; // Exhuast gas temp deg F
|
||||||
double oil_temp[FG_MAX_ENGINES]; // Oil temp deg F
|
float oil_temp[FG_MAX_ENGINES]; // Oil temp deg F
|
||||||
double oil_px[FG_MAX_ENGINES]; // Oil pressure psi
|
float oil_px[FG_MAX_ENGINES]; // Oil pressure psi
|
||||||
|
|
||||||
// Consumables
|
// Consumables
|
||||||
int num_tanks; // Max number of fuel tanks
|
int num_tanks; // Max number of fuel tanks
|
||||||
double fuel_quantity[FG_MAX_TANKS];
|
float fuel_quantity[FG_MAX_TANKS];
|
||||||
|
|
||||||
// Gear and flaps status
|
// Gear status
|
||||||
int num_wheels;
|
int num_wheels;
|
||||||
bool wow[FG_MAX_WHEELS];
|
bool wow[FG_MAX_WHEELS];
|
||||||
double flap_deflection; // normalized from 0 = up to 1 = full deflection
|
|
||||||
|
|
||||||
// Environment
|
// Environment
|
||||||
time_t cur_time; // current unix time
|
time_t cur_time; // current unix time
|
||||||
long int warp; // offset in seconds to unix time
|
long int warp; // offset in seconds to unix time
|
||||||
double visibility; // visibility in meters (for env. effects)
|
float visibility; // visibility in meters (for env. effects)
|
||||||
|
|
||||||
|
// Control surface positions (normalized values)
|
||||||
|
float elevator;
|
||||||
|
float flaps;
|
||||||
|
float left_aileron;
|
||||||
|
float right_aileron;
|
||||||
|
float rudder;
|
||||||
|
float speedbrake;
|
||||||
|
float spoilers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue