FDM: Added custom ABS. System: Started custom electrical system.

This commit is contained in:
Sidi Liang 2019-07-26 17:59:54 +08:00
parent 303ff00ef3
commit ef8c5fa2f7
11 changed files with 154 additions and 25 deletions

BIN
Models/.DS_Store vendored

Binary file not shown.

Binary file not shown.

Before

(image error) Size: 7.1 KiB

After

(image error) Size: 7.8 KiB

Binary file not shown.

After

(image error) Size: 21 KiB

Binary file not shown.

After

(image error) Size: 3.5 KiB

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<PropertyList>
<sim>
<model>
<livery>
<name type="string">Speed and power</name>
<texture>Messages/Speed and power.png</texture>
</livery>
</model>
</sim>
</PropertyList>

Binary file not shown.

Before

(image error) Size: 22 KiB

After

(image error) Size: 93 KiB

58
Nasal/electrical.nas Normal file
View File

@ -0,0 +1,58 @@
var electric_init = func(){ #Initialize
props.getNode("/",1).setValue("/systems/electrical/e-tron/battery-kWh",80);
props.getNode("/",1).setValue("/systems/electrical/e-tron/battery-U-V",760);
props.getNode("/",1).setValue("/systems/electrical/e-tron/switch/bat-fwd-eng",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/switch/bat-bwd-eng",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/fwd-eng-U-V",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/fwd-eng-U-V-max",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/bwd-eng-U-V",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/bwd-eng-U-V-max",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/fwd-eng-I-A",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/fwd-eng-I-A-max",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/bwd-eng-I-A",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/bwd-eng-I-A-max",0);
print("Electrical system initiallized!");
}
var electric_update = func(){
if(props.getNode("/",1).getValue("/systems/electrical/e-tron/switch/bat-fwd-eng") == 1){
props.getNode("/",1).setValue("/systems/electrical/e-tron/fwd-eng-U-V-max",380);
props.getNode("/",1).setValue("/systems/electrical/e-tron/fwd-eng-I-A-max",747);
}else{
props.getNode("/",1).setValue("/systems/electrical/e-tron/fwd-eng-U-V-max",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/fwd-eng-I-A-max",0);
}
if(props.getNode("/",1).getValue("/systems/electrical/e-tron/switch/bat-bwd-eng") == 1){
props.getNode("/",1).setValue("/systems/electrical/e-tron/bwd-eng-U-V-max",380);
props.getNode("/",1).setValue("/systems/electrical/e-tron/bwd-eng-I-A-max",747);
}else{
props.getNode("/",1).setValue("/systems/electrical/e-tron/bwd-eng-U-V-max",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/bwd-eng-I-A-max",0);
}
}
var electricTimer = maketimer(1, electric_update);
var startElectricalSystemUpdate = func(){
electricTimer.start();
print("Electrical system update started!");
}
var stopElectricalSystemUpdate = func(){
electricTimer.stop();
print("Electrical system update stopped!");
}
var resetElectricalSystemUpdate = func(){
electricTimer.stop();
electric_init();
electricTimer.start();
print("Electrical system update reseted!");
}
var L = setlistener("/sim/signals/fdm-initialized", func{
electric_init();
electricTimer.start();
removelistener(L);
});

View File

@ -1,37 +1,67 @@
var max_P_KW = 568;
var gearratio = 9.73;
props.getNode("/",1).setValue("/controls/engines/engine/rpm1",1000);
props.getNode("/",1).setValue("/controls/engines/engine/direction",1);
props.getNode("/",1).setValue("/controls/engines/engine/started",0);
props.getNode("/",1).setValue("/controls/gear/brake-cmd",0);
var update_engine = func(){
var direction = getprop("/controls/engines/engine/direction");
var throttle = getprop("/controls/engines/engine/throttle");
var rpm = getprop("/controls/engines/engine/rpm1");
var rpm_rate = throttle*max_P_KW*0.06;
var max_rpm = throttle*max_P_KW*90+1000;
var throttle = props.getNode("/",1).getValue("/controls/engines/engine/throttle");
var direction = props.getNode("/",1).getValue("/controls/engines/engine/direction");
var fwdUNode = props.getNode("/systems/electrical/e-tron/fwd-eng-U-V",1);
var fwdANode = props.getNode("/systems/electrical/e-tron/fwd-eng-I-A",1);
var bwdUNode = props.getNode("/systems/electrical/e-tron/bwd-eng-U-V",1);
var bwdANode = props.getNode("/systems/electrical/e-tron/bwd-eng-I-A",1);
var fwdMaxU = props.getNode("/",1).getValue("/systems/electrical/e-tron/fwd-eng-U-V-max");
var fwdMaxA = props.getNode("/",1).getValue("/systems/electrical/e-tron/fwd-eng-I-A-max");
var bwdMaxU = props.getNode("/",1).getValue("/systems/electrical/e-tron/bwd-eng-U-V-max");
var bwdMaxA = props.getNode("/",1).getValue("/systems/electrical/e-tron/bwd-eng-I-A-max");
fwdUNode.setValue(throttle * fwdMaxU);
fwdANode.setValue(throttle * fwdMaxA);
bwdUNode.setValue(throttle * bwdMaxU);
bwdANode.setValue(throttle * bwdMaxA);
var fwdPower = fwdUNode.getValue() * fwdANode.getValue();
var bwdPower = bwdUNode.getValue() * bwdANode.getValue();
var cmd_P_kW = (fwdPower + bwdPower)/1000;
#var cmd_P_kW = throttle*max_P_kW;
var rpm = props.getNode("/",1).getValue("/controls/engines/engine/rpm1");
var rpm_rate = cmd_P_kW * 0.06;
var max_rpm = cmd_P_kW * 90 + 1000;
if(rpm > max_rpm){
rpm_rate = -20;
}else if(rpm == max_rpm){
rpm_rate = 0;
}else{
rpm_rate = throttle*max_P_KW*0.053;
rpm_rate = cmd_P_kW* 0.06;
}
var rpmActual = rpm_calculate(rpm_rate);
var torque = 0;
if(rpmActual == 0){
torque = 0;
}else{
torque = (throttle*max_P_KW*1000)/(rpmActual*6.283*0.1667);#max 967
torque = (cmd_P_kW * 1000) / (rpmActual * 6.283 * 0.1667);#max 967
}
var force = 3.33*direction*torque*gearratio;
#print("torque:"~torque);
props.getNode("/",1).setValue("/fdm/jsbsim/external_reactions/engine/magnitude", force);
}
var engineTimer = maketimer(0.001, update_engine);
var rpm_calculate = func(rpm_rate){
var rpm = getprop("/controls/engines/engine/rpm1");
var rpm2 = 0;
var gearspeed = math.round(getprop("/gear/gear/rollspeed-ms"));
var gearspeed = math.round(props.getNode("/",1).getValue("/gear/gear/rollspeed-ms"));
var rpm2 = (gearspeed/0.3)*9.8;
#print(rpm2);
rpm_rate = rpm_rate/1000;
@ -42,18 +72,24 @@ var rpm_calculate = func(rpm_rate){
return rpmActual;
}
var engineTimer = maketimer(0.001, update_engine);
var startEngine = func(){
props.getNode("/",1).setValue("/controls/engines/engine/started",1);
props.getNode("/",1).setValue("/systems/electrical/e-tron/switch/bat-fwd-eng",1);
props.getNode("/",1).setValue("/systems/electrical/e-tron/switch/bat-bwd-eng",1);
engineTimer.start();
print("Engine started");
}
var stopEngine = func(){
props.getNode("/",1).setValue("/controls/engines/engine/started",0);
props.getNode("/",1).setValue("/fdm/jsbsim/external_reactions/engine/magnitude", 0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/switch/bat-fwd-eng",0);
props.getNode("/",1).setValue("/systems/electrical/e-tron/switch/bat-bwd-eng",0);
engineTimer.stop();
print("Engine stopped");
}

View File

@ -31,6 +31,37 @@ var rearright_door = aircraft.door.new("/controls/doors/rearright", 1);
beacon_switch = props.globals.getNode("controls/switches/warninglight", 2);
var beacon = aircraft.light.new( "/sim/model/lights/warning", [0.5, 0.5], "/controls/lighting/warning" );
beacon_switch = props.globals.getNode("controls/switches/indicator-left", 2);
var beacon = aircraft.light.new( "/sim/model/lights/indicator-left", [0.8, 0.5], "/controls/lighting/indicator-left" );
var beacon = aircraft.light.new( "/sim/model/lights/indicator-left", [0.8, 0.5], "/controls/lighting/indicator-left");
beacon_switch = props.globals.getNode("controls/switches/indicator-right", 2);
var beacon = aircraft.light.new( "/sim/model/lights/indicator-right", [0.8, 0.5], "/controls/lighting/indicator-right" );
var beacon = aircraft.light.new( "/sim/model/lights/indicator-right", [0.8, 0.5], "/controls/lighting/indicator-right");
var brakesABS = func(){
var gearFrtLftSpeed = math.round(props.getNode("/",1).getValue("/fdm/jsbsim/gear/unit/wheel-speed-fps"));
var gearFrtRgtSpeed = math.round(props.getNode("/",1).getValue("/fdm/jsbsim/gear/unit[1]/wheel-speed-fps"));
var gearBckLftSpeed = math.round(props.getNode("/",1).getValue("/fdm/jsbsim/gear/unit[2]/wheel-speed-fps"));
var gearBckRgtSpeed = math.round(props.getNode("/",1).getValue("/fdm/jsbsim/gear/unit[3]/wheel-speed-fps"));
if(gearFrtLftSpeed == 0 or gearBckLftSpeed == 0 or gearFrtRgtSpeed == 0 or gearBckRgtSpeed == 0){
props.getNode("/",1).setValue("/controls/gear/brake-left", 0);
props.getNode("/",1).setValue("/controls/gear/brake-right", 0);
}else{
props.getNode("/",1).setValue("/controls/gear/brake-left", 1);
props.getNode("/",1).setValue("/controls/gear/brake-right", 1);
}
}
var absTimer = maketimer(0.001, brakesABS);
var brakeWithABS = func(){
var brakeCmd = props.getNode("/",1).getValue("/controls/gear/brake-cmd");
if(brakeCmd){
absTimer.start();
}else{
absTimer.stop();
}
}
setlistener("/controls/gear/brake-cmd", brakeWithABS);

View File

@ -226,23 +226,13 @@
<repeatable>false</repeatable>
<binding>
<command>property-assign</command>
<property>/controls/gear/brake-left</property>
<value>1</value>
</binding>
<binding>
<command>property-assign</command>
<property>/controls/gear/brake-right</property>
<property>/controls/gear/brake-cmd</property>
<value>1</value>
</binding>
<mod-up>
<binding>
<command>property-assign</command>
<property>/controls/gear/brake-left</property>
<value>0</value>
</binding>
<binding>
<command>property-assign</command>
<property>/controls/gear/brake-right</property>
<property>/controls/gear/brake-cmd</property>
<value>0</value>
</binding>
</mod-up>
@ -291,6 +281,9 @@
<engine>
<file>Aircraft/followme_e-tron/Nasal/engine.nas</file>
</engine>
<electrical>
<file>Aircraft/followme_e-tron/Nasal/electrical.nas</file>
</electrical>
</nasal>
</PropertyList>

View File

@ -140,8 +140,8 @@
</propulsion>
<flight_control name="Truck">
<channel name="Steer">
<summer name="Steer Sum">
<input>fcs/rudder-cmd-norm</input>
<clipto>