Engine: Bug fix

Instruments: Added warning message
This commit is contained in:
Sidi Liang 2021-08-16 20:04:42 +08:00
parent ccbbae7e99
commit 090149ac0c
No known key found for this signature in database
GPG Key ID: 9785F5EECFFA5311
3 changed files with 53 additions and 10 deletions

View File

@ -18,6 +18,7 @@ var SmartInstruments = {
m.group = m.instrumentCanvas.createGroup();#//Main group
m.signGroup = m.instrumentCanvas.createGroup();#//sign group
m.welcomeGroup = m.instrumentCanvas.createGroup();
m.mapGroup = m.instrumentCanvas.createGroup(); #//map group
m.instrumentCanvas.addPlacement({"node": placement});
#Sign svg
canvas.parsesvg(
@ -51,6 +52,13 @@ var SmartInstruments = {
.setColor(1,0,0) # Text color
.setText("SELF TEST NORMAL")
.show();
m.warningText = m.group.createChild("text", "optional-id-for element")
.setTranslation(530, 140) # The origin is in the top left corner
.setAlignment("left-center") # All values from osgText are supported (see $FG_ROOT/Docs/README.osgtext)
.setFont("ExoRegular-ymMe.ttf") # Fonts are loaded either from $AIRCRAFT_DIR/Fonts or $FG_ROOT/Fonts
.setFontSize(50) # Set fontsize and optionally character aspect ratio
.setColor(1,0,0) # Text color
.setText("WARNING MESSAGE");
#//speedometer
m.speedometer = m.group.createChild("text", "optional-id-for element")
.setTranslation(1205, 380) # The origin is in the top left corner
@ -109,10 +117,16 @@ var SmartInstruments = {
.setFontSize(40) # Set fontsize and optionally character aspect ratio
.setColor(1,1,1) # Text color
.setText("9:41");
#//Map
#//Map Structure is a mess, removed
m.init();
return m;
},
initialized: 0,
loopCount:0,
showingWarningMessage: 0,
enableStartupSound: func(){
me.startupSoundIsEnabled = 1;
@ -138,6 +152,7 @@ var SmartInstruments = {
},
update: func(){
#//Speedometer
me.loopCount += 1;
var currentSpeedKMH = sprintf("%i", me.information.getSpeedKMH());
me.speedometer.updateText(currentSpeedKMH);
if(autospeed.active == 1){
@ -174,6 +189,15 @@ var SmartInstruments = {
var minute = me.information.getTimeMinute();
if(minute < 10) minute = "0"~minute;
me.timeDisplay.updateText(hour~":"~minute);
#//Warning MESSAGE
if(me.showingWarningMessage){
if(math.mod(me.loopCount, 10) == 0){
me.warningText.show();
}else{
me.warningText.hide();
}
}
},
updateTimer:nil,
@ -198,7 +222,7 @@ var SmartInstruments = {
me.gearDisplay.enableUpdate();
me.tempDisplay.enableUpdate();
me.timeDisplay.enableUpdate();
me.warningText.enableUpdate();
if(me.startupSound and me.startupSoundIsEnabled) followme.playAudio(me.startupSound, 1, me.startupSoundPath);
@ -215,6 +239,13 @@ var SmartInstruments = {
if(me.updateTimer != nil) me.updateTimer.stop();
me.group.hide();
me.welcomeGroup.hide();
},
showWarningMessage:func(msg){
me.warningText.setText(msg);
me.showingWarningMessage = 1;
},
hideWarningMessage:func(){
me.showingWarningMessage = 0;
}
};

View File

@ -69,7 +69,7 @@ var Series = {
return 0;#//No voltage, no current.
}
print("U ",U," R ",R," Pout ",Pout);
#//print("U ",U," R ",R," Pout ",Pout);
var deltaSquared = U*U - 4*R*Pout;
@ -96,11 +96,17 @@ var Series = {
#foreach(elem; me.units){
# totalTmp += elem.current * elem.current * elem.resistance + elem.activePower + elem.activePower_kW * 1000;
#}
foreach(elem; me.units){
elem.voltage = me.current * elem.resistance + (elem.activePower + elem.activePower_kW * 1000) / me.current;
if(me.current){
elem.voltage = me.current * elem.resistance + (elem.activePower + elem.activePower_kW * 1000) / me.current;
}else{
elem.voltage = 0;
}
#var factor = (elem.current * elem.current * elem.resistance + elem.activePower + elem.activePower_kW * 1000)/totalTmp;
#elem.voltage = me.voltage * factor;
electricalDebug.debugPrint("elem volt" ~ elem.voltage, 3);
electricalDebug.debugPrint(elem.applianceName ~ " volt" ~ elem.voltage, 3);
}
electricalDebug.debugPrint("____________________________SeriesVoltage calculated____________________________", 3);
},
@ -392,7 +398,7 @@ var Cable = {
}
};
var cSource = CurrentSource.new(0.0136, 450, kWh2kWs(82), "Battery");#//Battery for engine, 82kWh, 450V
var cSource = CurrentSource.new(0.0136, 405, kWh2kWs(82), "Battery");#//Battery for engine, 82kWh, 405V
var circuit_1 = Circuit.new(cSource);#//Engine circuit
var cSource_small = CurrentSource.new(0.0136, 12, kWh2kWs(0.72), "Battery");#//Battery for other systems, 60Ah, 12V

View File

@ -95,6 +95,8 @@ var Engine = {
ratedVoltage: 0, #//Rated voltage
ratedCurrent: 0, #//Rated Current, calculated when initializing
errorMessage: nil,
rpm_calculate: func(angularAcceleration){
var direction = me.getDirection();
@ -164,10 +166,9 @@ var Engine = {
var mode = me.engineNode.mode.getValue();
me.mode = mode;
if(!me.voltage){
me.rpm = 0;
me.engineNode.rpmNode.setValue(0);
outputForce(0);
if(me.voltage <= 0){
me.stopEngine();
me.errorMessage = "NO POWER";
return 0;
}
@ -222,9 +223,14 @@ var Engine = {
me.printDebugInfo();
}
outputForce(me.outputForce * N2LBS);
if(me.errorMessage){
smartInstruments.smartInstruments.showWarningMessage(err);
}else{
smartInstruments.smartInstruments.hideWarningMessage();
}
},
engineTimer: nil,