Commit bc8cf1bd authored by Михаил Данилов's avatar Михаил Данилов 💬

Autopush 0.6.0.

parent 558f6330
......@@ -8,17 +8,20 @@
var _enabled = 0;
var _K_p = nil;
var _F_p = nil;
var _K_i = nil;
var _K_d = nil;
var _F_i = nil;
var _K_d = nil;
var _F_d = nil;
var _F = nil;
var _int = nil;
var _deltaP_old = nil;
var _t_old = nil;
var _force_smooth = nil;
var _deltaV = nil;
var _T_f = nil;
var _K_yaw = nil;
var _yasim = 0;
var _speedup_listener = nil;
var _time = nil;
# (ft / s^2) / ((km / h) / s)
var _unitconv = M2FT / 3.6;
var _loop = func() {
if (!getprop("/sim/model/pushback/available")) {
......@@ -30,24 +33,22 @@ var _loop = func() {
var y = 0.0;
# Rollspeed is only adequate if the wheel is touching the ground.
if (getprop("/gear/gear[0]/wow")) {
var m = nil;
var deltaV = getprop("/sim/model/pushback/target-speed-km_h");
deltaV -= getprop("/gear/gear[0]/rollspeed-ms") * 3.6;
var dV = deltaV - _deltaV;
var time = systime();
var dt = (time - _time) * 0.001;
_int = math.min(math.max(_int + _K_i * dV * dt, -_F_i), _F_i);
var accel = math.min(math.max(_K_p * deltaV, -_F_p), _F_p);
accel += math.min(math.max(_K_d * dV / dt, -_F_d), _F_d);
accel += _int;
_deltaV = deltaV;
_time = time;
if (!_yasim) {
m = getprop("/fdm/jsbsim/inertia/weight-lbs");
force = accel * getprop("/fdm/jsbsim/inertia/weight-lbs") * _unitconv;
} else {
m = getprop("/fdm/yasim/gross-weight-lbs");
force = accel * getprop("/fdm/yasim/gross-weight-lbs") * _unitconv;
}
var deltaP = m * (getprop("/sim/model/pushback/target-speed-km_h") - getprop("/gear/gear[0]/rollspeed-ms") * 3.6);
var dP = deltaP - _deltaP_old;
var t = getprop("/sim/time/elapsed-sec");
var dt = math.max(t - _t_old, 0.0001);
_int = math.min(math.max(_int + dP * dt, -_F_i), _F_i);
force = (_K_p * deltaP + _K_d * dP / dt + _K_i * _int) * KG2LB;
# XXX Don't know the formula for lag filter, so I made my own.
var mix = math.min(dt/_T_f, 1.0);
force = force * mix + _force_smooth * (1.0 - mix);
_force_smooth = force;
_deltaP_old = deltaP;
_t_old = t;
var yaw = getprop("/sim/model/pushback/yaw") * _K_yaw;
x = math.cos(yaw);
y = math.sin(yaw);
......@@ -71,16 +72,18 @@ var _start = func() {
setprop("/sim/model/pushback/target-speed-km_h", 0.0)
}, 0.1);
_K_p = getprop("/sim/model/pushback/K_p");
_F_p = getprop("/sim/model/pushback/F_p");
_K_i = getprop("/sim/model/pushback/K_i");
_K_d = getprop("/sim/model/pushback/K_d");
_F_i = getprop("/sim/model/pushback/F_i");
_K_d = getprop("/sim/model/pushback/K_d");
_F_d = getprop("/sim/model/pushback/F_d");
_F = getprop("/sim/model/pushback/F");
_T_f = getprop("/sim/model/pushback/T_f");
_K_yaw = getprop("/sim/model/pushback/yaw-mult") * D2R;
_yasim = (getprop("/sim/flight-model") == "yasim");
_int = 0.0;
_deltaP_old = 0.0;
_t_old = getprop("/sim/time/elapsed-sec");
_force_smooth = 0.0;
_deltaV = 0.0;
_time = systime();
setprop("/sim/model/pushback/connected", 1);
if (!_timer.isRunning) {
if (getprop("/sim/model/pushback/chocks")) {
......@@ -90,14 +93,6 @@ var _start = func() {
gui.popupTip("Pushback connected,\nplease release brakes");
}
}
_speedup_listener = setlistener("/sim/speed-up", func(p) {
var speedup = p.getValue();
if (speedup > 1.0) {
settimer(func() {
gui.popupTip("Time speed-up: " ~ int(speedup) ~ "x\nWarning: pushback may become unstable!");
}, 0.1);
}
});
_timer.start();
}
......@@ -106,16 +101,13 @@ var _stop = func() {
gui.popupTip("Pushback and bypass pin removed");
}
_timer.stop();
if(_speedup_listener != nil) {
removelistener(_speedup_listener);
_speedup_listener = nil;
}
setprop("/sim/model/pushback/force-lbf", 0.0);
if (_yasim) {
setprop("/sim/model/pushback/force-x-yasim", 0.0);
setprop("/sim/model/pushback/force-y-yasim", 0.0);
}
setprop("/sim/model/pushback/connected", 0);
setprop("/sim/model/pushback/enabled", 0);
}
setlistener("/sim/model/pushback/enabled", func(p) {
......
......@@ -9,12 +9,11 @@
var _listener = nil;
var _view_listener = nil;
var _route = [nil, nil, nil, nil];
var _view = nil;
var _view_index = nil;
var _models = [nil, nil, nil, nil];
var _N = 0;
var _show = 0;
var _view_changed = 0;
var _view_changed_or_external = 0;
var _modelprefix = "Models/Autopush/cursor_";
var _start_immediately = nil;
var _S_min = nil;
......@@ -32,7 +31,7 @@ var _add = func(pos) {
_models[_N] = geo.put_model(_modelprefix ~ _N ~ ".xml", pos, 0.0);
_N += 1;
if (_N == 1) {
gui.popupTip("Please click start of the turn");
gui.popupTip("Click start of the turn");
} else if (_N == 2) {
gui.popupTip("Now click end of the turn");
} else if (_N == 3) {
......@@ -70,8 +69,21 @@ var _clear_models = func() {
}
}
var _set_view = func() {
if(!getprop("/sim/current-view/internal")){
_view_changed_or_external = 1;
return;
}
_view_index = getprop("/sim/current-view/view-number");
setprop("/sim/current-view/view-number", view.indexof("Model View"));
_view_changed_or_external = 0;
_view_listener = setlistener("/sim/current-view/name", func {
_view_changed_or_external = 1;
});
}
var _reset_view = func() {
if (!_view_changed) {
if (!_view_changed_or_external) {
setprop("/sim/current-view/view-number", _view_index);
}
if (_view_listener != nil) {
......@@ -113,20 +125,14 @@ setlistener("/sim/model/pushback/route/show", func(p) {
var enter = func(start_immediately = 0) {
clear();
_preload_models();
_view = getprop("/sim/model/pushback/route/view");
_view_index = getprop("/sim/current-view/view-number");
_set_view();
_S_min = getprop("/sim/model/pushback/driver/S_min-m");
setprop("/sim/current-view/view-number", view.indexof("Model View"));
var wp = geo.aircraft_position();
var H = geo.elevation(wp.lat(), wp.lon());
if (H != nil) {
wp.set_alt(H);
}
_add(wp);
_view_changed = 0;
_view_listener = setlistener("/sim/current-view/name", func {
_view_changed = 1;
});
_listener = setlistener("/sim/signals/click", func {
_add(geo.click_position());
});
......
......@@ -578,11 +578,12 @@
<yaw alias="/fdm/jsbsim/gear/unit[0]/steering/pos-deg"/>
<yaw-mult type="float">1.0</yaw-mult>
<target-speed-km_h type="float">0.0</target-speed-km_h>
<K_p type="float">0.005</K_p>
<K_i type="float">0.002</K_i>
<F_i type="float">25000.0</F_i>
<K_p type="float">1.0</K_p>
<F_p type="float">0.1</F_p>
<K_i type="float">0.01</K_i>
<F_i type="float">2.0</F_i>
<K_d type="float">0.0</K_d>
<T_f type="float">2.0</T_f>
<F_d type="float">0.0</F_d>
<driver>
<K_V type="float">10.0</K_V>
<F_V type="float">10.0</F_V>
......
......@@ -55,6 +55,7 @@ Distribute under the terms of GPLv2.
<halign>left</halign>
<label>Connect</label>
<property>/sim/model/pushback/enabled</property>
<live>true</live>
<binding>
<command>dialog-apply</command>
</binding>
......@@ -143,8 +144,8 @@ Distribute under the terms of GPLv2.
<binding>
<command>property-adjust</command>
<property>/sim/model/pushback/target-speed-km_h</property>
<min>-15</min>
<max>15</max>
<min>-25</min>
<max>25</max>
<step>-1</step>
<wrap>false</wrap>
</binding>
......@@ -153,8 +154,8 @@ Distribute under the terms of GPLv2.
<slider>
<row>1</row>
<col>2</col>
<min>-15</min>
<max>15</max>
<min>-25</min>
<max>25</max>
<property>/sim/model/pushback/target-speed-km_h</property>
<live>true</live>
<binding>
......@@ -171,8 +172,8 @@ Distribute under the terms of GPLv2.
<binding>
<command>property-adjust</command>
<property>/sim/model/pushback/target-speed-km_h</property>
<min>-15</min>
<max>15</max>
<min>-25</min>
<max>25</max>
<step>1</step>
<wrap>false</wrap>
</binding>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment