コード例 #1
0
        public async Task <bool> StartCharge()
        {
            IsPrecharging = true;

            latestChargeCurrent = 0;

            // Send 50ma so that the voltage can be measured
            ChargerService.RequestedVoltage = RequestedVoltage;
            ChargerService.RequestedCurrent = 0.05f;

            ChargerService.SupplyCurrentLimit = SupplyCurrentLimit;
            batteryIntegrator = 0;

            ChargerService.StopCharge();

            if (await ChargerService.WaitUntilChargerStopped(1000) == false)
            {
                return(false);
            }

            ChargerService.RequestedVoltage = BatteryService.BatteryData.EstimatePackVoltageFromCMUs / 1000;
            ChargerService.StartCharge();

            if (await ChargerService.WaitUntilChargerStarted(3000) == false ||
                await ChargerService.WaitUntilVoltageReached(RequestedVoltage, 10, 10000) == false)
            {
                await StopCharge();

                return(false);
            }

            await BatteryService.EngageContactors();

            if (await BatteryService.WaitUntilContactorsEngage(10000) == false)
            {
                await StopCharge();

                return(false);
            }

            StartTimer();

            IsPrecharging = false;

            return(true);
        }
コード例 #2
0
        public async Task <bool> StartDischarge()
        {
            CanPacket canPacket = new CanPacket(0x508);

            canPacket.SetByte(7, 0x0);
            canControl.ComponentCanService.SetCanToSendAt10Hertz(canPacket);

            await Task.Delay(1000);

            await batteryService.EngageContactors();

            if (!await batteryService.WaitUntilContactorsEngage(5000))
            {
                return(false);
            }

            // Not really necessary but a double check
            if (!batteryService.IsContactorsEngaged)
            {
                return(false);
            }

            canPacket.SetByte(7, 0x30);
            canControl.ComponentCanService.SetCanToSendAt10Hertz(canPacket);

            isDischarging = true;

            chargerUpdateTimer = new System.Timers.Timer
            {
                Interval  = 100,
                AutoReset = true,
                Enabled   = true
            };
            chargerUpdateTimer.Elapsed += DischargerUpdate;

            return(true);
        }