public async Task BasicChargeStartStopTest()
        {
            BatteryChargeService batteryChargeService = BatteryChargeService.NewInstance;

            batteryChargeService.UseTimerUpdateLoop = false;
            batteryChargeService.SetCharger(NewTDKService());

            uint state = batteryChargeService.ChargerState;

            Assert.IsTrue(state != CanReceivingNode.STATE_NA, "Charger does not seem to be there");

            Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be as it has not yet been started");

            // 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 = 34;

            SetCellVoltages(batteryChargeService.BatteryService.BatteryData, 4100);
            Assert.IsTrue(await batteryChargeService.StartCharge(), "Charger start failed");
            Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be");

            // 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);

            await batteryChargeService.StopCharge();

            Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be");
        }
Example #2
0
        public async Task BasicChargeStartStopTest()
        {
            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;
            }

            uint state = batteryChargeService.ChargerState;

            Assert.IsTrue(state != CanReceivingNode.STATE_NA, "Charger does not seem to be there");

            Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be as it has not yet been started");

            // 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");

            // 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);

            await batteryChargeService.StopCharge();

            Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be");
        }
Example #3
0
        public void CreateChargeService()
        {
            BatteryChargeService batteryChargeService = BatteryChargeService.NewInstance;

            Assert.AreEqual(batteryChargeService.ChargeToPercentage, 100);
        }
Example #4
0
        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");
        }