public async Task <bool> DockAsync()
        {
            _abort = false;
            _skillHelper.MistySpeak("Initiating charger docking.");
            _skillHelper.LogMessage("Execute charger docking.");

            _misty.RegisterBatteryChargeEvent(BatteryChargingMessage, 250, true, null, "BatteryChargingEvent", OnResponse);
            _misty.RegisterChargerPoseEvent(ChargerPoseMessage, 100, true, "ChargerPoseEvent", OnResponse);

            if (!await StartChargerDetectionAsync())
            {
                Cleanup();
                return(false);
            }

            // Try to dock N times.
            bool docked  = false;
            int  retries = 0;

            while (!docked && retries++ < DOCKING_MAX_RETRIES && !_abort)
            {
                docked = await ExecuteDockAsync(retries == DOCKING_MAX_RETRIES);
            }

            Cleanup();

            return(docked);
        }
Example #2
0
        public async Task <bool> DockAsync()
        {
            _skillHelper.LogMessage("Execute charger docking.");

            _misty.RegisterBatteryChargeEvent(BatteryChargingMessage, 250, true, null, "BatteryChargingEvent", OnResponse);

            _previousChargerPose = new Queue <ChargerPosition>();
            _abort = false;

            // Pitch sometimes has an offset even when Misty is level.
            _initialPitch = AxisLimited(_skillHelper.ImuPitch);
            _skillHelper.LogMessage($"Initial pitch is {_initialPitch:f3}.");

            _initialYaw = _skillHelper.ImuYaw;

            _misty.RegisterChargerPoseEvent(ChargerPoseMessage, 100, true, "ChargerPoseEvent", OnResponse);

            if (!await StartDockDetectorAsync())
            {
                Cleanup();
                return(false);
            }

            // Try to dock N times.
            bool docked  = false;
            int  retries = 0;

            while (!docked && retries++ < DOCKING_MAX_RETRIES)
            {
                docked = await ExecuteDockAsync();
            }

            Cleanup();

            return(docked);
        }