private void RegisterEvents() { //Register Bump Sensors with a callback _misty.RegisterBumpSensorEvent(BumpCallback, 50, true, null, null, null); //Front Right Time of Flight List <TimeOfFlightValidation> tofFrontRightValidations = new List <TimeOfFlightValidation>(); tofFrontRightValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontRight }); _misty.RegisterTimeOfFlightEvent(TOFFRRangeCallback, 0, true, tofFrontRightValidations, "FrontRight", null); //Front Left Time of Flight List <TimeOfFlightValidation> tofFrontLeftValidations = new List <TimeOfFlightValidation>(); tofFrontLeftValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontLeft }); _misty.RegisterTimeOfFlightEvent(TOFFLRangeCallback, 0, true, tofFrontLeftValidations, "FrontLeft", null); //Front Center Time of Flight List <TimeOfFlightValidation> tofFrontCenterValidations = new List <TimeOfFlightValidation>(); tofFrontCenterValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontCenter }); _misty.RegisterTimeOfFlightEvent(TOFCRangeCallback, 0, true, tofFrontCenterValidations, "FrontCenter", null); //Back Time of Flight List <TimeOfFlightValidation> tofBackValidations = new List <TimeOfFlightValidation>(); tofBackValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.Back }); _misty.RegisterTimeOfFlightEvent(TOFBRangeCallback, 0, true, tofBackValidations, "Back", null); //Setting debounce a little higher to avoid too much traffic //Firmware will do the actual stop for edge detection List <TimeOfFlightValidation> tofFrontRightEdgeValidations = new List <TimeOfFlightValidation>(); tofFrontRightEdgeValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.DownwardFrontRight }); _misty.RegisterTimeOfFlightEvent(FrontEdgeCallback, 1000, true, tofFrontRightEdgeValidations, "FREdge", null); List <TimeOfFlightValidation> tofFrontLeftEdgeValidations = new List <TimeOfFlightValidation>(); tofFrontLeftEdgeValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.DownwardFrontLeft }); _misty.RegisterTimeOfFlightEvent(FrontEdgeCallback, 1000, true, tofFrontLeftEdgeValidations, "FLEdge", null); }
public void OnStart(object sender, IDictionary <string, object> parameters) { _misty.TransitionLED(255, 140, 0, 0, 0, 255, LEDTransition.Breathe, 1000, null); _misty.Wait(3000); _misty.ChangeLED(0, 0, 255, null); //Register Bump Sensors with a callback _misty.RegisterBumpSensorEvent(BumpCallback, 0, true, null, null, null); //Register Cap Touch with a callback _misty.RegisterCapTouchEvent(CapTouchCallback, 0, true, null, null, null); }
public async void OnStart(object sender, IDictionary <string, object> parameters) { ProcessParameters(parameters); await _assetWrapper.LoadAssets(_reloadAssets); //Attempts to run the C# MoveArmsAndHead skill in this repository _misty.RunSkill("7c7342f9-9155-4968-a8ea-82123c4c5282", null, null); _misty.RegisterBumpSensorEvent(BumpCallback, 0, true, null, null, null); while (_misty.Wait(_random.Next(8000, 15000))) { Ewww(); } }
/// <summary> /// Register the desired startup events, more may be registered separately as needed /// </summary> private void RegisterEvents() { //Bumps _misty.RegisterBumpSensorEvent(BumpCallback, 0, true, null, null, null); //Cap touch _misty.RegisterCapTouchEvent(CapTouchCallback, 0, true, null, null, null); //TOF List <TimeOfFlightValidation> tofFrontRightValidations = new List <TimeOfFlightValidation>(); tofFrontRightValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.3 }); tofFrontRightValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontRight }); _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 300, true, tofFrontRightValidations, null, null); List <TimeOfFlightValidation> tofFrontLeftValidations = new List <TimeOfFlightValidation>(); tofFrontLeftValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.3 }); tofFrontLeftValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontLeft }); _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 300, true, tofFrontLeftValidations, null, null); List <TimeOfFlightValidation> tofBackValidations = new List <TimeOfFlightValidation>(); tofBackValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.3 }); tofBackValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.Back }); _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 300, true, tofBackValidations, null, null); List <TimeOfFlightValidation> tofFrontCenterValidations = new List <TimeOfFlightValidation>(); tofFrontCenterValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.3 }); tofFrontCenterValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontCenter }); _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 300, true, tofFrontCenterValidations, null, null); }
public async void OnStart(object sender, IDictionary <string, object> parameters) { //callback example _misty.ChangeLED(255, 36, 0, OnResponse); _misty.Wait(2000); //second callback example _misty.ChangeLED(0, 36, 255, OnResponse); _misty.Wait(1500); //async example await _misty.ChangeLEDAsync(255, 140, 0); //event registration _misty.RegisterBumpSensorEvent(BumpCallback, 0, true, null, null, null); }
/// <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 void OnStart(object sender, IDictionary <string, object> parameters) { _misty.ChangeLED(255, 255, 0, null); OnQueryResultReceived += ProcessQueryResult; _client = new HttpClient(); _misty.RegisterBumpSensorEvent(onBumped, 20, true, null, "bumped", null); _misty.RegisterCapTouchEvent(onTouched, 20, true, null, "toched", null); try { _credential = getAuthToken()?.Result; } catch (Exception ex) { _misty.SkillLogger.Log("Unable to authenticate dialogflow client.", ex); } }
/// <summary> /// Register the desired startup events, more may be registered separately as needed /// </summary> private void RegisterEvents() { //Voice Rec _misty.RegisterKeyPhraseRecognizedEvent(KeyPhraseRecognizedCallback, 0, true, null, null); //Face rec _misty.RegisterFaceRecognitionEvent(FaceRecCallback, 0, false, null, null, null); //Bumps _misty.RegisterBumpSensorEvent(BumpCallback, 0, true, null, null, null); //Cap touch _misty.RegisterCapTouchEvent(CapTouchCallback, 0, true, null, null, null); //TOF List <TimeOfFlightValidation> tofFrontRightValidations = new List <TimeOfFlightValidation>(); tofFrontRightValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.15 }); tofFrontRightValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontRight }); _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 50, true, tofFrontRightValidations, null, null); List <TimeOfFlightValidation> tofFrontLeftValidations = new List <TimeOfFlightValidation>(); tofFrontLeftValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.15 }); tofFrontLeftValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.FrontLeft }); _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 50, true, tofFrontLeftValidations, null, null); List <TimeOfFlightValidation> tofBackValidations = new List <TimeOfFlightValidation>(); tofBackValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.DistanceInMeters, Comparison = ComparisonOperator.LessThanOrEqual, ComparisonValue = 0.15 }); tofBackValidations.Add(new TimeOfFlightValidation { Name = TimeOfFlightFilter.SensorName, Comparison = ComparisonOperator.Equal, ComparisonValue = TimeOfFlightPosition.Back }); _misty.RegisterTimeOfFlightEvent(TOFRangeCallback, 50, true, tofBackValidations, null, null); }
/// <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); } }
/// <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="sender"></param> /// <param name="parameters"></param> public async void OnStart(object sender, IDictionary <string, object> parameters) { try { await InitializeSkill(); await ProcessStartupParameters(parameters); await ProcessAdjustableParameters(parameters); _misty.ChangeLED(255, 0, 0, null); if (!_misty.Wait(0)) { return; } //Spanish translations List <BumpSensorValidation> backLeftBumpValidations = new List <BumpSensorValidation>(); backLeftBumpValidations.Add(new BumpSensorValidation(BumpSensorFilter.SensorName, ComparisonOperator.Equal, BumpSensorPosition.BackLeft)); backLeftBumpValidations.Add(new BumpSensorValidation(BumpSensorFilter.IsContacted, ComparisonOperator.Equal, true)); _misty.RegisterBumpSensorEvent(ProcessBackLeftBumpEvent, 250, true, backLeftBumpValidations, null, null); //Face Rec on/off toggle List <BumpSensorValidation> backRightBumpValidations = new List <BumpSensorValidation>(); backRightBumpValidations.Add(new BumpSensorValidation(BumpSensorFilter.SensorName, ComparisonOperator.Equal, BumpSensorPosition.BackRight)); backRightBumpValidations.Add(new BumpSensorValidation(BumpSensorFilter.IsContacted, ComparisonOperator.Equal, true)); _misty.RegisterBumpSensorEvent(ProcessBackRightBumpEvent, 250, true, backRightBumpValidations, null, null); //Picture description List <BumpSensorValidation> frontRightBumpValidations = new List <BumpSensorValidation>(); frontRightBumpValidations.Add(new BumpSensorValidation(BumpSensorFilter.SensorName, ComparisonOperator.Equal, BumpSensorPosition.FrontRight)); frontRightBumpValidations.Add(new BumpSensorValidation(BumpSensorFilter.IsContacted, ComparisonOperator.Equal, true)); _misty.RegisterBumpSensorEvent(ProcessFrontRightBumpEvent, 250, true, frontRightBumpValidations, null, null); //Repeat List <BumpSensorValidation> frontLeftBumpValidations = new List <BumpSensorValidation>(); frontLeftBumpValidations.Add(new BumpSensorValidation(BumpSensorFilter.SensorName, ComparisonOperator.Equal, BumpSensorPosition.FrontLeft)); frontLeftBumpValidations.Add(new BumpSensorValidation(BumpSensorFilter.IsContacted, ComparisonOperator.Equal, true)); _misty.RegisterBumpSensorEvent(ProcessFrontLeftBumpEvent, 250, true, frontLeftBumpValidations, null, null); RegisterUserEvents(); if (!_misty.Wait(2000)) { return; } //All ready to go _assetWrapper.PlaySystemSound(SystemSound.Amazement); _assetWrapper.ShowSystemImage(SystemImage.EcstacyStarryEyed); _misty.ChangeLED(0, 0, 255, null); if (!_misty.Wait(1500)) { return; } BroadcastDetails("Hello! How are you?", _defaultVoice); await _misty.TransitionLEDAsync(255, 0, 0, 0, 0, 255, LEDTransition.Breathe, 500); _misty.Wait(1500); await _misty.TransitionLEDAsync(0, 0, 255, 255, 140, 0, LEDTransition.Breathe, 1000); /* * //Test code to describe a random image at this URL * BroadcastDetails("Describing random image."); * _misty.Wait(500); * string description = await _azureCognitive.AnalyzeImage("http://junglebiscuit.com/images/random/rand_image.pl"); * BroadcastDetails(description); */ } catch (Exception ex) { _misty.SkillLogger.Log("Failed while starting the skill.", ex); } }