1
0
Fork 0

Hitch/aertow updates fro D-NXKT

-fix a severe bug which led to unintended hitch releases;
-include the new JSBSim external force location variables;
-improvements for function closeHitch
This commit is contained in:
James Turner 2015-01-04 08:58:20 +00:00
parent 0060cdc24f
commit da1316a74c

View file

@ -1,22 +1,22 @@
# #
# Version: 10. March 2014 # Version: 30. December 2014
# #
# Purpose of this routine: # Purpose of this routine:
# ------------------------ # ------------------------
# #
# - Create visible winch- and towropes for gliders and towplanes # - Create visible winch- and towropes for gliders and towplanes
# - Support of aerotowing and winch for JSBSim-aircrafts (glider and towplanes) # - Support of aerotowing and winch for JSBSim-aircraft (glider and towplanes)
# #
# This routine is very similar to /FDM/YASim/Hitch.cpp # This routine is very similar to /FDM/YASim/Hitch.cpp
# Aerotowing is fully compatible to the YASim functionality. # Aerotowing is fully compatible to the YASim functionality.
# This means that YASim-gliders could be towed by JSBSim-aircrafts and vice versa. # This means that YASim-gliders could be towed by JSBSim-aircraft and vice versa.
# Setup-instructions with copy and paste examples are given below: # Setup-instructions with copy and paste examples are given below:
# #
# #
# Setup of visible winch/towropes for Yasim-aircrafts: # Setup of visible winch/towropes for Yasim-aircraft:
# ---------------------------------------------------- # ----------------------------------------------------
# #
# YASim-aircrafts with winch/aerotowing functionality should work out of the box. # YASim-aircraft with winch/aerotowing functionality should work out of the box.
# Optional you can customize the rope-diameter by adding the following to "your_aircraft-set.xml": # Optional you can customize the rope-diameter by adding the following to "your_aircraft-set.xml":
# </sim> # </sim>
# <hitches> # <hitches>
@ -37,13 +37,11 @@
# #
# #
# #
# Support of aerotowing and winch for JSBSim-aircrafts (glider and towplanes): # Support of aerotowing and winch for JSBSim-aircraft (glider and towplanes):
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# #
# 1. Define a hitch in the JSBSim-File. Coordinates according to JSBSims structural frame of reference # 1. Define a hitch in the JSBSim-File. Coordinates according to JSBSims structural frame of reference
# (x points to the tail, y points to the right wing, z points upwards). Be careful! This # (x points to the tail, y points to the right wing, z points upwards).
# coordinates don't appear in the property tree. You can only check them with test flights!
# The visible towrope is NOT an indicator of correct settings!
# Unit must be "LBS", frame must be "BODY". The force name is arbitrary. # Unit must be "LBS", frame must be "BODY". The force name is arbitrary.
# #
# <external_reactions> # <external_reactions>
@ -61,6 +59,7 @@
# </force> # </force>
# </external_reactions> # </external_reactions>
# 2. Define controls for aerotowing and winch. # 2. Define controls for aerotowing and winch.
# Add the following key bindings in "yourAircraft-set.xml": # Add the following key bindings in "yourAircraft-set.xml":
# <input> # <input>
@ -124,38 +123,49 @@
# </input> # </input>
# #
# For towplanes only "key n=79" (Open aerotow-hook) is required! # For towplanes only "key n=79" (Open aerotow-hook) is required!
#
#
# 3. Set mandatory properties: # 3. Set mandatory properties:
#<sim> #<sim>
# <hitches> # <hitches>
# <aerotow> # <aerotow>
# <force_name_jsbsim type="string">hitch</force_name_jsbsim> # <force_name_jsbsim type="string">hitch</force_name_jsbsim>
# <local-pos-x type="float">1.5</local-pos-x>
# <local-pos-y type="float"> 0.00</local-pos-y>
# <local-pos-z type="float">-0.3</local-pos-z>
# <force-is-calculated-by-other type="bool">false</force-is-calculated-by-other> # <force-is-calculated-by-other type="bool">false</force-is-calculated-by-other>
# <mp-auto-connect-period type="float">0.0</mp-auto-connect-period> # <mp-auto-connect-period type="float">0.0</mp-auto-connect-period>
# <!-- OPTIONAL
# <decoupled-force-and-rope-locations type="bool">true</decoupled-force-and-rope-locations>
# <local-pos-x type="float">1.5</local-pos-x>
# <local-pos-y type="float"> 0.00</local-pos-y>
# <local-pos-z type="float">-0.3</local-pos-z>
# -->
# </aerotow> # </aerotow>
# <winch> # <winch>
# <force_name_jsbsim type="string">hitch</force_name_jsbsim> # <force_name_jsbsim type="string">hitch</force_name_jsbsim>
# <local-pos-x type="float">0.0</local-pos-x> # <!-- OPTIONAL
# <local-pos-y type="float">0.0</local-pos-y> # <decoupled-force-and-rope-locations type="bool">true</decoupled-force-and-rope-locations>
# <local-pos-z type="float">0.0</local-pos-z> # <local-pos-x type="float">0.0</local-pos-x>
# <local-pos-y type="float">0.0</local-pos-y>
# <local-pos-z type="float">0.0</local-pos-z>
# -->
# </winch> # </winch>
# </hitches> # </hitches>
#</sim> #</sim>
# #
# "force_name_jsbsim" must be the external force name in JSBSim. # "force_name_jsbsim" must be the external force name in JSBSim.
# "force-is-calculated-by-other" should be "false" for gliders and "true" for tow planes.
# "mp-auto-connect-period" is only needed for tow planes and should be "1".
# #
# IMPORTANT: # IMPORTANT:
# JSBSim doesn't provide the hitch coordinates in the property tree. Hence you must set them again to get a # The hitch location is stored twice in the property tree (for tow force and for rope animation).
# visible towrope (local-pos-x/y/z). Unfortunately the coordinate systems are different. Here the coordinates # This is necessary to keep the towrope animation compatible to YASim-aircraft.
# for the "YASim-System" are needed (x points to the nose, y points to the left wing, z points upwards). # The hitch location for the tow force is stored in "fdm/jsbsim/external_reactions/hitch/location-x(yz)-in" and for the
# If you see the rope at the expected position "local-pos-x/y/z" are correct. # animated towrope in "sim/hitches/aerotow(winch)/local-pos-x(yz)".
# # By default only values for the tow force location have to be defined. The values for the towrope location are set
# "force-is-calculated-by-other" should be "false" for gliders and "true" for towplanes. # automatically (decoupled-force-and-rope-locations is "false" by default).
# "mp-auto-connect-period" is only needed for towplanes and should be "1". # It is feasible to use different locations for the force and rope. In order to do this, you have to set
# "decoupled-force-and-rope-locations" to "true" and provide values for "sim/hitches/aerotow(winch)/local-pos-x(yz)".
# Note that the frame of reference is different. Here the coordinates for the "YASim-System" are needed
# (x points to the nose, y points to the left wing, z points upwards).
# 4. Set optional properties: # 4. Set optional properties:
@ -193,7 +203,8 @@
# </winch> # </winch>
# </hitches> # </hitches>
#<sim> #<sim>
#
# That's it! # That's it!
@ -243,7 +254,7 @@
# set defaults for properties that are NOT already defined # set defaults for properties that are NOT already defined
# yasim properties for aerotow (should be already defined for yasim aircrafts but not for JSBSim aircrafts # yasim properties for aerotow (should be already defined for yasim aircraft but not for JSBSim aircraft
if (props.globals.getNode("sim/hitches/aerotow/broken") == nil ) if (props.globals.getNode("sim/hitches/aerotow/broken") == nil )
props.globals.getNode("sim/hitches/aerotow/broken", 1).setBoolValue(0); props.globals.getNode("sim/hitches/aerotow/broken", 1).setBoolValue(0);
if (props.globals.getNode("sim/hitches/aerotow/force") == nil ) if (props.globals.getNode("sim/hitches/aerotow/force") == nil )
@ -319,7 +330,7 @@
props.globals.getNode("sim/hitches/aerotow/tow/mp_last_reported_dist", 1).setValue(0.); props.globals.getNode("sim/hitches/aerotow/tow/mp_last_reported_dist", 1).setValue(0.);
} }
# yasim properties for winch (should be already defined for yasim aircrafts but not for JSBSim aircrafts # yasim properties for winch (should already be defined for yasim aircraft but not for JSBSim aircraft
#if (props.globals.getNode("sim/hitches/winch/open") == nil ) #if (props.globals.getNode("sim/hitches/winch/open") == nil )
props.globals.getNode("sim/hitches/winch/open", 1).setBoolValue(1); props.globals.getNode("sim/hitches/winch/open", 1).setBoolValue(1);
if (props.globals.getNode("sim/hitches/winch/broken") == nil ) if (props.globals.getNode("sim/hitches/winch/broken") == nil )
@ -388,7 +399,20 @@
props.globals.getNode("sim/hitches/winch/winch/magic-constant", 1).setValue(500.); props.globals.getNode("sim/hitches/winch/winch/magic-constant", 1).setValue(500.);
} }
# new properties for JSBSim aerotow and winch
if ( getprop("sim/flight-model") == "jsb" ) {
if (props.globals.getNode("sim/hitches/aerotow/decoupled-force-and-rope-locations") == nil )
props.globals.getNode("sim/hitches/aerotow/decoupled-force-and-rope-locations", 1).setBoolValue(0);
if (props.globals.getNode("sim/hitches/winch/decoupled-force-and-rope-locations") == nil )
props.globals.getNode("sim/hitches/winch/decoupled-force-and-rope-locations", 1).setBoolValue(0);
# consider older JSBSim-versions which do NOT provide the locations of external_reactions in the property tree
var hitchname_aerotow = getprop("sim/hitches/aerotow/force_name_jsbsim");
var hitchname_winch = getprop("sim/hitches/winch/force_name_jsbsim");
if (props.globals.getNode("fdm/jsbsim/external_reactions/" ~ hitchname_aerotow ~ "/location-x-in") == nil )
props.globals.getNode("sim/hitches/aerotow/decoupled-force-and-rope-locations").setBoolValue(1);
if (props.globals.getNode("fdm/jsbsim/external_reactions/" ~ hitchname_winch ~ "/location-x-in") == nil )
props.globals.getNode("sim/hitches/winch/decoupled-force-and-rope-locations").setBoolValue(1);
}
# ###################################################################################################################### # ######################################################################################################################
# main function # main function
@ -429,7 +453,7 @@ var towing = func {
# setup ai-towrope # setup ai-towrope
createTowrope("aerotow"); createTowrope("aerotow");
# set default hitch coordinates (needed for Ai- and non-interactive MP aircrafts) # set default hitch coordinates (needed for Ai- and non-interactive MP aircraft)
setAIObjectDefaults() ; setAIObjectDefaults() ;
} }
} # end hitch is closed } # end hitch is closed
@ -497,7 +521,7 @@ var towing = func {
# setup ai-towrope # setup ai-towrope
createTowrope("winch"); createTowrope("winch");
# set default hitch coordinates (needed for Ai- and non-interactive MP aircrafts) # set default hitch coordinates (needed for Ai- and non-interactive MP aircraft)
setAIObjectDefaults() ; setAIObjectDefaults() ;
} }
} # end hitch is closed } # end hitch is closed
@ -536,12 +560,7 @@ var findBestAIObject = func (){
# local variables # local variables
var aiobjects = []; # keeps the ai-planes from the property tree var aiobjects = []; # keeps the ai-planes from the property tree
var AI_id = 0; # id of towplane
var callsign = 0; # callsign of towplane
var aiPosition = geo.Coord.new(); # current processed ai-plane var aiPosition = geo.Coord.new(); # current processed ai-plane
var lat_deg = 0; # latitude of current processed aiobject
var lon_deg = 0; # longitude of current processed aiobject
var alt_m = 0; # altitude of current processed aiobject
var myPosition = geo.Coord.new(); # coordinates of glider var myPosition = geo.Coord.new(); # coordinates of glider
var distance_m = 0; # distance to ai-plane var distance_m = 0; # distance to ai-plane
@ -553,7 +572,7 @@ var findBestAIObject = func (){
var mp_open_last_state = 0; var mp_open_last_state = 0;
var isSlave = 0; var isSlave = 0;
if ( getprop("sim/flight-model") == "yasim" ) return; # bypass this routine for Yasim-aircrafts if ( getprop("sim/flight-model") == "yasim" ) return; # bypass this routine for Yasim-aircraft
#print("findBestAIObject"); #print("findBestAIObject");
@ -583,13 +602,17 @@ var findBestAIObject = func (){
if ( sprintf("%8s",node) == "aircraft" ) nodeIsAiAircraft = 1; if ( sprintf("%8s",node) == "aircraft" ) nodeIsAiAircraft = 1;
if ( sprintf("%11s",node) == "multiplayer" ) nodeIsMpAircraft = 1; if ( sprintf("%11s",node) == "multiplayer" ) nodeIsMpAircraft = 1;
#print("found NodeName=",node," nodeIsAiAircraft=",nodeIsAiAircraft," nodeIsMpAircraft=",nodeIsMpAircraft ); #print("found NodeName=",node," nodeIsAiAircraft=",nodeIsAiAircraft," nodeIsMpAircraft=",nodeIsMpAircraft );
if ( !nodeIsAiAircraft and !nodeIsMpAircraft ) continue;
if( !nodeIsAiAircraft and !nodeIsMpAircraft ) continue; if ( !aimember.getNode("valid").getValue() ) continue; # node is invalid
if( running_as_autoconnect ) { if( running_as_autoconnect ) {
if ( !nodeIsMpAircraft ) continue; if ( !nodeIsMpAircraft ) continue;
if ( aimember.getValue("sim/hitches/aerotow/open") == 1 ) continue; # if mp hook open, auto-connect isn't possible #if ( aimember.getValue("sim/hitches/aerotow/open") == nil ) continue; # this node MUST exist for mp-aircraft which want to be towed
if (mycallsign != aimember.getValue("sim/hitches/aerotow/tow/connected-to-ai-or-mp-callsign") ) continue ; # I'm the wrong one #if ( aimember.getValue("sim/hitches/aerotow/open") == 1 ) continue; # if mp hook open, auto-connect is NOT possible
if ( aimember.getValue("sim/hitches/aerotow/open") != 0 ) continue;
if (mycallsign != aimember.getValue("sim/hitches/aerotow/tow/connected-to-ai-or-mp-callsign") ) continue ; # I am the wrong one
if ( !getprop("sim/hitches/aerotow/mp_oldOpen") ) continue; # this prevents an unwanted immediate auto-connect after the dragger
# released its hitch. Firstly wait for a reported "open" hitch from glider
} }
var lat_deg = aimember.getNode("position/latitude-deg").getValue(); var lat_deg = aimember.getNode("position/latitude-deg").getValue();
@ -626,9 +649,9 @@ var findBestAIObject = func (){
aimember.getNode("sim/hitches/aerotow/tow/dist",1).setValue(-1.); aimember.getNode("sim/hitches/aerotow/tow/dist",1).setValue(-1.);
found = 1; found = 1;
} } # end distance_m < bestdist_m
} } # end node != nil
} } # end loop aiobjects
if (found) { if (found) {
if ( !running_as_autoconnect) { if ( !running_as_autoconnect) {
setprop("sim/messages/pilot", sprintf("%s, I am on your hook, distance %4.3f meter.",aicallsign,bestdist_m)); setprop("sim/messages/pilot", sprintf("%s, I am on your hook, distance %4.3f meter.",aicallsign,bestdist_m));
@ -640,15 +663,18 @@ var findBestAIObject = func (){
isSlave = 1; isSlave = 1;
props.globals.getNode("sim/hitches/aerotow/is-slave").setBoolValue(isSlave); props.globals.getNode("sim/hitches/aerotow/is-slave").setBoolValue(isSlave);
} }
# set the dist value to some value below the tow length (if not, the hitch would open the next calc force run
distance_m = towlength_m * 0.5;
props.globals.getNode("sim/hitches/aerotow/mp_oldOpen").setBoolValue(1); props.globals.getNode("sim/hitches/aerotow/mp_oldOpen").setBoolValue(1);
} # end: if found } # end: if found
else { else {
if (!running_as_autoconnect) { if (!running_as_autoconnect) {
setprop("sim/messages/atc", sprintf("Sorry, no aircraft for aerotow!")); setprop("sim/messages/atc", sprintf("Sorry, no aircraft for aerotow!"));
} }
else{
#print("auto-connect: found=0");
props.globals.getNode("sim/hitches/aerotow/mp_oldOpen").setBoolValue(1);
}
} }
} # End function findBestAIObject } # End function findBestAIObject
@ -680,6 +706,7 @@ var aerotow = func (open){
var my_pitch_deg = getprop("orientation/pitch-deg"); var my_pitch_deg = getprop("orientation/pitch-deg");
# hook coordinates in Yasim-system (x-> nose / y -> left wing / z -> up) # hook coordinates in Yasim-system (x-> nose / y -> left wing / z -> up)
assignHitchLocations("aerotow");
var x = getprop("sim/hitches/aerotow/local-pos-x"); var x = getprop("sim/hitches/aerotow/local-pos-x");
var y = getprop("sim/hitches/aerotow/local-pos-y"); var y = getprop("sim/hitches/aerotow/local-pos-y");
var z = getprop("sim/hitches/aerotow/local-pos-z"); var z = getprop("sim/hitches/aerotow/local-pos-z");
@ -692,7 +719,7 @@ var aerotow = func (open){
var install_distance_m = Xn[0]; # in front of ref-point of glider var install_distance_m = Xn[0]; # in front of ref-point of glider
var install_side_m = Xn[1]; var install_side_m = Xn[1];
var install_alt_m = Xn[2]; var install_alt_m = Xn[2];
var myHitch_pos = myPosition.apply_course_distance( my_head_deg , install_distance_m ); var myHitch_pos = myPosition.apply_course_distance( my_head_deg , install_distance_m );
var myHitch_pos = myPosition.apply_course_distance( my_head_deg - 90. , install_side_m ); var myHitch_pos = myPosition.apply_course_distance( my_head_deg - 90. , install_side_m );
@ -700,28 +727,29 @@ var aerotow = func (open){
########################################### ai hitch position ############################################ ########################################### ai hitch position ############################################
var aiNodeID = getprop("sim/hitches/aerotow/tow/connected-to-ai-or-mp-id"); # id of former found ai/mp aircraft #var aiNodeID = getprop("sim/hitches/aerotow/tow/connected-to-ai-or-mp-id"); # id of former found ai/mp aircraft
#print("aiNodeID=",aiNodeID); #print("aiNodeID=",aiNodeID);
var aiCallsign = getprop("sim/hitches/aerotow/tow/connected-to-ai-or-mp-callsign"); # callsign of former found ai/mp aircraft
var found = 0;
aiobjects = props.globals.getNode("ai/models").getChildren(); aiobjects = props.globals.getNode("ai/models").getChildren();
foreach (var aimember; aiobjects) { foreach (var aimember; aiobjects) {
if ( (var c = aimember.getNode("id") ) != nil ) { if ( (var c = aimember.getNode("id") ) != nil ) {
var testprop = c.getValue(); if ( !aimember.getNode("valid").getValue() ) continue; # node is invalid
if ( testprop == aiNodeID) {
# get coordinates
var ai_lat = aimember.getNode("position/latitude-deg").getValue();
var ai_lon = aimember.getNode("position/longitude-deg").getValue();
var ai_alt = (aimember.getNode("position/altitude-ft").getValue()) * FT2M;
#print("ai_lat,lon,alt",ai_lat,ai_lon,ai_alt);
var ai_pitch_deg = aimember.getNode("orientation/pitch-deg").getValue(); # Identifying the MP-aircraft by its node-id works fine with JSBSim-aircraft but NOT with YASim.
var ai_roll_deg = aimember.getNode("orientation/roll-deg").getValue(); # In YASim the node-id is not updated which could lead to complications (e.g. node-id changes after "Pause" or "Exit").
var ai_head_deg = aimember.getNode("orientation/true-heading-deg").getValue(); #var testprop = c.getValue();
#if ( testprop == aiNodeID) {
var aiHitchX = aimember.getNode("sim/hitches/aerotow/local-pos-x").getValue(); # Identifying the MP-aircraft by its callsign works fine with JSBSim AND YASim-aircraft
var aiHitchY = aimember.getNode("sim/hitches/aerotow/local-pos-y").getValue(); var testprop = aimember.getNode("callsign").getValue();
var aiHitchZ = aimember.getNode("sim/hitches/aerotow/local-pos-z").getValue(); if ( testprop == aiCallsign ) {
found = found + 1;
###################### check status of ai hitch ######################
if ( getprop("sim/flight-model") == "jsb" ) { if ( getprop("sim/flight-model") == "jsb" ) {
# check if the multiplayer hitch state has changed # check if the multiplayer hitch state has changed
# this trick avoids immediate opening after locking because MP-aircraft has not yet reported a locked hitch # this trick avoids immediate opening after locking because MP-aircraft has not yet reported a locked hitch
@ -738,6 +766,21 @@ var aerotow = func (open){
} # end: state has changed } # end: state has changed
} # end: node is available } # end: node is available
} #end : JSBSim } #end : JSBSim
########################################################################
# get coordinates
var ai_lat = aimember.getNode("position/latitude-deg").getValue();
var ai_lon = aimember.getNode("position/longitude-deg").getValue();
var ai_alt = (aimember.getNode("position/altitude-ft").getValue()) * FT2M;
#print("ai_lat,lon,alt",ai_lat,ai_lon,ai_alt);
var ai_pitch_deg = aimember.getNode("orientation/pitch-deg").getValue();
var ai_roll_deg = aimember.getNode("orientation/roll-deg").getValue();
var ai_head_deg = aimember.getNode("orientation/true-heading-deg").getValue();
var aiHitchX = aimember.getNode("sim/hitches/aerotow/local-pos-x").getValue();
var aiHitchY = aimember.getNode("sim/hitches/aerotow/local-pos-y").getValue();
var aiHitchZ = aimember.getNode("sim/hitches/aerotow/local-pos-z").getValue();
var aiPosition = geo.Coord.set_latlon( ai_lat, ai_lon, ai_alt ); var aiPosition = geo.Coord.set_latlon( ai_lat, ai_lon, ai_alt );
@ -781,9 +824,9 @@ var aerotow = func (open){
############################################# calc forces ################################################## ############################################# calc forces ##################################################
# calc forces only for JSBSim-aircrafts # calc forces only for JSBSim-aircraft
# tow-end-forces must be reported in N to be consiststent to Yasim-aircrafts # tow-end-forces must be reported in N to be consiststent to Yasim-aircraft
# hitch-forces must be LBS to be consistent to the JSBSim "external_forces/.../magnitude" definition # hitch-forces must be LBS to be consistent to the JSBSim "external_forces/.../magnitude" definition
if ( getprop("sim/flight-model") == "jsb" ) { if ( getprop("sim/flight-model") == "jsb" ) {
@ -799,7 +842,7 @@ var aerotow = func (open){
# or the MP-aircraft is a non-interactive mp plane (mp_reported_dist = -1) # or the MP-aircraft is a non-interactive mp plane (mp_reported_dist = -1)
# => update forces else use the old forces! # => update forces else use the old forces!
var breakforce_N = getprop("sim/hitches/aerotow/tow/brake-force"); # could be different in both aircrafts var breakforce_N = getprop("sim/hitches/aerotow/tow/brake-force"); # could be different in both aircraft
var isSlave = getprop("sim/hitches/aerotow/is-slave"); var isSlave = getprop("sim/hitches/aerotow/is-slave");
if ( !isSlave ){ # if we are master, we have to calculate the forces if ( !isSlave ){ # if we are master, we have to calculate the forces
@ -896,7 +939,7 @@ var aerotow = func (open){
############################################# report forces ############################################## ############################################# report forces ##############################################
# if we are connected to an MP aircraft and master # if we are connected to a MP-aircraft and master
var nodeIsMpAircraft = getprop("sim/hitches/aerotow/tow/connected-to-mp-node"); var nodeIsMpAircraft = getprop("sim/hitches/aerotow/tow/connected-to-mp-node");
if ( nodeIsMpAircraft and !isSlave ){ if ( nodeIsMpAircraft and !isSlave ){
#print("report Forces"); #print("report Forces");
@ -938,16 +981,21 @@ var aerotow = func (open){
} # end: aiNodeID } # end: aiNodeID
else{
if ( !aimember.getNode("valid").getValue() ) { # MP-aircraft is accessable (node is valid)
#print("MP-aircraft isn't valid!");
props.globals.getNode("sim/hitches/aerotow/open").setBoolValue(1); # open my hitch
setprop("sim/messages/atc", sprintf("MP-aircraft disappeared!" ));
}
}
} # end: check id != nil } # end: check id != nil
} # end: loop over aiobjects } # end: loop over aiobjects
if ( found == 0 ) {
if ( getprop("sim/flight-model") == "jsb" ) {
setprop("sim/messages/atc", sprintf("MP-aircraft disappeared!" ));
props.globals.getNode("sim/hitches/aerotow/open").setBoolValue(1); # open my hitch
props.globals.getNode("sim/hitches/aerotow/tow/connected-to-ai-or-mp-id").setIntValue(0);
props.globals.getNode("sim/hitches/aerotow/tow/connected-to-ai-or-mp-callsign").setValue("");
props.globals.getNode("sim/hitches/aerotow/tow/connected-to-ai-node").setBoolValue(0);
props.globals.getNode("sim/hitches/aerotow/tow/connected-to-mp-node").setBoolValue(0);
props.globals.getNode("sim/hitches/aerotow/tow/connected-to-property-node").setBoolValue(0);
}
#if ( getprop("sim/flight-model") == "yasim" ) removeTowrope("aerotow"); # remove towrope model
} # end found=0
} # end function aerotow } # end function aerotow
@ -974,6 +1022,7 @@ var winch = func (open){
var my_pitch_deg = getprop("orientation/pitch-deg"); var my_pitch_deg = getprop("orientation/pitch-deg");
# hitch coordinates in YASim-system (x-> nose / y -> left wing / z -> up) # hitch coordinates in YASim-system (x-> nose / y -> left wing / z -> up)
assignHitchLocations("winch");
var x = getprop("sim/hitches/winch/local-pos-x"); var x = getprop("sim/hitches/winch/local-pos-x");
var y = getprop("sim/hitches/winch/local-pos-y"); var y = getprop("sim/hitches/winch/local-pos-y");
var z = getprop("sim/hitches/winch/local-pos-z"); var z = getprop("sim/hitches/winch/local-pos-z");
@ -1036,9 +1085,9 @@ var winch = func (open){
############################################# calc forces ################################################## ############################################# calc forces ##################################################
# calc forces only for JSBSim-aircrafts # calc forces only for JSBSim-aircraft
# tow-end-forces must be reported in N to be consiststent to Yasim-aircrafts # tow-end-forces must be reported in N to be consiststent to Yasim-aircraft
# hitch-forces must be LBS to be consistent to the JSBSim "external_forces/.../magnitude" definition # hitch-forces must be LBS to be consistent to the JSBSim "external_forces/.../magnitude" definition
if ( getprop("sim/flight-model") == "jsb" ) { if ( getprop("sim/flight-model") == "jsb" ) {
@ -1261,13 +1310,112 @@ var getFreeModelID = func {
# ###################################################################################################################### # ######################################################################################################################
# close hitch # close aerotow hitch
# ###################################################################################################################### # ######################################################################################################################
var closeHitch = func { var closeHitch = func {
#print("closeHitch"); #print("closeHitch");
# close only, if
# - not yet closed
# - connected to property-node
# - distance < towrope length
var open = getprop("sim/hitches/aerotow/open");
if ( !open ) return;
var aiNodeID = getprop("sim/hitches/aerotow/tow/connected-to-ai-or-mp-id"); # id of former found ai/mp aircraft
if ( aiNodeID < 1 ) {
setprop("sim/messages/atc", sprintf("No aircraft selected!"));
return;
}
##################################### calc distance between hitches ######################
###################### my hitch position #######################
myPosition = geo.aircraft_position();
var my_head_deg = getprop("orientation/heading-deg");
var my_roll_deg = getprop("orientation/roll-deg");
var my_pitch_deg = getprop("orientation/pitch-deg");
# hook coordinates in Yasim-system (x-> nose / y -> left wing / z -> up)
assignHitchLocations("aerotow");
var x = getprop("sim/hitches/aerotow/local-pos-x");
var y = getprop("sim/hitches/aerotow/local-pos-y");
var z = getprop("sim/hitches/aerotow/local-pos-z");
var alpha_deg = my_roll_deg * (1.); # roll clockwise (looking in x-direction) := +
var beta_deg = my_pitch_deg * (-1.); # pitch clockwise (looking in y-direction) := -
# transform hook coordinates
var Xn = PointRotate3D(x:x,y:y,z:z,xr:0.,yr:0.,zr:0.,alpha_deg:alpha_deg,beta_deg:beta_deg,gamma_deg:0.);
var install_distance_m = Xn[0]; # in front of ref-point of glider
var install_side_m = Xn[1];
var install_alt_m = Xn[2];
var myHitch_pos = myPosition.apply_course_distance( my_head_deg , install_distance_m );
var myHitch_pos = myPosition.apply_course_distance( my_head_deg - 90. , install_side_m );
myHitch_pos.set_alt(myPosition.alt() + install_alt_m);
###################### ai hitch position #######################
var found = 0;
aiobjects = props.globals.getNode("ai/models").getChildren();
foreach (var aimember; aiobjects) {
if ( (var c = aimember.getNode("id") ) != nil ) {
var testprop = c.getValue();
if ( testprop == aiNodeID) {
found = found + 1;
# get coordinates
var ai_lat = aimember.getNode("position/latitude-deg").getValue();
var ai_lon = aimember.getNode("position/longitude-deg").getValue();
var ai_alt = (aimember.getNode("position/altitude-ft").getValue()) * FT2M;
var ai_pitch_deg = aimember.getNode("orientation/pitch-deg").getValue();
var ai_roll_deg = aimember.getNode("orientation/roll-deg").getValue();
var ai_head_deg = aimember.getNode("orientation/true-heading-deg").getValue();
var aiHitchX = aimember.getNode("sim/hitches/aerotow/local-pos-x").getValue();
var aiHitchY = aimember.getNode("sim/hitches/aerotow/local-pos-y").getValue();
var aiHitchZ = aimember.getNode("sim/hitches/aerotow/local-pos-z").getValue();
var aiPosition = geo.Coord.set_latlon( ai_lat, ai_lon, ai_alt );
var alpha_deg = ai_roll_deg * (1.);
var beta_deg = ai_pitch_deg * (-1.);
# transform hook coordinates
var Xn = PointRotate3D(x:aiHitchX,y:aiHitchY,z:aiHitchZ,xr:0.,yr:0.,zr:0.,alpha_deg:alpha_deg,beta_deg:beta_deg,gamma_deg:0.);
var install_distance_m = Xn[0]; # in front of ref-point of glider
var install_side_m = Xn[1];
var install_alt_m = Xn[2];
var aiHitch_pos = aiPosition.apply_course_distance( ai_head_deg , install_distance_m );
var aiHitch_pos = aiPosition.apply_course_distance( ai_head_deg - 90. , install_side_m );
aiHitch_pos.set_alt(aiPosition.alt() + install_alt_m);
var distance = (myHitch_pos.direct_distance_to(aiHitch_pos));
var towlength_m = props.globals.getNode("sim/hitches/aerotow/tow/length").getValue();
if ( distance > towlength_m ) {
var aicallsign = getprop("sim/hitches/aerotow/tow/connected-to-ai-or-mp-callsign");
#setprop("sim/messages/atc", sprintf("Aircraft with callsign %s is too far away (distance is %4.0f meter).",aicallsign, distance));
setprop("sim/messages/atc", sprintf("Selected aircraft is too far away (distance to %s is %4.0f meter).",aicallsign, distance));
return;
}
setprop("sim/hitches/aerotow/tow/dist", distance);
}
}
}
setprop("sim/hitches/aerotow/open", "false"); setprop("sim/hitches/aerotow/open", "false");
setprop("sim/hitches/aerotow/mp_oldOpen", "true"); setprop("sim/hitches/aerotow/mp_oldOpen", "true");
@ -1282,7 +1430,7 @@ var releaseHitch = func (device){
#print("releaseHitch"); #print("releaseHitch");
if ( getprop("sim/flight-model") == "yasim" ) return; # bypass this routine for Yasim-aircrafts if ( getprop("sim/flight-model") == "yasim" ) return; # bypass this routine for Yasim-aircraft
setprop("sim/hitches/" ~ device ~ "/open", "true"); setprop("sim/hitches/" ~ device ~ "/open", "true");
@ -1503,6 +1651,35 @@ var releaseWinch = func {
} # End function releaseWinch } # End function releaseWinch
# ######################################################################################################################
# assignHitchLocations
# ######################################################################################################################
var assignHitchLocations = func (device){
if ( getprop("sim/flight-model") == "yasim" ) return; # bypass this routine for Yasim-aircraft
if ( getprop("sim/hitches/" ~ device ~ "/decoupled-force-and-rope-locations") ) return; # bypass this routine
#print("assignHitchLocations");
var in2m = 0.0254;
var hitchname = getprop("sim/hitches/" ~ device ~ "/force_name_jsbsim");
# location-x(yz)-in: JSBSim Structural Frame: x points to tail, y points to right wing, z points upward
# local-pos-x(yz): YaSim frame: x points to nose, y points to left wing, z points upward
setprop("sim/hitches/" ~ device ~ "/local-pos-x",
- getprop("fdm/jsbsim/external_reactions/" ~ hitchname ~ "/location-x-in") * in2m );
setprop("sim/hitches/" ~ device ~ "/local-pos-y",
- getprop("fdm/jsbsim/external_reactions/" ~ hitchname ~ "/location-y-in") * in2m );
setprop("sim/hitches/" ~ device ~ "/local-pos-z",
getprop("fdm/jsbsim/external_reactions/" ~ hitchname ~ "/location-z-in") * in2m );
} # End function assignHitchLocations
# ###################################################################################################################### # ######################################################################################################################
# point transformation # point transformation
# ###################################################################################################################### # ######################################################################################################################
@ -1644,5 +1821,5 @@ var PointRotate3D = func (x,y,z,xr,yr,zr,alpha_deg,beta_deg,gamma_deg){
# - pull in towrope: take sink rate of rope into account # - pull in towrope: take sink rate of rope into account
# - dynamic ID for ai-rope-model # - dynamic ID for ai-rope-model
# #
# Please contact D-NXKT at yahoo.de for bug-reports, suggestions, ... # Please contact D_NXKT at yahoo.de for bug-reports, suggestions, ...
# #