Board index FlightGear Development Nasal

Making drogue slave to probe after contact in AAR

Nasal is the scripting language of FlightGear.

Making drogue slave to probe after contact in AAR

Postby Farrukh » Fri May 24, 2013 3:02 am

I am working currently to improve the Air to Air Refueling Scenario in FG. I have calculated the drogues lats longs from tanker lat/lon and similarly probe lat lon from user aircraft respectively. I have used a contact variable for left and right drogue each and when probe makes contact with any of the drogues, the respective variable is set to Boolean true.
Now after having made contact of probe with drogue, i want to make drogue slave to the probe (lat/lon or position) till the time the contact variable is true. But i am not having any success till now in this case. I have already gone through the animations applied in XML files but it is of no success to me as i want to slave drogue w.r.t probe. Any help/idea would be welcomed
Posts: 12
Joined: Sun Oct 23, 2011 7:48 am

Re: Making drogue slave to probe after contact in AAR

Postby Johan G » Fri May 24, 2013 7:37 am

Could you post some code examples between [code] tags, so the ones of us that can be of help with that can be of more help. :wink:

As a side note, are you aware of that the NATO AAR procedures are openly published at the RAF web site? :shock: :D
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Johan G
Posts: 6250
Joined: Fri Aug 06, 2010 5:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: Making drogue slave to probe after contact in AAR

Postby stuart » Fri May 24, 2013 10:38 am

Hi Farrukh,

By far the simplest way to do this would be to have separate animations on the tanker and receiving aircraft and simply hide show/hide the drogues depending on whether contact has been made. That would still leave the hose to be dealt with, but would at least give some visual information.

You should be aware that I've made a number of enhancements to the AAR coding in the development stream that will be available in the next release (v2.12.0). In particular, AAR now supports multiple contact points, the definition of the probe position, and user control of the refueling envelope (i.e. how close you need to be to get contact).

Details are available here: and I still need to document how to configure the refueling points on tanker aircraft, but they are pretty obvious from looking at the AI/tankers.xml file.

User avatar
Posts: 1588
Joined: Wed Nov 29, 2006 9:56 am
Location: Edinburgh
Callsign: G-MWLX

Re: Making drogue slave to probe after contact in AAR

Postby Farrukh » Sat May 25, 2013 3:37 am

Thanx Stuart and Johan...
My code for AAR is as attached so that anyone can read and help me...if possible..I have to apply number of rotation and show/hide animations to bring some visual information out of this...but that can make the scenario very fake and unreal...However, i am constantly in a search of making something out of this work..Just for ur information, i was using X plane before...but i also came to a dead end there...Flight gear is an open source therefore i came to this to have control..however, i am stuck between XML and Nasal files and can't have much control on animations.
Code: Select all
var left_drogue_contact = func {

   var left_drog_contact = 0;
   #probe offsets
   var x_offset = -0.496004;
   var y_offset = 0.000873193;
   var z_offset = 1.76627;
   var d_x_offset = -27.3505;
   var d_y_offset = -15.9516;
   var d_z_offset = -0.172246;
   var d_bouncen_x = -27.9201;
   var d_bouncen_y = -15.9516;
   var d_bouncen_z = -0.17464;
   var probe_hdg = ac_hdg.getValue();
   var probe_pitch = p_pitch.getValue();
   var probe_lat = p_lat.getValue();
   var probe_lon = p_lon.getValue();
   var probe_roll = p_roll.getValue() * D2R;
   var tanker2_lat = d1_lat.getValue();
   var tanker2_lon = d1_lon.getValue();
   var tanker2_alt = d1_alt.getValue() * FT2M;
   var tanker2_roll = d_roll.getValue() * D2R;
   var drogue_hdg = d_hdg.getValue();
   #offset vertically of probe
   var pr_alt = (p_alt.getValue() * FT2M) + z_offset * math.cos(probe_roll) - y_offset * math.sin(probe_roll);
   var probe_pos =, probe_lon, pr_alt);
   #longitudinal offset for probe position
   probe_pos.apply_course_distance(probe_hdg, x_offset);   #second argument is in meters and is x offset of probe from centre of the aircraft
   #lateral offset for probe position
   probe_pos.apply_course_distance(probe_hdg + 90, y_offset* math.cos(probe_roll) + z_offset * math.sin(probe_roll));
   var a =;
   var b = probe_pos.lon();
   var c = probe_pos.alt();
   var tanker_pos =, tanker2_lon, tanker2_alt);
   tanker_pos.apply_course_distance(drogue_hdg , d_x_offset);
   tanker_pos.apply_course_distance(drogue_hdg + 90, d_y_offset * math.cos(tanker2_roll) + d_z_offset * math.sin(tanker2_roll));
   tanker_pos.set_alt(tanker2_alt + d_z_offset * math.cos(tanker2_roll) - d_y_offset * math.sin(tanker2_roll));
   #geo.put_model("Models/Geometry/IL-78/Models/Arbitrary_point_wingman1.xml", a, b , pr_alt);
   var a1 =;
   var b1 = tanker_pos.lon();
   var c1 = tanker_pos.alt();
   var d_boun_centr =, tanker2_lon, tanker2_alt);
   d_boun_centr.apply_course_distance(drogue_hdg , d_bouncen_x);
   d_boun_centr.apply_course_distance(drogue_hdg + 90, d_bouncen_y * math.cos(tanker2_roll) + d_bouncen_z * math.sin(tanker2_roll));
   d_boun_centr.set_alt(tanker2_alt + d_bouncen_z * math.cos(tanker2_roll) - d_bouncen_y * math.sin(tanker2_roll));
   var a2 =;
   var b2 = d_boun_centr.lon();
   var c2 = d_boun_centr.alt();
   var probe_pos_xyz  = geodtocart(a, b, c);
   var tanker_pos_xyz = geodtocart(a1, b1, c1);
   var d_bouncen_xyz  = geodtocart(a2, b2, c2);
   var R_x = d_bouncen_xyz[0] - probe_pos_xyz[0];
   var R_y = d_bouncen_xyz[1] - probe_pos_xyz[1];
   var R_z = d_bouncen_xyz[2] - probe_pos_xyz[2];
   var Radius = math.sqrt(R_x * R_x + R_y * R_y + R_z * R_z);
   var probe_bearing = probe_pos.course_to(tanker_pos);
   var probe_distance = probe_pos.distance_to(tanker_pos);   

   var diff_alt = probe_pos.alt()- d_boun_centr.alt();   # in meters
   var elev = math.atan2(diff_alt, probe_distance) * R2D;      #in degrees
   var alt_diff = abs(diff_alt);
   var hdg_diff = abs(probe_hdg - drogue_hdg);
   var bearing_hdg_diff = abs(geo.normdeg(probe_bearing - probe_hdg));
   #var bearing_hdg_diff = abs(probe_bearing - probe_hdg);
   var pitch_elev_diff = abs(probe_pitch) - elev;
   var left_drog_contact = Radius < 0.67 and alt_diff < 0.67 and hdg_diff < 15 and pitch_elev_diff < 8;
Posts: 12
Joined: Sun Oct 23, 2011 7:48 am

Return to Nasal

Who is online

Users browsing this forum: Google [Bot] and 1 guest