update DG-101G: improve animation of tow for winch launch
[fg:toms-fgdata.git] / Aircraft / DG-101G / Nasal / dialogs.nas
1 # ####################################################################################
2 # ####################################################################################
3 # Nasal script for dialogs
4 #
5 # ####################################################################################
6 # Author: Klaus Kerner
7 # Version: 2012-07-09
8 #
9
10 # ####################################################################################
11 # basic fucntions to create dialogs
12 var config_dialog = gui.Dialog.new("sim/gui/dialogs/dg101g/config/dialog", 
13                                    "Aircraft/DG-101G/Dialogs/config.xml");
14
15 var aerotowing_ai_dialog = gui.Dialog.new(
16                                   "sim/gui/dialogs/dg101g/aerotowing_ai/dialog", 
17                                   "Aircraft/DG-101G/Dialogs/aerotowing_ai.xml");
18
19 var aerotowing_advanced_dialog = gui.Dialog.new(
20                                   "sim/gui/dialogs/dg101g/aerotowing_advanced/dialog",
21                                   "Aircraft/DG-101G/Dialogs/aerotowing_advanced.xml");
22
23
24 var dragrobot_dialog = gui.Dialog.new("sim/gui/dialogs/dg101g/dragrobot/dialog", 
25                                   "Aircraft/DG-101G/Dialogs/dragrobot.xml");
26 var dragrobot_advanced_dialog = gui.Dialog.new(
27                                   "sim/gui/dialogs/dg101g/dragrobot_advanced/dialog",
28                                   "Aircraft/DG-101G/Dialogs/dragrobot_advanced.xml");
29
30 var winch_dialog = gui.Dialog.new("sim/gui/dialogs/dg101g/winch/dialog", 
31                                   "Aircraft/DG-101G/Dialogs/winch.xml");
32
33 var winch_advanced_dialog = gui.Dialog.new(
34                                   "sim/gui/dialogs/dg101g/winch_advanced/dialog", 
35                                   "Aircraft/DG-101G/Dialogs/winch_advanced.xml");
36
37
38 # ####################################################################################
39 # config dialog: helper function to display masses in SI units than imperial units
40 var guiUpdateConfig = func {
41     # pilot's mass 
42     if ( getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs") == nil ) {
43         var mass_pilot_kg = 80;
44     }
45     else {
46         var mass_pilot_kg = getprop(
47                              "/fdm/jsbsim/inertia/pointmass-weight-lbs") * 0.45359237;
48     }
49     setprop("sim/glider/gui/config/mass_pilot_kg", mass_pilot_kg);
50     
51     # water tank masses 
52     if ( getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[1]") == nil ) {
53         var mass_tank_kg = 0;
54     }
55     else {
56         var mass_tank_kg = getprop(
57                           "/fdm/jsbsim/inertia/pointmass-weight-lbs[1]") * 0.45359237;
58         # cleanup a bug as the gui slider does only update one property, not two
59         setprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[2]", 
60                 getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[1]") );
61     }
62     setprop("sim/glider/gui/config/mass_tank_kg", mass_tank_kg);
63     
64     # payload mass 
65     if ( getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[3]") == nil ) {
66         var mass_payload_kg = 0;
67     }
68     else {
69         var mass_payload_kg = getprop(
70                           "/fdm/jsbsim/inertia/pointmass-weight-lbs[3]") * 0.45359237;
71     }
72     setprop("sim/glider/gui/config/mass_payload_kg", mass_payload_kg);
73 }
74
75 var guiconfiginit = setlistener("sim/signals/fdm-initialized", 
76                                  guiUpdateConfig,,0);
77 var guiconfig1    = setlistener("/fdm/jsbsim/inertia/pointmass-weight-lbs", 
78                                  guiUpdateConfig,,0);
79 var guiconfig2    = setlistener("/fdm/jsbsim/inertia/pointmass-weight-lbs[1]", 
80                                  guiUpdateConfig,,0);
81 var guiconfig3    = setlistener("/fdm/jsbsim/inertia/pointmass-weight-lbs[3]", 
82                                  guiUpdateConfig,,0);
83
84  
85 # ####################################################################################
86 # winch dialog: helper function to cancel the winch, avoiding race conditions
87 var guiWinchCancel = func {
88     dg101g.removeWinch();
89     dg101g.resetWinch();
90 }
91  
92
93
94 # ####################################################################################
95 # winch dialog: helper function to display winch operation points
96 var guiUpdateWinch = func {
97     if ( getprop("sim/glider/winch/conf/pull_max_lbs") == nil ) {
98         var pull_max_lbs = 1100;
99     }
100     else {
101         var pull_max_lbs = getprop("sim/glider/winch/conf/pull_max_lbs");
102     }
103     var pull_max_daN = pull_max_lbs * 0.45359237;
104     setprop("sim/glider/gui/winch/pull_max_daN", pull_max_daN);
105     
106     if ( getprop("sim/glider/winch/conf/pull_max_speed_mps") == nil ) {
107         var pull_max_speed_mps = 40;
108     }
109     else {
110         var pull_max_speed_mps = getprop("sim/glider/winch/conf/pull_max_speed_mps");
111     }
112     var pull_max_speed_kmh = pull_max_speed_mps * 3.6;
113     setprop("sim/glider/gui/winch/pull_max_speed_kmh", pull_max_speed_kmh);
114     
115   # for the speed correction, relative factors are used: 
116     #  k_speed_x1 = speed_x1 / pull_max_speed_mps
117     #  or: speed_x1 = k_speed_x1 * pull_max_speed_mps
118     if ( getprop("sim/glider/winch/conf/k_speed_x1") == nil ) {
119         var k_speed_x1 = 0.85;
120     }
121     else {
122         var k_speed_x1 = getprop("sim/glider/winch/conf/k_speed_x1");
123     }
124     var speed_x1 = k_speed_x1 * pull_max_speed_mps * 3.6;
125     setprop("sim/glider/gui/winch/speed_x1", speed_x1);
126     
127     #  k_speed_y2 = speed_y2 / pull_max_lbs
128     #  or: speed_y2 = k_speed_y2 * pull_max_lbs
129     if ( getprop("sim/glider/winch/conf/k_speed_y2") == nil ) {
130         var k_speed_y2 = 0.00;
131     }
132     else {
133         var k_speed_y2 = getprop("sim/glider/winch/conf/k_speed_y2");
134     }
135     var speed_y2 = k_speed_y2 * pull_max_lbs * 0.45359237;
136     setprop("sim/glider/gui/winch/speed_y2", speed_y2);
137     
138   # for the angle correction, relative factors are used: 
139     #  k_angle_x1 = angle_x1 / 70 (as 70° is hard-coded, not changeable)
140     #  or: angle_x1 = k_angle_x1 * 70
141     if ( getprop("sim/glider/winch/conf/k_angle_x1") == nil ) {
142         var k_angle_x1 = 0.75;
143     }
144     else {
145         var k_angle_x1 = getprop("sim/glider/winch/conf/k_angle_x1");
146     }
147     var angle_x1 = k_angle_x1 * 70;
148     setprop("sim/glider/gui/winch/angle_x1", angle_x1);
149     
150     #  k_angle_y2 = angle_y2 / pull_max_lbs
151     #  or: angle_y2 = k_angle_y2 * pull_max_lbs
152     if ( getprop("sim/glider/winch/conf/k_angle_y2") == nil ) {
153         var k_angle_y2 = 0.30;
154     }
155     else {
156         var k_angle_y2 = getprop("sim/glider/winch/conf/k_angle_y2");
157     }
158     var angle_y2 = k_angle_y2 * pull_max_lbs * 0.45359237;
159     setprop("sim/glider/gui/winch/angle_y2", angle_y2);
160 }
161
162 var guiwinchinit = setlistener("sim/sginals/fdm-initialized", 
163                                      guiUpdateWinch,,0);
164 var guiwinchspeed_x   = setlistener("sim/glider/winch/conf/pull_max_speed_mps", 
165                                      guiUpdateWinch,,0);
166 var guiwinchforce_x   = setlistener("sim/glider/winch/conf/pull_max_lbs", 
167                                      guiUpdateWinch,,0);
168 var guikspeedx1       = setlistener("sim/glider/winch/conf/k_speed_x1", 
169                                      guiUpdateWinch,,0);
170 var guikspeedy2       = setlistener("sim/glider/winch/conf/k_speed_y2", 
171                                      guiUpdateWinch,,0);
172 var guikanglex1       = setlistener("sim/glider/winch/conf/k_angle_x1", 
173                                      guiUpdateWinch,,0);
174 var guikangley2       = setlistener("sim/glider/winch/conf/k_angle_y2", 
175                                      guiUpdateWinch,,0);
176
177
178 # ####################################################################################
179 # drag-robot dialog: helper function to display properties in better readable SI units
180 var guiUpdateDragRobot = func {
181     # min. takeoff speed 
182     if ( getprop("sim/glider/dragger/conf/glob_min_speed_takeoff_mps") == nil ) {
183         var min_speed_takeoff = 20 * 3.6;
184     }
185     else {
186         var min_speed_takeoff = getprop(
187                           "sim/glider/dragger/conf/glob_min_speed_takeoff_mps") * 3.6;
188     }
189     setprop("sim/glider/gui/dragrobot/min_speed_takeoff", min_speed_takeoff);
190     
191     # max. speed 
192     if ( getprop("sim/glider/dragger/conf/glob_max_speed_mps") == nil ) {
193         var max_speed = 36 * 3.6;
194     }
195     else {
196         var max_speed = getprop("sim/glider/dragger/conf/glob_max_speed_mps") * 3.6;
197     }
198     setprop("sim/glider/gui/dragrobot/max_speed", max_speed);
199     
200     # max. tauten speed 
201     if ( getprop("sim/glider/dragger/conf/glob_max_speed_tauten_mps") == nil ) {
202         var max_speed_tauten = 3 * 3.6;
203     }
204     else {
205         var max_speed_tauten = getprop(
206                            "sim/glider/dragger/conf/glob_max_speed_tauten_mps") * 3.6;
207     }
208     setprop("sim/glider/gui/dragrobot/max_speed_tauten", max_speed_tauten);
209     
210 }
211
212
213 # ####################################################################################
214 # drag-robot dialog: helper function to run the roboter, avoiding race conditions
215 var guiRunDragRobot = func {
216     dg101g.findDragger();
217     dg101g.hookDragger();
218     dg101g.startDragRobot();
219 }
220
221
222 # ####################################################################################
223 # drag-robot dialog: helper function to cancel the roboter, avoiding race conditions
224 var guiCancelDragRobot = func {
225     dg101g.removeDragRobot();
226     dg101g.resetRobotAttributes();
227     dg101g.removeTowingRope();
228 }
229
230
231 var guidragrobotinit = setlistener("sim/signals/fdm-initialized", 
232                                      guiUpdateDragRobot,,0);
233 var guidragrobot_1   = setlistener("sim/glider/dragger/conf/glob_min_speed_takeoff_mps", 
234                                      guiUpdateDragRobot,,0);
235 var guidragrobot_2   = setlistener("sim/glider/dragger/conf/glob_max_speed_mps", 
236                                      guiUpdateDragRobot,,0);
237 var guidragrobot_3   = setlistener("sim/glider/dragger/conf/glob_max_speed_tauten_mps", 
238                                      guiUpdateDragRobot,,0);
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254