public void SetChargePower() { TDKService tdkService = NewTDKService(); tdkService.StartCharge(); Assert.IsTrue(tdkService.IsCharging, "Charger is not charging and should be"); tdkService.RequestedCurrent = 3.2f; tdkService.RequestedVoltage = 32.1f; // We call it twice as it gets set on the first time and read on the second tdkService.ChargerUpdateInner(); tdkService.ChargerUpdateInner(); Assert.AreEqual(tdkService.ActualCurrent, 0); Assert.AreEqual(tdkService.ActualVoltage, tdkService.RequestedVoltage, 0.5); tdkService.StopCharge(); Assert.IsFalse(tdkService.IsCharging, "Charger is still charging and should be stopped"); }
public async Task BalancingChargeTest() { BatteryChargeService batteryChargeService = BatteryChargeService.NewInstance; batteryChargeService.UseTimerUpdateLoop = false; CanService canService = CanService.NewInstance; canService.ConnectViaLoopBack(); TDKService tdkService = NewTDKService(); tdkSimulator.BatteryConnected = true; batteryChargeService.SetCharger(NewTDKService()); batteryChargeService.BatteryService.BatteryData.ComponentCanService = canService; if (batteryChargeService.BatteryService.BatteryData.GetBMU(0) != null) { batteryChargeService.BatteryService.BatteryData.GetBMU(0).ComponentCanService = canService; } if (batteryChargeService.BatteryService.BatteryData.GetBMU(1) != null) { batteryChargeService.BatteryService.BatteryData.GetBMU(1).ComponentCanService = canService; } Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be - Point 1"); // Bit out of order but we simulate the contactors engaging now as we can't insert it during the call to StartCharge EngageContactors(batteryChargeService.BatteryService.BatteryData); // Battery is now setup in normal state, run the charge loop batteryChargeService.RequestedCurrent = 5; batteryChargeService.RequestedVoltage = 32; batteryChargeService.BatteryService.BatteryData.ParallelStrings = 1; SetCellVoltages(batteryChargeService.BatteryService.BatteryData, 4100); SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData); Assert.IsTrue(await batteryChargeService.StartCharge(), "Charger start failed"); Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be"); SetChargeVoltageError(batteryChargeService.BatteryService.BatteryData, 100, -50); SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData); batteryChargeService.ChargerUpdateInner(); tdkService.ChargerUpdateInner(); tdkService.ChargerUpdateInner(); Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 2"); // Keep sending heartbeats so we don't time out SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData); Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 3"); Assert.AreEqual(batteryChargeService.RequestedVoltage, batteryChargeService.ChargerActualVoltage, "Requested Voltage has not flowed through"); Assert.IsTrue(batteryChargeService.ChargerService.RequestedCurrent > 0, "Battery does not appear to be charging"); Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 4"); for (int i = 0; i < 10; i++) { batteryChargeService.ChargerUpdateInner(); tdkService.ChargerUpdateInner(); SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData); } Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 3"); float batteryChargerCurrent = batteryChargeService.ChargerService.RequestedCurrent; // Battery over charged SetChargeVoltageError(batteryChargeService.BatteryService.BatteryData, -35, -50); for (int i = 0; i < 10; i++) { batteryChargeService.ChargerUpdateInner(); tdkService.ChargerUpdateInner(); SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData); } Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 4"); Assert.IsTrue(batteryChargeService.ChargerService.RequestedCurrent < batteryChargerCurrent, "Current should be going down as we are balancing, but it is not"); // Bit out of order but we simulate the contactors disengaging now as we can't insert it during the call to StartCharge DisengageContactors(batteryChargeService.BatteryService.BatteryData); Assert.IsTrue(await batteryChargeService.StopCharge(), "Battery did not stop as expected"); Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be as it has been shutdown"); }