Example #1
0
		/// <summary>
		/// Get the assets and startup some timers to do random movements and other things...
		/// </summary>
		/// <param name="parameters"></param>
		public async void OnStart(object sender, IDictionary<string, object> parameters)
		{
			try
			{
				//Get the audio and image lists for use in the skill
				_audioList = (await _misty.GetAudioListAsync())?.Data;
				_imageList = (await _misty.GetImageListAsync())?.Data;
				
				_misty.Wait(2000);
				
				_misty.PlayAudio("s_Awe.wav", 100, null); 
				_misty.ChangeLED(255, 255, 255, null);
				_misty.DisplayImage("e_ContentRight.jpg", 1, null);  
				
				RegisterEvents();

				//_heartbeatTimer = new Timer(HeartbeatCallback, null, 3000, 3000);
				_moveHeadTimer = new Timer(MoveHeadCallback, null, 10000, 10000);
				_moveArmsTimer = new Timer(MoveArmCallback, null, 10000, 10000);
				_ledTimer = new Timer(ChangeLEDCallback, null, 2000, 2000);
			}
			catch (Exception ex)
			{
				_misty.SkillLogger.Log($"ForceDriving : OnStart: => Exception", ex);
			}
		}
        /// <summary>
        /// This event handler is called when the robot/user sends a start message
        /// The parameters can be set in the Skill Runner (or as json) and used in the skill if desired
        /// </summary>
        /// <param name="parameters"></param>
        public async void OnStart(object sender, IDictionary <string, object> parameters)
        {
            //TODO Put your code here and update the summary above
            int task_id = 0;

            _timeToTellJokes = true;
            try
            {
                //Get the audio and image lists for use in the skill
                _audioList = (await _misty.GetAudioListAsync())?.Data;
                _imageList = (await _misty.GetImageListAsync())?.Data;
                _misty.Wait(2000);

                task_id++;
                _misty.PlayAudio("Misty_Hi.wav", 80, null);
                _misty.Wait(2000);
                _misty.PlayAudio("Misty_I_am_Annie.wav", 80, null);
                _misty.Wait(4000);
                _misty.ChangeLED(255, 255, 255, null);
                _misty.DisplayImage("e_DefaultContent.jpg", 1, null);
                _misty.MoveHead(10, 0, 0, 60, AngularUnit.Degrees, null);

                task_id++;
                _misty.RegisterAudioPlayCompleteEvent(AudioPlayCallback, 0, true, null, null);
                // Temporarily disable this voice recognition of the keyphrase wake up words due to SDK software issue.
                // It will be used the the fix is done.
                // The skill will be initiated by the skill sequencer.
//				_misty.StartKeyPhraseRecognition(null);
//				_misty.RegisterKeyPhraseRecognizedEvent(10, false, "KeyPhrase", null);
//				_misty.KeyPhraseRecognizedEventReceived += ProcessKeyPhraseEvent;
                _misty.StartFaceRecognition(null);
                RegisterEvents();

                task_id++;
                _heartbeatTimer = new Timer(HeartbeatCallback, null, 5000, 3000);
                _moveHeadTimer  = new Timer(MoveHeadCallback, null, 5000, 7000);
                _moveArmsTimer  = new Timer(MoveArmCallback, null, 5000, 4000);
                _ledTimer       = new Timer(ChangeLEDCallback, null, 1000, 1000);
            }
            catch (Exception ex)
            {
                if (task_id == 0)
                {
                    _misty.SkillLogger.LogVerbose($"TellingJokeSkill : Failed to Load audio and image files");
                }
                else if (task_id == 1)
                {
                    _misty.SkillLogger.LogVerbose($"TellingJokeSkill : Failed to play audio and display image files");
                }
                else if (task_id == 2)
                {
                    _misty.SkillLogger.LogVerbose($"TellingJokeSkill : Failed to register events");
                }
                else
                {
                    _misty.SkillLogger.LogVerbose($"TellingJokeSkill : Failed to setup timers");
                }
                _misty.SkillLogger.Log($"TellingJokeSkill : OnStart: => Exception", ex);
            }
        }
Example #3
0
        public async Task RefreshAssetLists()
        {
            //Get the current assets on the robot
            IGetAudioListResponse audioListResponse = await _misty.GetAudioListAsync();

            if (audioListResponse.Status == ResponseStatus.Success && audioListResponse.Data.Count() > 0)
            {
                AudioList = audioListResponse.Data;
            }

            IGetImageListResponse imageListResponse = await _misty.GetImageListAsync();

            if (imageListResponse.Status == ResponseStatus.Success && imageListResponse.Data.Count() > 0)
            {
                ImageList = imageListResponse.Data;
            }

            IGetVideoListResponse videoListResponse = await _misty.GetVideoListAsync();

            if (videoListResponse.Status == ResponseStatus.Success && videoListResponse.Data.Count() > 0)
            {
                VideoList = videoListResponse.Data;
            }
        }
        /// <summary>
        /// Get the assets and startup some timers to do random movements and other things...
        /// </summary>
        /// <param name="parameters"></param>
        public async void OnStart(object sender, IDictionary <string, object> parameters)
        {
            try
            {
                var deviceInfo = await _misty.GetDeviceInformationAsync();

                if (!_misty.Wait(0))
                {
                    return;
                }

                //Get the audio and image lists for use in the skill
                _audioList = (await _misty.GetAudioListAsync())?.Data;

                if (!_misty.Wait(0))
                {
                    return;
                }
                _imageList = (await _misty.GetImageListAsync())?.Data;


                if (!_misty.Wait(0))
                {
                    return;
                }

                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }

                if (_imageList != null && _imageList.Count > 0)
                {
                    ImageDetails randomImage = _imageList[_randomGenerator.Next(0, _imageList.Count - 1)];
                    _misty.DisplayImage(randomImage.Name, 1, null);
                }


                if (!_misty.Wait(2000))
                {
                    return;
                }

                _misty.ChangeLED(255, 255, 255, null);

                //Register a number of events
                _misty.RegisterAudioPlayCompleteEvent(AudioPlayCallback, 0, true, null, null);
                _misty.RegisterCapTouchEvent(CapTouchCallback, 0, true, null, null, null);
                _misty.RegisterKeyPhraseRecognizedEvent(KeyPhraseRecognizedCallback, 250, true, null, null);
                _misty.StartKeyPhraseRecognition(null);
                _misty.StartFaceRecognition(null);

                //Create an event with a specific name so we can unregister it when needed using that name
                _misty.RegisterBumpSensorEvent(BumpCallback, 0, true, null, "MyBumpSensorName", null);

                //Register face rec with keepAlive = false, it will need to be reregistered after triggering if the user wants it to run again
                _misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null);

                //Play audio indicator that the event registration state has changed
                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                    await Task.Delay(1000);

                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }

                if (!_misty.Wait(30000))
                {
                    return;
                }


                //Unregister the bump sensor
                _misty.UnregisterEvent("MyBumpSensorName", UnregisterCallback);

                //Play audio indicator that the event registration state has changed
                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                    await Task.Delay(1000);

                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }

                if (!_misty.Wait(20000))
                {
                    return;
                }

                //Unregister ALL events
                _misty.UnregisterAllEvents(UnregisterCallback);

                //Play audio indicator that the event registration state has changed
                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                    await Task.Delay(1000);

                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }


                if (!_misty.Wait(20000))
                {
                    return;
                }

                //Play audio indicator that the event registration state has changed
                if (_audioList != null && _audioList.Count > 0)
                {
                    AudioDetails randomAudio = _audioList[_randomGenerator.Next(0, _audioList.Count - 1)];
                    _misty.PlayAudio(randomAudio.Name, 100, null);
                    await Task.Delay(1000);

                    _misty.PlayAudio(randomAudio.Name, 100, null);
                }

                //Re-register events
                _misty.RegisterAudioPlayCompleteEvent(AudioPlayCallback, 0, true, null, null);
                _misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null);
                _misty.RegisterCapTouchEvent(CapTouchCallback, 0, true, null, null, null);
                _misty.RegisterKeyPhraseRecognizedEvent(KeyPhraseRecognizedCallback, 0, true, null, null);

                //You can also register events without callbacks, it requires a user to subscribe to that event as follows...
                //Note that this re-registers bump events to play a sound on release, not contact as they were previously handled
                _misty.RegisterBumpSensorEvent(0, true, null, null, null);
                _misty.BumpSensorEventReceived += ProcessBumpEvent;

                //Will continue to process events until timeout of cancel
            }
            catch (Exception ex)
            {
                _misty.SkillLogger.Log($"InteractiveMistySkill : OnStart: => Exception", ex);
            }
        }
Example #5
0
        private async Task LoadAssets()
        {
            //Get the current assets on the robot
            IGetAudioListResponse audioListResponse = await _misty.GetAudioListAsync();

            if (audioListResponse.Status == ResponseStatus.Success && audioListResponse.Data.Count() > 0)
            {
                _audioList = audioListResponse.Data;
            }

            IGetImageListResponse imageListResponse = await _misty.GetImageListAsync();

            if (imageListResponse.Status == ResponseStatus.Success && imageListResponse.Data.Count() > 0)
            {
                _imageList = imageListResponse.Data;
            }

            IGetVideoListResponse videoListResponse = await _misty.GetVideoListAsync();

            if (videoListResponse.Status == ResponseStatus.Success && videoListResponse.Data.Count() > 0)
            {
                _videoList = videoListResponse.Data;
            }

            //Load the assets in the Assets/SkillAssets folder to the robot if they are missing or if ReloadAssets is passed in
            StorageFolder skillAssetFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets\SkillAssets");

            IList <StorageFile> assetFileList = (await skillAssetFolder.GetFilesAsync()).ToList();

            foreach (StorageFile storageFile in assetFileList)
            {
                if (_reloadAssets ||
                    (!_audioList.Any(x => x.Name == storageFile.Name) &&
                     !_imageList.Any(x => x.Name == storageFile.Name) &&
                     !_videoList.Any(x => x.Name == storageFile.Name)))
                {
                    StorageFile file = await skillAssetFolder.GetFileAsync(storageFile.Name);

                    IRandomAccessStreamWithContentType stream = await file.OpenReadAsync();

                    byte[] contents = new byte[stream.Size];
                    await stream.AsStream().ReadAsync(contents, 0, contents.Length);

                    if (storageFile.Name.EndsWith(".mp3") ||
                        storageFile.Name.EndsWith(".wav") ||
                        storageFile.Name.EndsWith(".wma") ||
                        storageFile.Name.EndsWith(".aac"))
                    {
                        if ((await _misty.SaveAudioAsync(storageFile.Name, contents, false, true)).Status == ResponseStatus.Success)
                        {
                            _audioList.Add(new AudioDetails {
                                Name = storageFile.Name, SystemAsset = false
                            });
                            _misty.SkillLogger.LogInfo($"Uploaded audio asset '{storageFile.Name}'");
                        }
                        else
                        {
                            _misty.SkillLogger.Log($"Failed to upload audio asset '{storageFile.Name}'");
                        }
                    }
                    else if (storageFile.Name.EndsWith(".mp4") ||
                             storageFile.Name.EndsWith(".wmv"))
                    {
                        if ((await _misty.SaveVideoAsync(storageFile.Name, contents, false, true)).Status == ResponseStatus.Success)
                        {
                            _videoList.Add(new VideoDetails {
                                Name = storageFile.Name, SystemAsset = false
                            });
                            _misty.SkillLogger.LogInfo($"Uploaded video asset '{storageFile.Name}'");
                        }
                        else
                        {
                            _misty.SkillLogger.Log($"Failed to upload video asset '{storageFile.Name}'");
                        }
                    }
                    else if (storageFile.Name.EndsWith(".jpg") ||
                             storageFile.Name.EndsWith(".jpeg") ||
                             storageFile.Name.EndsWith(".png") ||
                             storageFile.Name.EndsWith(".gif"))
                    {
                        if ((await _misty.SaveImageAsync(storageFile.Name, contents, false, true, 0, 0)).Status == ResponseStatus.Success)
                        {
                            _imageList.Add(new ImageDetails {
                                Name = storageFile.Name, SystemAsset = false
                            });
                            _misty.SkillLogger.LogInfo($"Uploaded image asset '{storageFile.Name}'");
                        }
                        else
                        {
                            _misty.SkillLogger.Log($"Failed to upload image asset '{storageFile.Name}'");
                        }
                    }
                    else
                    {
                        _misty.SkillLogger.Log($"Unknown extension for asset '{storageFile.Name}', could not load to robot.");
                    }
                }
            }
        }