-void FGAICarrier::UpdateFlols( double dt) {
-
- float trans[3][3];
- float in[3];
- float out[3];
-
- float cosRx, sinRx;
- float cosRy, sinRy;
- float cosRz, sinRz;
-
- double flolsXYZ[3], eyeXYZ[3];
- double lat, lon, alt;
- Point3D eyepos;
- Point3D flolspos;
-
-/* cout << "x_offset " << flols_x_offset
- << " y_offset " << flols_y_offset
- << " z_offset " << flols_z_offset << endl;
-
- cout << "roll " << roll
- << " heading " << hdg
- << " pitch " << pitch << endl;
-
- cout << "carrier lon " << pos[0]
- << " lat " << pos[1]
- << " alt " << pos[2] << endl;*/
-
-// set the Flols intitial position to the carrier position
-
- flolspos = pos;
-
-/* cout << "flols lon " << flolspos[0]
- << " lat " << flolspos[1]
- << " alt " << flolspos[2] << endl;*/
-
-// set the offsets in metres
-
-/* cout << "flols_x_offset " << flols_x_offset << endl
- << "flols_y_offset " << flols_y_offset << endl
- << "flols_z_offset " << flols_z_offset << endl;*/
-
- in[0] = flols_off.x();
- in[1] = flols_off.y();
- in[2] = flols_off.z();
-
-// pre-process the trig functions
-
- cosRx = cos(roll * SG_DEGREES_TO_RADIANS);
- sinRx = sin(roll * SG_DEGREES_TO_RADIANS);
- cosRy = cos(pitch * SG_DEGREES_TO_RADIANS);
- sinRy = sin(pitch * SG_DEGREES_TO_RADIANS);
- cosRz = cos(hdg * SG_DEGREES_TO_RADIANS);
- sinRz = sin(hdg * SG_DEGREES_TO_RADIANS);
-
-// set up the transform matrix
-
- trans[0][0] = cosRy * cosRz;
- trans[0][1] = -1 * cosRx * sinRz + sinRx * sinRy * cosRz ;
- trans[0][2] = sinRx * sinRz + cosRx * sinRy * cosRz;
-
- trans[1][0] = cosRy * sinRz;
- trans[1][1] = cosRx * cosRz + sinRx * sinRy * sinRz;
- trans[1][2] = -1 * sinRx * cosRx + cosRx * sinRy * sinRz;
-
- trans[2][0] = -1 * sinRy;
- trans[2][1] = sinRx * cosRy;
- trans[2][2] = cosRx * cosRy;
-
-// multiply the input and transform matrices
-
- out[0] = in[0] * trans[0][0] + in[1] * trans[0][1] + in[2] * trans[0][2];
- out[1] = in[0] * trans[1][0] + in[1] * trans[1][1] + in[2] * trans[1][2];
- out[2] = in[0] * trans[2][0] + in[1] * trans[2][1] + in[2] * trans[2][2];
-
-// convert meters to ft to degrees of latitude
- out[0] = (out[0] * 3.28083989501) /(366468.96 - 3717.12 * cos(flolspos[0] * SG_DEGREES_TO_RADIANS));
-
-// convert meters to ft to degrees of longitude
- out[1] = (out[1] * 3.28083989501)/(365228.16 * cos(flolspos[1] * SG_DEGREES_TO_RADIANS));
-
-//print out the result
-/* cout << "lat adjust deg" << out[0]
- << " lon adjust deg " << out[1]
- << " alt adjust m " << out[2] << endl;*/
-
-// adjust Flols position
- flolspos[0] += out[0];
- flolspos[1] += out[1];
- flolspos[2] += out[2];
-
-// convert flols position to cartesian co-ordinates
-
- sgGeodToCart(flolspos[1] * SG_DEGREES_TO_RADIANS,
- flolspos[0] * SG_DEGREES_TO_RADIANS,
- flolspos[2] , flolsXYZ );
-
-
-/* cout << "flols X " << flolsXYZ[0]
- << " Y " << flolsXYZ[1]
- << " Z " << flolsXYZ[2] << endl;
-
-// check the conversion
-
- sgCartToGeod(flolsXYZ, &lat, &lon, &alt);
-
- cout << "flols check lon " << lon
- << " lat " << lat
- << " alt " << alt << endl; */
-
-//get the current position of the pilot's eyepoint (cartesian cordinates)
-
- sgdCopyVec3( eyeXYZ, globals->get_current_view()->get_absolute_view_pos() );
-
- /* cout << "Eye_X " << eyeXYZ[0]
- << " Eye_Y " << eyeXYZ[1]
- << " Eye_Z " << eyeXYZ[2] << endl; */
-
- sgCartToGeod(eyeXYZ, &lat, &lon, &alt);
-
- eyepos[0] = lon * SG_RADIANS_TO_DEGREES;
- eyepos[1] = lat * SG_RADIANS_TO_DEGREES;
- eyepos[2] = alt;
-
-/* cout << "eye lon " << eyepos[0]
- << " eye lat " << eyepos[1]
- << " eye alt " << eyepos[2] << endl; */
-
-//calculate the ditance from eye to flols
-
- dist = sgdDistanceVec3( flolsXYZ, eyeXYZ );
-
-//apply an index error
-
- dist -= 100;
-
- //cout << "distance " << dist << endl;
-
- if ( dist < 5000 ) {
- // calculate height above FLOLS
- double y = eyepos[2] - flolspos[2];
-
- // calculate the angle from the flols to eye
- // above the horizontal
- // double angle;
-
- if ( dist != 0 ) {
- angle = asin( y / dist );
- } else {
- angle = 0.0;
- }
-
- angle *= SG_RADIANS_TO_DEGREES;
-
-
- // cout << " height " << y << " angle " << angle ;
-
-// set the value of source
-
- if ( angle <= 4.35 && angle > 4.01 )
- { source = 1; }
- else if ( angle <= 4.01 && angle > 3.670 )
- { source = 2; }
- else if ( angle <= 3.670 && angle > 3.330 )
- { source = 3; }
- else if ( angle <= 3.330 && angle > 2.990 )
- { source = 4; }
- else if ( angle <= 2.990 && angle > 2.650 )
- { source = 5; }
- else if ( angle <= 2.650 )
- { source = 6; }
- else
- { source = 0; }
-
-// cout << " source " << source << endl;
-
- }
-} // end updateflols
-
-int FGAICarrierHardware::unique_id = 1;
+
+void FGAICarrier::UpdateElevator(double dt, double transition_time) {
+
+ double step = 0;
+
+ if ((elevators && pos_norm >= 1 ) || (!elevators && pos_norm <= 0 ))
+ return;
+
+ // move the elevators
+ if ( elevators ) {
+ step = dt/transition_time;
+ if ( step > 1 )
+ step = 1;
+ } else {
+ step = -dt/transition_time;
+ if ( step < -1 )
+ step = -1;
+ }
+ // assume a linear relationship
+ raw_pos_norm += step;
+
+ //low pass filter
+ pos_norm = (raw_pos_norm * time_constant) + (pos_norm * (1 - time_constant));
+
+ //sanitise the output
+ if (raw_pos_norm >= 1) {
+ raw_pos_norm = 1;
+ } else if (raw_pos_norm <= 0) {
+ raw_pos_norm = 0;
+ }
+ return;
+
+} // end UpdateElevator
+
+void FGAICarrier::UpdateJBD(double dt, double jbd_transition_time) {
+
+ string launchbar_state = _launchbar_state_node->getStringValue();
+ double step = 0;
+
+ if (launchbar_state == "Engaged"){
+ jbd = true;
+ } else {
+ jbd = false;
+ }
+
+ if (( jbd && jbd_pos_norm >= 1 ) || ( !jbd && jbd_pos_norm <= 0 )){
+ return;
+ }
+
+ // move the jbds
+ if ( jbd ) {
+ step = dt/jbd_transition_time;
+ if ( step > 1 )
+ step = 1;
+ } else {
+ step = -dt/jbd_transition_time;
+ if ( step < -1 )
+ step = -1;
+ }
+
+ // assume a linear relationship
+ raw_jbd_pos_norm += step;
+
+ //low pass filter
+ jbd_pos_norm = (raw_jbd_pos_norm * jbd_time_constant) + (jbd_pos_norm * (1 - jbd_time_constant));
+
+ //sanitise the output
+ if (jbd_pos_norm >= 1) {
+ jbd_pos_norm = 1;
+ } else if (jbd_pos_norm <= 0) {
+ jbd_pos_norm = 0;
+ }
+
+ return;
+
+} // end UpdateJBD