public override void PowerUpdateCurrentChange() { if (ControllingNode.Node.Data.SupplyDependent[ControllingNode.Node.gameObject.GetInstanceID()].ResistanceComingFrom.Count > 0) { if (!(SlowResponse && PullingWatts == 0)) { ControllingNode.Node.FlushSupplyAndUp(ControllingNode.Node.gameObject); //Room for optimisation CircuitResistance = ElectricityFunctions.WorkOutResistance(ControllingNode.Node.Data.SupplyDependent[ControllingNode.Node.gameObject.GetInstanceID()].ResistanceComingFrom); // //!! VoltageAtChargePort = ElectricityFunctions.WorkOutVoltageFromConnector(ControllingNode.Node, ResistanceSourceModule.ReactionTo.ConnectingDevice); VoltageAtSupplyPort = ElectricityFunctions.WorkOutVoltageFromConnectors(ControllingNode.Node, ControllingNode.CanConnectTo); BatteryCalculation.PowerUpdateCurrentChange(this); if (current != Previouscurrent) { if (Previouscurrent == 0 && !(current <= 0)) { } else if (current == 0 && !(Previouscurrent <= 0)) { ControllingNode.Node.FlushSupplyAndUp(ControllingNode.Node.gameObject); } ControllingNode.Node.Data.SupplyingCurrent = current; Previouscurrent = current; } } } else { CircuitResistance = 999999999999; } PowerSupplyFunction.PowerUpdateCurrentChange(this); }
public override void PowerUpdateCurrentChange() { if (ControllingNode.Node.InData.Data.SupplyDependent.ContainsKey(ControllingNode.Node)) { if (ControllingNode.Node.InData.Data.SupplyDependent[ControllingNode.Node].ResistanceComingFrom.Count > 0) { if (!(SlowResponse && PullingWatts == 0)) { ControllingNode.Node.InData.FlushSupplyAndUp(ControllingNode.Node); //Room for optimisation CircuitResistance = ElectricityFunctions.WorkOutResistance(ControllingNode.Node.InData.Data.SupplyDependent[ControllingNode.Node].ResistanceComingFrom); // //!! VoltageAtChargePort = ElectricityFunctions.WorkOutVoltageFromConnector(ControllingNode.Node, ResistanceSourceModule.ReactionTo.ConnectingDevice); VoltageAtSupplyPort = ElectricityFunctions.WorkOutVoltageFromConnectors(ControllingNode.Node, ControllingNode.CanConnectTo); if (Cansupport) //Denotes capacity to Provide current { //NOTE This assumes that the voltage will be same on either side if (ToggleCansupport && IsAtVoltageThreshold()) // ToggleCansupport denotes Whether at the current time it is allowed to provide current { if (CurrentCapacity > 0) { var needToPushVoltage = StandardSupplyingVoltage - VoltageAtSupplyPort; current = needToPushVoltage / CircuitResistance; if (current > MaximumCurrentSupport) { current = MaximumCurrentSupport; } PullingWatts = ((current * StandardSupplyingVoltage) * (OutputLevel / 100)); // Should be the same as NeedToPushVoltage + powerSupply.ActualVoltage } } else if (PullingWatts > 0) { //Cleaning up values if it can't supply PullingWatts = 0; current = 0; PullLastDeductedTime = -1; } } if (current != Previouscurrent) { if (current == 0) { ControllingNode.Node.InData.FlushSupplyAndUp(ControllingNode.Node); } ControllingNode.Node.InData.Data.SupplyingCurrent = current; Previouscurrent = current; } } } else { CircuitResistance = MonitoringResistance; } } PowerSupplyFunction.PowerUpdateCurrentChange(this); }
public override void PowerNetworkUpdate() { VoltageAtChargePort = ElectricityFunctions.WorkOutVoltageFromConnector(ControllingNode.Node, ResistanceSourceModule.ReactionTo.ConnectingDevice); VoltageAtSupplyPort = ElectricityFunctions.WorkOutVoltageFromConnectors(ControllingNode.Node, ControllingNode.CanConnectTo); BatteryCalculation.PowerNetworkUpdate(this); if (current != Previouscurrent | SupplyingVoltage != PreviousSupplyingVoltage | InternalResistance != PreviousInternalResistance) { ControllingNode.Node.Data.SupplyingCurrent = current; Previouscurrent = current; ControllingNode.Node.Data.SupplyingVoltage = SupplyingVoltage; PreviousSupplyingVoltage = SupplyingVoltage; ControllingNode.Node.Data.InternalResistance = InternalResistance; PreviousInternalResistance = InternalResistance; ElectricalSynchronisation.NUCurrentChange.Add(ControllingNode); } //Logger.Log(CurrentCapacity + " < CurrentCapacity" + ControllingNode.Node.InData.Categorytype, Category.Electrical); }
public override void PowerNetworkUpdate() { VoltageAtChargePort = ElectricityFunctions.WorkOutVoltageFromConnector(ControllingNode.Node, ResistanceSourceModule.ReactionTo.ConnectingDevice); VoltageAtSupplyPort = ElectricityFunctions.WorkOutVoltageFromConnectors(ControllingNode.Node, ControllingNode.CanConnectTo); //Checks if the battery is actually on This is not needed in PowerUpdateCurrentChange Since having those updates Would mean it would be on if (isOnForInterface) { if (CanCharge) { if (ToggleCanCharge) { if (ResistanceSourceModule.Resistance != MonitoringResistance) { ChargingWatts = VoltageAtChargePort / ResistanceSourceModule.Resistance * VoltageAtChargePort; if (chargeCapacityTime) { CurrentCapacity += (ChargingWatts * (Time.time - ChargLastDeductedTime) * (InputLevel / 100)); } ChargLastDeductedTime = Time.time; if (VoltageAtChargePort > IncreasedChargeVoltage && ChargingDivider < MaxChargingDivider) { //Increasing the current charge by ChargingDivider += 10; ResistanceSourceModule.Resistance = 1000 / (StandardChargeNumber / ChargingDivider); } else if (VoltageAtChargePort < ExtraChargeCutOff) { if (10 < ChargingDivider) { ChargingDivider -= 10; ResistanceSourceModule.Resistance = 1000 / (StandardChargeNumber / ChargingDivider); } else { //Turning off charge if it pulls too much ChargingWatts = 0; ChargingDivider = 10; ResistanceSourceModule.Resistance = MonitoringResistance; chargeCapacityTime = false; } } if (CurrentCapacity >= CapacityMax) { CurrentCapacity = CapacityMax; ChargingWatts = 0; ToggleCansupport = true; ChargingDivider = 10; ResistanceSourceModule.Resistance = MonitoringResistance; chargeCapacityTime = false; } } else if (VoltageAtChargePort > IncreasedChargeVoltage && CurrentCapacity < CapacityMax) { if (ChargingDivider == 0) { ChargingDivider = 10; } ResistanceSourceModule.Resistance = 1000 / (StandardChargeNumber / ChargingDivider); chargeCapacityTime = true; ChargLastDeductedTime = Time.time; } } else if (ResistanceSourceModule.Resistance != MonitoringResistance) { ChargingWatts = 0; ChargingDivider = 10; ResistanceSourceModule.Resistance = MonitoringResistance; chargeCapacityTime = false; } } if (Cansupport) { if (ToggleCansupport) { if (PullingWatts > 0) { if (PullLastDeductedTime <= 0) { PullLastDeductedTime = Time.time; } CurrentCapacity -= (PullingWatts * (OutputLevel / 100)) * (Time.time - PullLastDeductedTime); PullLastDeductedTime = Time.time; if (CurrentCapacity <= 0) { CurrentCapacity = 0; ToggleCansupport = false; PullingWatts = 0; current = 0; PullLastDeductedTime = -1; } } else if (VoltageAtSupplyPort < MinimumSupportVoltage && CurrentCapacity > 0) { var needToPushVoltage = StandardSupplyingVoltage - VoltageAtSupplyPort; current = needToPushVoltage / CircuitResistance; if (current > MaximumCurrentSupport) { current = MaximumCurrentSupport; } PullingWatts = ((current * StandardSupplyingVoltage) * (OutputLevel / 100)); } } else if (PullingWatts > 0) { PullingWatts = 0; current = 0; PullLastDeductedTime = -1; } } } if (current != Previouscurrent | SupplyingVoltage != PreviousSupplyingVoltage | InternalResistance != PreviousInternalResistance) { ControllingNode.Node.InData.Data.SupplyingCurrent = current; Previouscurrent = current; ControllingNode.Node.InData.Data.SupplyingVoltage = SupplyingVoltage; PreviousSupplyingVoltage = SupplyingVoltage; ControllingNode.Node.InData.Data.InternalResistance = InternalResistance; PreviousInternalResistance = InternalResistance; ElectricalManager.Instance.electricalSync.NUCurrentChange.Add(ControllingNode); } }