Electrical: rework started; Engine: turn off debug mode by default
This commit is contained in:
parent
b2ae75a4b0
commit
14e421e57e
|
@ -1,3 +1,158 @@
|
|||
var Series = {
|
||||
#//Class for any series connection
|
||||
new: func() {
|
||||
return { parents:[Circuit] };
|
||||
},
|
||||
units: [],
|
||||
addUnit: func(unit){
|
||||
me.units.append(unit);
|
||||
},
|
||||
|
||||
|
||||
totalResistance: func(){
|
||||
var total = 0;
|
||||
foreach(elem; units){
|
||||
total += elem.resistance;
|
||||
}
|
||||
return total;
|
||||
},
|
||||
|
||||
totalPower: func(){
|
||||
var total = 0;
|
||||
foreach(elem; units){
|
||||
total += elem.power;
|
||||
}
|
||||
return total;
|
||||
},
|
||||
|
||||
voltage: 0, #//Volt
|
||||
current: func(){
|
||||
return (me.voltage + math.sqrt(me.voltage * me.voltage - 4 * me.totalResistance * me.totalPower)) / 2 * me.totalResistance; #//Ampere
|
||||
},
|
||||
|
||||
|
||||
#/*calculateVoltage: func(){
|
||||
# foreach(elem; units){
|
||||
# elem.voltage
|
||||
# }
|
||||
#},*/
|
||||
};
|
||||
|
||||
var Circuit = {
|
||||
#//Class for any circuit
|
||||
#//Currently only support one current source in a circuit
|
||||
new: func(cSource) {
|
||||
var new_circuit = { parents:[Circuit] };
|
||||
var new_series = new_circuit.newSeriesWithUnits(cSource);
|
||||
new_circuit.addParallel(new_series);
|
||||
return new_circuit;
|
||||
},
|
||||
|
||||
|
||||
parallelConnection: [],
|
||||
|
||||
newSeriesWithUnits: func(addedUnits...){
|
||||
var newSeries = Series.new();
|
||||
foreach(elem; addedUnits){
|
||||
newSeries.addUnit(elem);
|
||||
}
|
||||
return newSeries;
|
||||
},
|
||||
|
||||
addParallel: func(units){
|
||||
me.parallelConnection.append(units);
|
||||
},
|
||||
|
||||
current: 0, #//Ampere
|
||||
voltage: func(){
|
||||
return parallelConnection[0].units[0].electromotiveForce;
|
||||
}, #//Volt
|
||||
|
||||
calculateParallelVoltage: func(){
|
||||
foreach(elem; parallelConnection){
|
||||
elem.voltage = me.voltage;
|
||||
}
|
||||
}, #//Volt
|
||||
|
||||
totalParalleCurrent: func(){
|
||||
var total = 0;
|
||||
foreach(elem; parallelConnection){
|
||||
total += elem.current;
|
||||
}
|
||||
return total;
|
||||
}, #//Ampere
|
||||
|
||||
|
||||
};
|
||||
|
||||
var Appliance = {
|
||||
#//Class for any electrical appliance
|
||||
new: func() {
|
||||
return { parents:[Appliance] };
|
||||
},
|
||||
|
||||
resistance: 0, #//electric resistance, Ωμέγα
|
||||
voltage: 0, #//electric voltage, Volt
|
||||
current: 0, #//electric current, Ampere
|
||||
power: 0, #//electric power, Watt
|
||||
isResistor: 0,
|
||||
|
||||
applianceName: "Appliance",
|
||||
applianceDescription: "This is a electric appliance",
|
||||
|
||||
setName: func(text){
|
||||
me.applianceName = text;
|
||||
},
|
||||
setDescription: func(text){
|
||||
me.applianceDescription = text;
|
||||
},
|
||||
setResistance: func(r){
|
||||
me.resistance = r;
|
||||
},
|
||||
calculatePower: func(){
|
||||
me.power = me.voltage * me.current;
|
||||
return me.power;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
var CurrentSource = {
|
||||
#//Class for any current source
|
||||
new: func() {
|
||||
return { parents:[Appliance], applianceName: "CurrentSource" };
|
||||
},
|
||||
|
||||
electromotiveForce: 0, #//Volt
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
var cSource = CurrentSource.new();
|
||||
cSource.name = "Battery";
|
||||
cSource.resistance = 13.6 * 0.001;
|
||||
cSource.electromotiveForce = 760;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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-kWs",288000);
|
||||
|
|
|
@ -44,7 +44,7 @@ var Engine = {
|
|||
power: 0, #kW
|
||||
outputForce: 0, #N
|
||||
|
||||
debugMode: 1,
|
||||
debugMode: 0,
|
||||
|
||||
elecNodeI: nil,
|
||||
elecNodeV: nil,
|
||||
|
|
Loading…
Reference in New Issue