예제 #1
0
            protected override async void nextStageAction()
            {
                try
                {
                    MasterSpellLibrary.SpellFeedbackSFX.Stop();
                    await Task.Delay(150);

                    MasterSpellLibrary.SpellProgressSFX.Play();
                    await Task.Delay(1000); // Give a moment to get ready.

                    //Current.SpellBeingTrained.AddGlyph(new Glyph(AverageAttitude, Stillness.StillnessScore, AverageAttitude.StdDev));
                    Current.SpellBeingTrained.AddGlyph(new Glyph(AverageAttitude, Stillness.StillnessScore, 0));
                    Current.CheckGlyphCount();

                    var EulerAngles = AverageAttitude.Average.ToEulerAngles();
                    //Log.Debug("SpellTraining", $"Saved glyph at yaw {EulerAngles.X:f2}, pitch {EulerAngles.Y}, and roll {EulerAngles.Z} from zero stance.");
                    //Log.Debug("SpellTraining", $"Saved {((GestureRecognizerStage)CurrentStage).Label} at {EulerAngles:f1} from zero stance.  That's {AverageAttitude.Average.AngleTo(lastOrientation):f0} degrees from the last one.  Baselines are {Stillness.StillnessScore:f2} for stillness, {AverageAttitude.StdDev:f2} for orientation.");
                    Log.Debug("SpellTraining", $"Saved {((GestureRecognizerStage)CurrentStage).Label} at {EulerAngles:f1} from zero stance.  That's {AverageAttitude.Average.AngleTo(lastOrientation):f0} degrees from the last one.  Baseline is {Stillness.StillnessScore:f2} for stillness.");
                    CurrentStage = new GlyphTrainingStage($"Glyph {Current.SpellBeingTrained.Glyphs.Count}", Implement, AttitudeProvider);
                }
                catch (Exception e)
                {
                    Log.Error("Glyph training stage progression", e.Message);
                    throw;
                }
            }
예제 #2
0
        public void Stop(bool force = false)
        {
            try
            {
                if (IsPlaying)
                {
                    _player.Stop();
                }
            }
            catch (Exception ex)
            {
                Log.Error(TAG, $"Error during stop: {ex.Message}");
                Log.Debug(TAG, ex.ToString());
            }
            finally
            {
                if (_lock != null)
                {
                    _lock.Release();
                    _lock = null;
                }

                StopForeground(force);
                StopSelf(_startId);

                _startId = 0;
            }
        }
예제 #3
0
            public TumblerFindingStage(string label, Toolkit toolkit, Tumbler tgtTumbler, AngleAxisProvider provider) : base(label)
            {
                Kit           = toolkit;
                targetTumbler = tgtTumbler;

                AttitudeProvider = provider;
                SetUpProvider(AttitudeProvider, allowProviderToPersist: true);

                LastAngle = Angle = AttitudeProvider.Angle;
                Log.Debug("TumblerStage|Ctor", $"Initial angle: {Angle}");
                TargetAngle       = tgtTumbler.Angle;
                RequiredDirection = tgtTumbler.Direction;
                // Certain special tumblers - like ResetToZero - have a designated direction of zero, meaning "opposite to current setting."
                if (tgtTumbler.Direction == 0)
                {
                    RequiredDirection = -1 * Math.Sign(provider.Angle);
                }

                // CurrentDirection is based on AngleTrend.
                AngleTrend = new RollingAverage <double>(5);

                InterimInterval = TimeSpan.FromMilliseconds(20);

                Activate();
            }
예제 #4
0
            protected override void interimAction()
            {
                if (AccelProvider.Vector == null || AccelProvider.Vector.LengthSquared() < 0.001)
                {
                    return;                                                                               // Throw out the initial zeroes before our sensors are live.
                }
                AverageRotationSpeed.Update(GyroProvider.Vector.Length());
                AverageAxis.Update(GyroProvider.Vector.Normalize());
                AverageAccel.Update(AccelProvider.Vector);
                //AverageAttitude.Update(AttitudeProvider.Quaternion);

                thisStroke.Snapshots.Add(new StrokeSnapshot()
                {
                    RotationVelocity = AverageRotationSpeed.Average,
                    Axis             = AverageAxis.Average.Normalize(),
                    Accel            = AverageAccel.Average,
                    //Orientation = AverageAttitude.Average,
                    Orientation = AttitudeProvider.Quaternion,
                    Timestamp   = GyroProvider.nanosecondsElapsed
                });

                count++;
                if (count % 10 == 1)
                {
                    Log.Debug("Snapshot", $"{thisStroke.Snapshots.Last()} - Approach {ClosestApproachToInitial:f2} / {ClosestApproachToFinal:f2}");
                }
            }
예제 #5
0
        //protected void FindAllViews()
        //{
        //    _gestureClassLabel = FindViewById<TextView>(Resource.Id.melee_gc_label);

        //    _qualityThis = FindViewById<TextView>(Resource.Id.melee_qual_this);
        //    _qualityAvg = FindViewById<TextView>(Resource.Id.melee_qual_avg);
        //    _qualityRatio = FindViewById<TextView>(Resource.Id.melee_qual_ratio);

        //    _delayThis = FindViewById<TextView>(Resource.Id.melee_delay_this);
        //    _delayAvg = FindViewById<TextView>(Resource.Id.melee_delay_avg);
        //    _delayRatio = FindViewById<TextView>(Resource.Id.melee_delay_ratio);

        //    _durationThis = FindViewById<TextView>(Resource.Id.melee_dur_this);
        //    _durationAvg = FindViewById<TextView>(Resource.Id.melee_dur_avg);
        //    _durationRatio = FindViewById<TextView>(Resource.Id.melee_dur_ratio);

        //    _numptsThis = FindViewById<TextView>(Resource.Id.melee_numpts_this);
        //    _numptsAvg = FindViewById<TextView>(Resource.Id.melee_numpts_avg);
        //    _numptsRatio = FindViewById<TextView>(Resource.Id.melee_numpts_ratio);

        //    _pkaccelThis = FindViewById<TextView>(Resource.Id.melee_pkaccel_this);
        //    _pkaccelAvg = FindViewById<TextView>(Resource.Id.melee_pkaccel_avg);
        //    _pkaccelRatio = FindViewById<TextView>(Resource.Id.melee_pkaccel_ratio);

        //    _userTrainingBtn = FindViewById<Button>(Resource.Id.melee_user_training_btn);
        //    _cuedSingleBtn = FindViewById<Button>(Resource.Id.melee_cued_single_btn);
        //    _cuedSeriesBtn = FindViewById<Button>(Resource.Id.melee_cued_series_btn);
        //}

        #endregion

        #region Activity Lifecycle Methods
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.SimpleListPage);
            //FindAllViews();

            //GestureClassList = FragmentManager.FindFragmentById<GestureClassListFragment>(Resource.Id.mlrn_gestureclass_list_fragment);
            //LatestSample = FragmentManager.FindFragmentById<LatestSampleFragment>(Resource.Id.mlrn_latest_sample_display);

            Dataset    = new DataSet <DKS>();
            Classifier = new Classifier(); // Just in case; it's not actually going to get used in this version.

            //SetUpButtonClicks();

            // Debugging
            var q1 = Quaternion.CreateFromAxisAngle(Vector3.One, 0.25f);
            var q2 = Quaternion.Identity;

            Log.Debug(_tag, $"First test: quat {q1} + quat {q2} = quat {q1 + q2}.");
            Log.Debug(_tag, $"Second test: Operator.Add(q1, q2) = {Operator.Add(q1, q2)}");
            var dks1 = new DKS();

            dks1.Values.Value4 = q1;
            var dks2 = new DKS();

            dks2.Values.Value4 = q2;
            var dksSum = dks1 + dks2;

            Log.Debug(_tag, $"Third test: dks1 + dks2 = dks3 w/ orientation {dksSum.Orientation}");
            var dksSum2 = Operator.Add(dks1, dks2);

            Log.Debug(_tag, $"Fourth test: Operator.Add(dks1, dks2) = dks3 w/ orientation {dksSum2.Orientation}");
        }
예제 #6
0
 public LockTumblerLiftingStage(string label, Toolkit toolkit, Tumbler tgtTumbler, AngleAxisProvider oProvider = null)
     : base(label, toolkit, Tumbler.PinMoveTarget, oProvider)
 {
     Log.Debug("Lockpicking|TumblerLifting", $"Lifting {label}");
     AngleRateOfChange = new RollingAverage <float>(5, 0f);
     tumblerUnderway   = tgtTumbler;
 }
예제 #7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.SpellTraining);

            currentSignalsDisplay = FindViewById <TextView>(Resource.Id.current_signals_text);
            bestSignalsDisplay    = FindViewById <TextView>(Resource.Id.best_signals_text);
            resultsDisplay        = FindViewById <TextView>(Resource.Id.result_text);

            SetUpSpellButtons();

            // See if the current focus is already in our (local, for now) library, and load it if so.  Otherwise, take us to calibration.
            var focusString = Res.SpecificTags.Get(InteractionLibrary.CurrentSpecificTag);

            if (focusString != null && focusString.Length > 0)
            {
                ThePlayersFocus = Focus.FromString(focusString, InteractionLibrary.CurrentSpecificTag);
            }
            else if (InteractionLibrary.CurrentSpecificTag == InteractionLibrary.SpellTeaching.Name + "0000")
            {
                Focus.InitMasterFocus();
                InteractionLibrary.CurrentSpecificTag = Focus.MasterFocus.TagID;
                Log.Info("Training", "Using master focus.");
                ThePlayersFocus = Focus.MasterFocus;
            }
            else
            {
                ThePlayersFocus = new Focus(InteractionLibrary.CurrentSpecificTag);
            }

            CurrentStage = GestureRecognizerStage.NullStage;
        }
예제 #8
0
 public Commessa()
 {
     //registro il view model e lo inserisco nel binding context dell'activity view
     InitializeComponent();
     vm                = (CommessaViewModel)(ServiceLocator.Current.GetInstance(typeof(CommessaViewModel)));
     vm.Navigation     = this.Navigation;
     vm.filterCommesse = "Tutti";
     BindingContext    = vm;
     ((CommessaViewModel)BindingContext).Initialize(this);
     try
     {
         MessagingCenter.Subscribe <string, string>(MessagingCenterEvents.Subscriber, MessagingCenterEvents.AlertError, async(sender, msg) =>
         {
             if (!string.IsNullOrEmpty(msg))
             {
                 await DisplayAlert("Informazione", msg, "OK");
             }
         });
     }
     catch (TargetInvocationException ecx)
     {
         Log.Error("AppOfficina", ecx.StackTrace);
     }
     catch (Exception ecc)
     {
         Log.Error("AppOfficina", ecc.Message);
     }
 }
예제 #9
0
        protected void LoadMeleeClassifier()
        {
            foreach (var option in new string[] { OFFENSE, DEFENSE })
            {
                try
                {
                    ClassifierTree cTree;
                    string         contents;

                    AssetManager assets   = this.Assets;
                    var          filename = $"{option}.{Classifier.FileExtension}";
                    var          filepath = $"{GetExternalFilesDir(null)}/{filename}";

                    using (StreamReader sr = new StreamReader(assets.Open(filename)))
                    {
                        contents = sr.ReadToEnd();
                        cTree    = Serializer.Deserialize <ClassifierTree>(contents);
                        if (cTree != null)
                        {
                            Log.Debug("Loading classifier", $"Loaded our {option} classifier tree (from asset file).");
                        }
                    }

                    if (cTree == null)
                    {
                        using (var streamReader = new StreamReader(filepath))
                        {
                            contents = streamReader.ReadToEnd();
                            Log.Debug("Loading classifier", $"Loading our {option} classifier tree, it currently contains: \n\n{contents}\n");

                            cTree = Serializer.Deserialize <ClassifierTree>(contents);
                        }
                    }
                    if (cTree == null)
                    {
                        throw new Exception($"Classifier deserialization failed - filename {filepath}");
                    }

                    CueClassifiers[option] = cTree.MainClassifier;
                    Dataset = new DataSet <DKS> {
                        Name = cTree.MainClassifier.MatchingDatasetName
                    };
                    foreach (var gClass in cTree.GestureClasses)
                    {
                        Dataset.AddClass(gClass);
                        //if (cTree.CueClassifiers.ContainsKey(gClass.className)) CueClassifiers.Add(gClass.className, cTree.CueClassifiers[gClass.className]);
                    }
                    SelectedGestureClass = Dataset.Classes.FirstOrDefault();
                }
                catch (Exception ex)
                {
                    Log.Debug("MachineLearning|Load Classifier", ex.ToString());
                    Speech.SayAllOf("Cannot launch melee - no melee classifier found.").Wait();
                    Finish();
                }
            }
        }
예제 #10
0
 public VaultTumblerFindingStage(string label, Toolkit toolkit, Tumbler tgtTumbler, AngleAxisProvider oProvider)
     : base(label, toolkit, tgtTumbler, oProvider)
 {
     DegreesBetweenClicks = Current.LockBeingOpened.DegreesBetweenClicks;
     TotalClicks          = (int)(360 / DegreesBetweenClicks);
     LastClicks           = CurrentClicks = Clicks(oProvider.Angle);
     TargetClicks         = Clicks(tgtTumbler.Angle);
     Log.Debug("Safecracking|TumblerFinding", $"Starting to search for {label}");
 }
예제 #11
0
            protected override async Task abortActionAsync()
            {
                var gravVector = AttitudeProvider.Vector.Normalize();

                Log.Debug("TumblerStage|Abort", $"Gravity vector ({gravVector}) closer to 'Up' than to 'Horizontal' ({AttitudeProvider.Axis}) - indicates restart.");
                await Speech.SayAllOf("Whoops. Off axis. Start over.");

                AttitudeProvider.Deactivate();
                Current.SeekReadyPosition();
            }
예제 #12
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            Log.Info("Motion", "{0} // {1} // {2} // {3}", e.ActionMasked.ToString(), e.Action.ToString(), e.ActionIndex, e.PointerCount);
            if (e.Action == MotionEventActions.Down || (int)e.ActionMasked == (int)MotionEventActions.PointerDown)
            {
                var ind = e.Action == MotionEventActions.Down ? 0 : e.ActionIndex;
                pointers [ind] = new PointF {
                    X = e.GetX(ind), Y = e.GetY(ind)
                };
            }
            else if (e.Action == MotionEventActions.Up ||
                     (int)e.ActionMasked == (int)MotionEventActions.PointerUp)
            {
                if (e.Action == MotionEventActions.Up)
                {
                    for (int i = 0; i < pointers.Length; ++i)
                    {
                        pointers [i] = null;
                    }
                }
                else
                {
                    var id = e.GetPointerId(e.ActionIndex);
                    pointers [id] = null;
                    generator.SetFingerCoefficient(id, 0);
                }
            }
            else if (e.Action == MotionEventActions.Move)
            {
                for (int i = 0; i < e.PointerCount; ++i)
                {
                    var pointerIndex = e.GetPointerId(i);
                    pointers[pointerIndex] = new PointF {
                        X = e.GetX(i), Y = e.GetY(i)
                    };
                }
            }

            generator.CarrierFrequency = (e.GetY() / Height) * (600 - 80) + 80;
            for (int i = 0; i < pointers.Length; i++)
            {
                var amp = pointers [i] == null ? 0 : 6 * (pointers [i].Value.X / Width);
                generator.SetFingerCoefficient(i, amp);
                Log.Info("NewAmp", "{0} -> {1}", i, amp);
            }

            if (!played)
            {
                player.Play();
                played = true;
            }

            Invalidate();
            return(true);
        }
예제 #13
0
        private void HandleProposal(object sender, EventArgs <Message> e)
        {
            var msg = e.Value;

            if (msg.Type != Communications.MsgType.Notify || !msg.Content.StartsWith(PROPOSE))
            {
                return;
            }
            Log.Debug(_tag, "Received opponent's proposal message.");
            opponentsProposal = msg;
            opponentsProposalSignal.Set();
        }
예제 #14
0
 protected override void interimAction()
 {
     base.interimAction();
     if (object.ReferenceEquals(targetTumbler, Tumbler.ResetToZero) &&
         Math.Abs(Angle) < Current.LockBeingOpened.RotationAccuracyRequired * 2)
     {
         targetTumbler     = Current.LockBeingOpened.Tumblers[0];
         TargetAngle       = targetTumbler.Angle;
         RequiredDirection = targetTumbler.Direction;
         Plugin.Vibrate.CrossVibrate.Current.Vibration(5);
     }
     Log.Debug("Lockpicking|TumblerFinding", $"Aiming for {TargetAngle}, currently at {Angle}.");
 }
예제 #15
0
            protected override async Task nextStageActionAsync()
            {
                await AttitudeProvider.SetFrameShiftFromCurrent();

                SpellBeingTrained.ZeroStance = AttitudeProvider.FrameShift;

                Log.Debug("SpellTraining", $"Zero stance assigned at {SpellBeingTrained.ZeroStance.ToEulerAngles():f1}.");

                await Speech.SayAllOf("Begin");

                //Speech.Say("Begin");
                CurrentStage = new GlyphTrainingStage($"Glyph 0", Implement, AttitudeProvider);
            }
예제 #16
0
            protected override void interimAction()
            {
                LastAngle = Angle;
                Angle     = AttitudeProvider.Angle;
                var angleChange = Angle - LastAngle;

                Log.Debug("TumblerStage|Interim", $"New angle: {Angle}");
                if (Math.Abs(angleChange) > 15.0)
                {
                    Log.Debug("LockOpening|InterimAction", $"Caution - Angle changed by {angleChange:f1}.");
                }
                AngleTrend.Update(angleChange);
            }
예제 #17
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            var formatted = formatter?.Invoke(state, exception)
                            ?? exception?.ToString()
                            ?? state?.ToString()
                            ?? eventId.ToString();

            AndroidLog.WriteLine(logLevel.ToLogPriority(), Tag, formatted);
        }
예제 #18
0
        protected void RelayMessage(int ResourceID, string message)
        {
            var v = FindViewById <TextView>(ResourceID);

            if (v == null)
            {
                Log.Error("LockOpeningActivity:RelayMessage", $"Unable to find field {ResourceID} so as to pass message << {message} >>");
                return;
            }
            RunOnUiThread(() =>
            {
                v.Text       = message;
                v.Visibility = ViewStates.Visible;
            });
        }
예제 #19
0
        protected virtual async void LimberUpVolumeReleased(object sender, EventArgs e)
        {
            (CurrentStage as LimberingUpStage).StopAndReturnValues(out Vector3 axis, out Vector3 upDir);
            AxisVector = axis;
            UpVector   = upDir;
            Log.Debug("Locks|LimberUp", $"Axis Vector is {AxisVector:f2}, up vector is {UpVector:f2}");

            await Task.Delay(250);

            OnVolumeButtonPressed  -= LimberUpVolumePressed;
            OnVolumeButtonReleased -= LimberUpVolumeReleased;
            OnVolumeButtonPressed  += HandleVolumeButtonPressed;
            OnVolumeButtonReleased += HandleVolumeButtonReleased;
            SeekReadyPosition();
        }
예제 #20
0
        protected async Task <IChoreographer> InitChoreographer()
        {
            if (!CueClassifiers.ContainsKey(OFFENSE))
            {
                throw new Exception($"{OFFENSE} classifier not found.");
            }
            if (!CueClassifiers.ContainsKey(DEFENSE))
            {
                throw new Exception($"{DEFENSE} classifier not found.");
            }

            // Establish the choreographer - this depends on whether you're connected or not (and on Solipsism mode)
            if (Communications.Bluetooth.BluetoothMessageCenter.TemporaryAddressBook_SingleEntry == null)
            {
                if (!Res.SolipsismMode)
                {
                    return(new SimpleChoreographer(CueClassifiers));
                }
                else
                {
                    return(new SolipsisticChoreographer(CueClassifiers));
                }
            }
            else
            {
                Message myProposal = new Message(MsgType.Notify, PROPOSE);
                Communications.Bluetooth.BluetoothMessageCenter.TemporaryAddressBook_SingleEntry.SendMessage(myProposal);
                Log.Debug(_tag, "Sent proposal message.");
                await opponentsProposalSignal.WaitAsync();

                if (String.Compare(myProposal.ID, opponentsProposal.ID) == 0)
                {
                    Log.Debug(_tag, "Tie GUID encountered - WTF???");
                    return(await InitChoreographer());
                }
                else if (String.Compare(myProposal.ID, opponentsProposal.ID) > 0)
                {
                    Log.Debug(_tag, "My GUID wins - I'm choreographer.");
                    return(new SendingChoreographer(Communications.Bluetooth.BluetoothMessageCenter.TemporaryAddressBook_SingleEntry, CueClassifiers));
                }
                else
                {
                    Log.Debug(_tag, "My GUID loses - the other guy is choreographer this time.");
                    return(new ReceivingChoreographer(Communications.Bluetooth.BluetoothMessageCenter.TemporaryAddressBook_SingleEntry));
                }
            }
        }
예제 #21
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.MeleeTraining);

            currentSignalsDisplay = FindViewById <TextView>(Resource.Id.current_signals_text);
            bestSignalsDisplay    = FindViewById <TextView>(Resource.Id.best_signals_text);
            resultsDisplay        = FindViewById <TextView>(Resource.Id.result_text);

            SetUpFormButtons();

            // See if the current sword is already in our (local, for now) library, and load it if so.  Otherwise, create one.
            var swordString = Res.SpecificTags.Get(InteractionLibrary.CurrentSpecificTag);

            if (swordString != null && swordString.Length > 0)
            {
                ThePlayersSword = Sword.FromString(swordString, InteractionLibrary.CurrentSpecificTag);
                CurrentStage    = GestureRecognizerStage.NullStage;
                return;
            }
            else if (InteractionLibrary.CurrentSpecificTag == InteractionLibrary.MeleeTeaching.Name + "0000")
            {
                Sword.InitMasterSword();
                InteractionLibrary.CurrentSpecificTag = Sword.MasterSword.TagID;
                Log.Info("Training", "Using master sword.");
                ThePlayersSword = Sword.MasterSword;
            }
            else
            {
                ThePlayersSword = new Sword(InteractionLibrary.CurrentSpecificTag);
            }

            if (ThePlayersSword.EnGardeOrientation == null || ThePlayersSword.EnGardeOrientation.Average.AngleTo(Quaternion.Identity) < 1)
            {
                await Speech.SayAllOf("No pre-existing ahn garde stance found.  Please take and hold your ahn garde stance to begin.");

                CurrentStage = new DefineEnGardeStage("Defining new en garde", true);
            }
            else
            {
                await Speech.SayAllOf("Confirm your saved ahn garde stance to begin.");

                setFormNameButton.Text = RetrainEnGardeText;
                CurrentStage           = new EnGardeStage("Confirm en garde", "Okay. Use onscreen buttons to train specific forms.", GestureRecognizerStage.NullStage, true);
            }
        }
예제 #22
0
        private void WriteLine(object message, LogPriority priority)
        {
            var trace        = new StackTrace().GetFrame(2).GetMethod();
            var callerMethod = trace.DeclaringType.FullName;

            Log.WriteLine(priority, callerMethod, message.ToString());
            string logHeader = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss,fff} " +
                               $"{priority.ToString().ToUpper()}  {callerMethod}";
            string logMessage = message.ToString();

            lock (_lock)
            {
                using StreamWriter logWritter = new StreamWriter(CurrentLogPath, true, Encoding.UTF8);
                logWritter.WriteLine(logHeader);
                logWritter.WriteLine($" {logMessage}");
                logWritter.WriteLine();
            }
        }
예제 #23
0
            protected override async Task nextStageActionAsync()
            {
                if (IsInitialPoseEstimate)
                {
                    Current.FormBeingTrained.InitialOrientation = AttitudeProvider.Quaternion;
                    Log.Debug("Stroke still stances", $"Still position #1 set at {AttitudeProvider.Quaternion}, {AttitudeProvider.Quaternion.AngleTo(Quaternion.Identity)} degrees from En Garde.");
                    CurrentStage = new FormSetupStage($"{Current.FormBeingTrained.FormName} form, second still pose", AttitudeProvider, true);
                }
                else
                {
                    await Speech.SayAllOf("Thank you. Take your ahngarde stance again.");

                    Current.FormBeingTrained.FinalOrientation = AttitudeProvider.Quaternion;
                    Log.Debug("Stroke still stances", $"Still position #2 set at {AttitudeProvider.Quaternion}, {AttitudeProvider.Quaternion.AngleTo(Quaternion.Identity)} degrees from En Garde.");
                    CurrentStage = new EnGardeStage("En Garde before stroke training", "Wait for the cue, then execute the form as you wish it to be judged in play.",
                                                    new StrokeTrainingStage($"{Current.FormBeingTrained.FormName}, stroke training, rep 0"), true);
                }
            }
예제 #24
0
        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException("logEvent");
            }
            var renderSpace = new StringWriter();

            _textFormatter.Format(logEvent, renderSpace);

            var tag = logEvent.Properties.Where(x => x.Key == Constants.SourceContextPropertyName).Select(x => x.Value.ToString("l", null)).FirstOrDefault() ?? "";

            switch (logEvent.Level)
            {
            case LogEventLevel.Debug:
                AndroidLog.Debug(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Information:
                AndroidLog.Info(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Verbose:
                AndroidLog.Verbose(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Warning:
                AndroidLog.Warn(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Error:
                AndroidLog.Error(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Fatal:
                AndroidLog.Wtf(tag, renderSpace.ToString());
                break;

            default:
                AndroidLog.WriteLine(LogPriority.Assert, tag, renderSpace.ToString());
                break;
            }
        }
예제 #25
0
            protected override async Task nextStageActionAsync()
            {
                //await AttitudeProvider.SetFrameShiftFromCurrent();
                //Blade.EnGardeOrientation = new AdvancedRollingAverageQuat(10, null, AttitudeProvider.FrameShift.Inverse());
                //Blade.EnGardeOrientation = new AdvancedRollingAverageQuat(10, null, AverageAttitude.Average, 1.0f);
                Blade.EnGardeOrientation = AverageAttitude;
                Blade.EnGardeOrientation.Update(AttitudeProvider.Quaternion);
                Log.Debug("Melee Training", $">>>> Setting en garde to {Blade.EnGardeOrientation.Average}, with sigma {Blade.EnGardeOrientation.Sigma}.  In reference frame {AttitudeProvider.FrameShift}.");
                Blade.SaveSpecifics(); // Saves both the average attitude itself, and also the standard deviation of it.  Important for later!

                await Speech.SayAllOf("Okay.  Use the onscreen controls to train specific forms.");

                CurrentStage = GestureRecognizerStage.NullStage;
                Current.formNameTextbox.Enabled = true;
                //await Speech.SayAllOf("Begin");
                //if (Current.AppendMode == null || Current.AppendMode == false)
                //    CurrentStage = new FormSetupStage($"{Label} form prep", AttitudeProvider);
                //else
                //    CurrentStage = new StrokeTrainingStage($"{Label} appending ({Current.FormBeingTrained.Strokes.Count})", AttitudeProvider);
            }
예제 #26
0
        protected async void RespondToPromptCue(object o, EventArgs <ChoreographyCue> eargs)
        {
            CurrentCue = eargs.Value;
            Classifier = CueClassifiers[CurrentCue.ClassifierKey];
            //await GimmeCue(eargs.Value.GestureClass);
            SelectedGestureClass = Classifier.MatchingDatasetClasses[CurrentCue.GestureClassIndex];
            if (CurrentCue.CueTime < DateTime.Now)
            {
                Log.Debug(_tag, $"Timing issue - CurrentCue.CueTime is {CurrentCue.CueTime}, now is {DateTime.Now}.");
                CurrentCue.CueTime = DateTime.Now + TimeSpan.FromMilliseconds(250);
            }
            var delay = CurrentCue.CueTime - DateTime.Now;
            await Task.Delay(delay);

            Speech.Say(SelectedGestureClass.className, SoundOptions.AtSpeed(2.0));
            Stopwatch.Restart();
            if (_singleMode)
            {
                MeleeChoreographer.Deactivate();
            }
        }
예제 #27
0
            protected override async Task nextStageActionAsync()
            {
                if (Current.setFormNameButton.Text == RetrainEnGardeText)
                {
                    Current.setFormNameButton.Text = "Random";                                                       // Undoes our little textual flag that lets us retrain the en garde using this button instead of its usual function.
                }
                var oldOrientation = Blade.EnGardeOrientation.Average;

                Blade.EnGardeOrientation.Update(AttitudeProvider.Quaternion); // Subtle trick: we keep averaging the En Garde orientation so it "tracks" the player's shifts in taking it, over time.
                Log.Debug("EnGarde Stage", $"Updating the prior en garde ({oldOrientation}), using the new one ({AttitudeProvider.Quaternion}," +
                          $" {AttitudeProvider.Quaternion.AngleTo(oldOrientation)} degrees away), producing a new one ({Blade.EnGardeOrientation.Average}," +
                          $" {Blade.EnGardeOrientation.Average.AngleTo(oldOrientation)} degrees away from the prior one).");

                //// In order to *pass along* a provider, to an arbitrary Gesture Stage which has already been created and passed to us
                //// (and which might or might not want to use our provider at all), we use this trick.  Activate it in here, and during
                //// activation, a specific STATIC provider is made available.  We lock so that (in theory) two EnGarde Stages which were
                //// running in separate threads wouldn't end up accessing the static value at the wrong times.
                //using (await _asyncLock.LockAsync())
                //{
                //    //EngardeProvider = AttitudeProvider; // Can be referenced from inside the prestartAction of the provided stage, if desired. (Not during the ctor... that's already gone by!)
                //    EngardeProvider = new FrameShiftedOrientationProvider(Android.Hardware.SensorType.GameRotationVector);
                //    await Task.WhenAll(EngardeProvider.SetFrameShiftFromCurrent(), Speech.Say(NextStageCue));
                //    CurrentStage = NextStage;
                //    CurrentStage.Activate();
                //    EngardeProvider = null;
                //}

                // Different approach to solving the above problem.
                var EngardeProvider = new FrameShiftedOrientationProvider(Android.Hardware.SensorType.GameRotationVector);
                await Task.WhenAll(EngardeProvider.SetFrameShiftFromCurrent(), Speech.SayAllOf(NextStageCue));

                CurrentStage = NextStage;
                var cStage = CurrentStage as ITakeAnAttitudeProvider;

                if (cStage != null)
                {
                    cStage.AttitudeProvider = EngardeProvider;
                }
                CurrentStage.Activate();
            }
예제 #28
0
            protected override async void nextStageAction()
            {
                try
                {
                    MasterSpellLibrary.SpellFeedbackSFX.Stop();
                    await Task.Delay(150);

                    MasterSpellLibrary.SpellProgressSFX.Play();
                    await Task.Delay(1000); // Give a moment to get ready.

                    //Current.SpellBeingTrained.AddGlyph(new Glyph(AverageAttitude, Stillness.StillnessScore, AverageAttitude.StdDev));
                    //Current.SpellBeingTrained.AddGlyph(new Glyph(AverageAttitude, Stillness.StillnessScore, 0));
                    //Current.CheckGlyphCount();
                    TargetGlyph.Orientation = AverageAttitude;

                    //var EulerAngles = AverageAttitude.Average.ToEulerAngles();
                    var o = TargetGlyph.Orientation;
                    //Log.Debug("SpellTraining", $"Saved glyph at yaw {EulerAngles.X:f2}, pitch {EulerAngles.Y}, and roll {EulerAngles.Z} from zero stance.");
                    //Log.Debug("SpellTraining", $"Saved {((GestureRecognizerStage)CurrentStage).Label} at {EulerAngles:f1} from zero stance.  That's {AverageAttitude.Average.AngleTo(lastOrientation):f0} degrees from the last one.  Baselines are {Stillness.StillnessScore:f2} for stillness, {AverageAttitude.StdDev:f2} for orientation.");
                    Log.Debug("SpellTraining", $"Glyph {TargetGlyph.Name} recorded at:          {o.X}, {o.Y}, {o.Z}, {o.W}");
                    GlyphQuaternions += $"{TargetGlyph.Name}                {o.X}, {o.Y}, {o.Z}, {o.W}\n";
                    Res.Storage.Put(GlyphKey, GlyphQuaternions);
                    if (TargetGlyphIndex < Glyph.AllGlyphs.Count - 1)
                    {
                        CurrentStage = new NewGlyphTrainingStage(TargetGlyphIndex + 1, Implement, AttitudeProvider);
                    }
                    else
                    {
                        Log.Debug("SpellTraining", $"Logged orientations:\n{GlyphQuaternions}");
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Glyph training stage progression", e.Message);
                    throw;
                }
            }
예제 #29
0
        private void Play()
        {
            if (!IsPlaying)
            {
                try
                {
                    if (_mediaSession == null)
                    {
                        _mediaSession = new RadioStationMediaSession(this);
                    }

                    if (_player == null)
                    {
                        _player = new RadioStationPlayer(this, this);
                        _player.StateChanged += OnPlayerStateChanged;
                        _player.Error        += OnPlayerError;
                    }

                    _lock = new RadioStationServiceLock(this);
                    _player.Start();
                }
                catch (Exception ex)
                {
                    Log.Error(TAG, $"Failed to play: {ex.Message}");
                    Log.Debug(TAG, ex.ToString());

                    if (_lock != null)
                    {
                        _lock.Release();
                        _lock = null;
                    }

                    Error?.Invoke(this, new RadioStationErrorEventArgs(ex));
                }
            }
        }
예제 #30
0
        public static async Task <Classifier> FindBestClassifier(DataSet <DKS> Dataset, GestureClass currentGC = null)
        {
            var sw = new System.Diagnostics.Stopwatch();

            Func <Classifier, DataSet <DKS>, Task <ClassifierMetrics> > assessmentFunc;
            DataSet <DKS> d;
            string        gestureName;

            if (currentGC != null)
            {
                // First, create a special Dataset which contains only two GC's... the one we're looking at, and "other".
                d = new DataSet <DKS>();
                d.AddClass(currentGC.className);
                d.AddClass("Other");
                foreach (var seq in Dataset.Samples)
                {
                    var s = new Sequence <DKS>()
                    {
                        SourcePath = seq.SourcePath
                    };
                    if (seq.TrueClassIndex == currentGC.index)
                    {
                        s.TrueClassIndex = 0;
                    }
                    else
                    {
                        s.TrueClassIndex = 1;
                    }
                    //s.TrueClassName = Dataset.ActualGestureClasses[s.TrueClassIndex].className;
                    d.AddSequence(s, skipBitmap: true);
                }
                assessmentFunc = assessClassifier_singleGC;
                gestureName    = currentGC.className;
            }
            else
            {
                d = Dataset;
                assessmentFunc = assessClassifier_multiGC;
                gestureName    = "full dataset";
            }

            Classifier        c = null, bestC = null;
            ClassifierMetrics bestOverallMetric = new ClassifierMetrics()
            {
                CrossEntropyLoss = 1000, WeightedAccuracy = -1
            };                                                                                                                // Ridiculously worse than any conceivable real classifier's metrics.

            var fExNames = Enumerable.Range(0, 14).Select(n => PULL + n.ToString());
            var fExList  = fExNames.Select <string, FeatureExtractor <DKS> >(name => new FeatureListExtractor(name)).ToHashSet();

            fExList.UnionWith(FeatureListExtractor.AllExtractors.Values);
            var  fExTestedList = new List <FeatureExtractor <DKS> >();
            bool addedDerivedExtractors = false, addedPullExtractors = false;

            while (fExList.Count > 0)
            {
                // Pop the first entry in the extractor list - using While & Pop lets us add new extractors /inside/ the loop.
                var extractor = fExList.First();
                fExList.Remove(extractor);
                fExTestedList.Add(extractor);

                // Create a fresh classifier to build based on this extractor
                c = (extractor is FeatureClusterExtractor) ? new ClusterClassifier() : new Classifier();

                sw.Start();
                var loss = c.CreateMachine(d, extractor);
                sw.Stop();
                var createTime = sw.Elapsed.TotalMilliseconds;
                sw.Reset();

                extractor.metrics = await assessmentFunc(c, d);

                extractor.metrics.CrossEntropyLoss = loss;
                extractor.metrics.TimeToCreate     = createTime;
                //Log.Debug("MachineLearning|SpecialTest", $"Created special classifier for {currentGC.className} with {extractor.Name} in " +
                //    $"{createTime:f1}ms; loss {loss:f3} / score {extractor.metrics.OverallScore():f2}. Assessed in {extractor.metrics.TimePerDatapoint:f1} ms/pt, with {extractor.metrics.WeightedAccuracy:f1}% accuracy.");

                if (extractor.metrics > bestOverallMetric)
                {
                    bestOverallMetric = extractor.metrics;
                    bestC             = c;
                    if (extractor.metrics.OverallScore() > 80) // Worse than 80% accuracy => don't bother reporting it to me.
                    {
                        Log.Debug("MachineLearning|SpecialTest", $"New best classifier for {gestureName}: {extractor.Name} in " +
                                  $"{createTime:f1}ms; loss {loss:f3} / accuracy score {extractor.metrics.OverallScore():f2}%. Assessed in " +
                                  $"{extractor.metrics.TimePerDatapoint:f1} ms/pt, with {extractor.metrics.WeightedAccuracy:f1}% raw accuracy.");
                    }
                }

                if (fExList.Count == 0 && !addedPullExtractors)
                {
                    addedPullExtractors = true;
                    var bestExtractors1 = fExTestedList
                                          .Where(extr => extr.Dimensions > 1)
                                          .Where(extr => !extr.Name.IsOneOf("LinAccelVec", "GravityVec", "GyroVec", "RotQuat"))   // 'Cause their 'pull' axes are already part of the pull-all-fourteen basic set.
                                          .OrderByDescending(extr => extr.metrics)
                                          .Take(3);
                    foreach (var bestEx in bestExtractors1)
                    {
                        fExList.Add(new FeatureListExtractor(PULLX + bestEx.Name));
                        if (bestEx.Dimensions >= 2)
                        {
                            fExList.Add(new FeatureListExtractor(PULLY + bestEx.Name));
                        }
                        if (bestEx.Dimensions >= 3)
                        {
                            fExList.Add(new FeatureListExtractor(PULLZ + bestEx.Name));
                        }
                        if (bestEx.Dimensions == 4)
                        {
                            fExList.Add(new FeatureAxisSelector <DKS>(3, bestEx)
                            {
                                Name = "PULL_W_" + bestEx.Name
                            });
                        }
                    }
                }

                if (fExList.Count == 0 && !addedDerivedExtractors)
                {
                    addedDerivedExtractors = true;
                    var bestExtractors2 = fExTestedList.OrderByDescending(extr => extr.metrics).Take(3).ToList();
                    //Log.Debug("MachineLearning|SpecialTest", $"\nFirst place goes to {bestExtractors[0].Name} with {bestExtractors[0].ExtractorScore:f2}, " +
                    //    $"second to {bestExtractors[1].Name} with {bestExtractors[1].ExtractorScore:f2}, and third to {bestExtractors[2].Name} with " +
                    //    $"{bestExtractors[2].ExtractorScore:f2}.\n ");
                    var be0 = bestExtractors2[0];
                    var be1 = bestExtractors2[1];
                    var be2 = bestExtractors2[2];
                    if (be0.Dimensions + be1.Dimensions < 5)
                    {
                        fExList.Add(new FeatureListExtractor(be0.Name, be1.Name));
                    }
                    if (be0.Dimensions + be2.Dimensions < 5)
                    {
                        fExList.Add(new FeatureListExtractor(be0.Name, be2.Name));
                    }
                    if (be1.Dimensions + be2.Dimensions < 5)
                    {
                        fExList.Add(new FeatureListExtractor(be1.Name, be2.Name));
                    }
                    //if (be0.Dimensions + be1.Dimensions + be2.Dimensions < 6)
                    fExList.Add(new FeatureListExtractor(be0.Name, be1.Name, be2.Name));
                    //fExList.Add(new FeatureListExtractor(INTEGRATE + bestExtractors[0].Name));
                    fExList.Add(new FeatureClusterExtractor(be0.Name, be1.Name));
                    fExList.Add(new FeatureClusterExtractor(be0.Name, be2.Name));
                    fExList.Add(new FeatureClusterExtractor(be1.Name, be2.Name));
                    fExList.Add(new FeatureClusterExtractor(be0.Name, be1.Name, be2.Name));
                }
            }

            //var lastExtractors = fExTestedList.Skip(fExTestedList.Count - 5).ToList();
            //Log.Debug("MachineLearning|SpecialTest", $"\nDerived: {lastExtractors[0].Name} with {lastExtractors[0].ExtractorScore:f2}, " +
            //    $"{lastExtractors[1].Name} with {lastExtractors[1].ExtractorScore:f2}, {lastExtractors[2].Name} with " +
            //    $"{lastExtractors[2].ExtractorScore:f2}, {lastExtractors[3].Name} with {lastExtractors[3].ExtractorScore:f2}, and " +
            //    $" {lastExtractors[4].Name} with {lastExtractors[4].ExtractorScore:f2}.\n ");

            var bestExtractors = fExTestedList.OrderByDescending(extr => extr.metrics).Take(3).ToList();

            Log.Debug("MachineLearning|SpecialTest", $"For {gestureName}:");
            var labelStrings = new string[] { "First place", "Second place", "Third place" };

            for (int i = 0; i < 3; i++)
            {
                var bestExtr = bestExtractors[i];
                Log.Debug("MachineLearning|SpecialTest", $"  {labelStrings[i]} goes to {bestExtr.Name}, with a score of {bestExtr.metrics.OverallScore():f2} " +
                          $"(accuracy {(bestExtr.metrics.WeightedAccuracy):f1}%, loss {bestExtr.metrics.CrossEntropyLoss:f2}, time {bestExtr.metrics.TimePerDatapoint:f1}).");
            }

            return(bestC);
        }