Exemple #1
0
        /// <summary>
        /// Speech recognized handler
        /// </summary>
        /// <param name="recognized"></param>
        private void SpeechRecognizedHandler(sr.SpeechRecognized recognized)
        {
            TimeSpan sinceTalk = DateTime.Now - Talker.lastSpoken;

            if (sinceTalk.TotalSeconds < SpeechRecognizerTalkerBlackoutSec)
            {
                Tracer.Trace("SpeechRecognizedHandler in blackout at " + sinceTalk.TotalSeconds + " sec");
                return;
            }

            int    angle            = Direction.to180fromRad(-recognized.Body.Angle);
            string commandText      = recognized.Body.Text;
            string commandSemantics = recognized.Body.Semantics.ValueString;
            double confidence       = Math.Round(recognized.Body.Confidence, 3); // 0 to 1, usually around 0.97 for successfully recognized commands

            //Tracer.Trace("****************************************  SpeechRecognizedHandler  **************************************** ");
            //Tracer.Trace("speech '" + commandText + "'=>'" + commandSemantics + "' at " + angle + " degrees,  confidence " + confidence);


            // find the handler based on semantics:
            SpeechRecognizerDictionaryItem srdi = (from di in speechRecognizerDictionary
                                                   where di.semantics == commandSemantics
                                                   select di).FirstOrDefault();


            // usually Confidence is 0.95-0.99
            if (srdi != null && recognized.Body.Confidence > srdi.minimumRequiredConfidence)
            {
                VoiceCommandState state = _state.VoiceCommandState;
                state.TimeStamp         = DateTime.Now;
                state.Text              = commandText;
                state.Semantics         = commandSemantics;
                state.ConfidencePercent = (int)Math.Round(confidence * 100.0f);
                state.Direction         = angle;

                LogHistory(1, "speech '" + commandText + "'=>'" + commandSemantics + "' at " + angle + " deg,   " + confidence);

                // now call the handler:
                srdi.handler(srdi, angle);
            }
            else if (confidence > 0.5d)
            {
                LogHistory(3, "rejected '" + commandText + "'=>'" + commandSemantics + "' at " + angle + " deg,   " + confidence);

                Talker.Say(10, "Homm");     // not enough confidence
            }

            //setPan(angle);
            //setTilt(0);
        }
Exemple #2
0
        public void Init()
        {
            Dropping = false;

            IsTurning         = false;
            LastTurnStarted   = DateTime.MinValue;
            LastTurnCompleted = DateTime.MinValue;

            if (WheelsEncoderState == null)
            {
                WheelsEncoderState = new WheelsEncoderState();
            }

            if (collisionState == null)
            {
                collisionState = new CollisionState();
            }

            if (gpsState == null)
            {
                gpsState = new GpsState();
            }

            if (MostRecentAnalogValues == null)
            {
                MostRecentAnalogValues = new proxibrick.AnalogDataDssSerializable()
                {
                    TimeStamp = DateTime.MinValue
                };
            }

            MostRecentLaserTimeStamp = DateTime.Now;

            if (VoiceCommandState == null)
            {
                VoiceCommandState = new VoiceCommandState();
            }

            int MAX_HUMANS_TO_TRACK = 7;    // FrameProcessor preallocates 7

            HumanInteractionStates = new HumanInteractionState[MAX_HUMANS_TO_TRACK];

            for (int i = 0; i < HumanInteractionStates.Length; i++)
            {
                HumanInteractionStates[i] = new HumanInteractionState();
            }

            if (followDirectionPidControllerAngularSpeed == null)
            {
                followDirectionPidControllerAngularSpeed = new PIDController()
                {
                    Name                 = "AngularSpeed",
                    MaxIntegralError     = 180.0d,              // degrees; anything more causes controller reset (error too large)
                    MaxUpdateIntervalSec = 10.0d,               // ms; anything more causes controller reset (interval too long)
                    MaxPidValue          = 100.0d,              // pid factor upper limit
                    MinPidValue          = 0.0d,                // pid factor lower limit

                    Kp = PIDController.ProportionalGainDefault, // Proportional constant, 3.0
                    Ki = PIDController.IntegralGainDefault,     // Integral constant, 0.1
                    Kd = PIDController.DerivativeGainDefault    // Derivative constant, 0.5
                };
            }

            if (followDirectionPidControllerLinearSpeed == null)
            {
                followDirectionPidControllerLinearSpeed = new PIDController()
                {
                    Name                 = "LinearSpeed",
                    MaxIntegralError     = 2000.0d,             // mm/sec; anything more causes controller reset (error too large)
                    MaxUpdateIntervalSec = 10.0d,               // ms; anything more causes controller reset (interval too long)
                    MaxPidValue          = 1000.0d,             // pid factor upper limit
                    MinPidValue          = 0.0d,                // pid factor lower limit

                    Kp = PIDController.ProportionalGainDefault, // Proportional constant, 3.0
                    Ki = PIDController.IntegralGainDefault,     // Integral constant, 0.1
                    Kd = PIDController.DerivativeGainDefault    // Derivative constant, 0.5
                };
            }

            if (PowerScale == 0.0d)
            {
                PowerScale = 0.5d;
            }
        }
        public void Init()
        {
            Dropping = false;

            IsTurning = false;
            LastTurnStarted = DateTime.MinValue;
            LastTurnCompleted = DateTime.MinValue;

            if (WheelsEncoderState == null)
            {
                WheelsEncoderState = new WheelsEncoderState();
            }

            if (collisionState == null)
            {
                collisionState = new CollisionState();
            }

            if (gpsState == null)
            {
                gpsState = new GpsState();
            }

            if (MostRecentAnalogValues == null)
            {
                MostRecentAnalogValues = new proxibrick.AnalogDataDssSerializable() { TimeStamp = DateTime.MinValue };
            }

            MostRecentLaserTimeStamp = DateTime.Now;

            if (VoiceCommandState == null)
            {
                VoiceCommandState = new VoiceCommandState();
            }

            int MAX_HUMANS_TO_TRACK = 7;    // FrameProcessor preallocates 7

            HumanInteractionStates = new HumanInteractionState[MAX_HUMANS_TO_TRACK];

            for (int i = 0; i < HumanInteractionStates.Length; i++)
            {
                HumanInteractionStates[i] = new HumanInteractionState();
            }

            if (followDirectionPidControllerAngularSpeed == null)
            {
                followDirectionPidControllerAngularSpeed = new PIDController()
                    {
                        Name = "AngularSpeed",
                        MaxIntegralError = 180.0d,          // degrees; anything more causes controller reset (error too large)
                        MaxUpdateIntervalSec = 10.0d,       // ms; anything more causes controller reset (interval too long)
                        MaxPidValue = 100.0d,               // pid factor upper limit
                        MinPidValue = 0.0d,                 // pid factor lower limit

                        Kp = PIDController.ProportionalGainDefault,             // Proportional constant, 3.0
                        Ki = PIDController.IntegralGainDefault,                 // Integral constant, 0.1
                        Kd = PIDController.DerivativeGainDefault                // Derivative constant, 0.5
                    };
            }

            if (followDirectionPidControllerLinearSpeed == null)
            {
                followDirectionPidControllerLinearSpeed = new PIDController()
                    {
                        Name = "LinearSpeed",
                        MaxIntegralError = 2000.0d,         // mm/sec; anything more causes controller reset (error too large)
                        MaxUpdateIntervalSec = 10.0d,       // ms; anything more causes controller reset (interval too long)
                        MaxPidValue = 1000.0d,              // pid factor upper limit
                        MinPidValue = 0.0d,                 // pid factor lower limit

                        Kp = PIDController.ProportionalGainDefault,             // Proportional constant, 3.0
                        Ki = PIDController.IntegralGainDefault,                 // Integral constant, 0.1
                        Kd = PIDController.DerivativeGainDefault                // Derivative constant, 0.5
                    };
            }

            if (PowerScale == 0.0d)
            {
                PowerScale = 0.5d;
            }
        }