// Performs the sequence by stepping through each frame and executing the required
        // voice synthesizer, delay, and motion actions.
        private void RunSequenceThread()
        {
            if (!servoManager.IsConnected())
            {
                ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Warning, "Servo hardware is disconnected, running sequence '" + runningSequence.name + "' in simulation mode.");
            }

            // Disable the person tracking feature while a sequence is executing.
            servoManager.PersonTrackingEnable(false);

            ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Info, "RunSequence(): sequence '" + runningSequence.name + "' started.");

            foreach (Frame frame in runningSequence.GetFrames())
            {
                // Run the speech synthesizer asynchronously. Speaks while continuing to
                // perform moves in this and subsequent frames.
                if (frame.speechString != null)
                {
                    speechSynthesizer.SpeakAsync(frame.speechString);
                }

                // Go to the relevant PPT Slide
                // perform moves in this and subsequent frames.
                if (frame.pptIndex != null)
                {
                    if (pptController.IsPptActive())
                    {
                        pptController.GoToSlide(frame.pptIndex);
                    }
                }

                // Wait for the specified amount of time.
                if (frame.delay > 0)
                {
                    Thread.Sleep((int)(frame.delay * 1000));
                }

                // Move all servos in the frame list.
                if (frame.GetServoPositions().Count > 0)
                {
                    servoManager.MoveServos(frame.GetServoPositions(), frame.timeToDestination);
                }
            }

            ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Info, "RunSequence(): sequence '" + runningSequence.name + "' completed.");

            // Re-enable the person tracking feature.
            servoManager.PersonTrackingEnable(true);

            lock (sequenceLock)
            {
                sequenceIsRunning = false;
            }
        }
예제 #2
0
        // Performs the sequence by stepping through each frame and executing the required
        // voice synthesizer, delay, and motion actions.
        private void RunSequenceThread()
        {
            if (!servoManager.IsConnected())
            {
                ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Warning, "Servo hardware is disconnected, running servos in simulation mode for sequence '" + runningSequence.name + "'.");
            }

            if (!ariaManager.IsConnected())
            {
                ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Warning, "Robot base hardware is disconnected, running robot base in simulation mode for sequence '" + runningSequence.name + "'.");
            }

            ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Info, "RunSequenceThread(): sequence '" + runningSequence.name + "' started.");

            foreach (Frame frame in runningSequence.GetFrames())
            {
                // Run the speech synthesizer asynchronously. Speaks while continuing to
                // perform moves in this and subsequent frames.
                if (frame.speechString != null)
                {
                    robotSpeech.Speak(frame.speechString);
                }

                // Set the state of the LED eyes.
                if (frame.eyeState != null)
                {
                    switch (frame.eyeState)
                    {
                    case "Open":
                        robotEyes.SetEyeState(true, true);
                        break;

                    case "Closed":
                        robotEyes.SetEyeState(false, false);
                        break;

                    case "LeftClosed":
                        robotEyes.SetEyeState(false, true);
                        break;

                    case "RightClosed":
                        robotEyes.SetEyeState(true, false);
                        break;
                    }
                }

                // Wait for the specified amount of time.
                if (frame.delay > 0)
                {
                    Thread.Sleep((int)(frame.delay * 1000));
                }


                // Servo motion and wheel motion are performed simultaneously by creating two separate threads and
                // waiting until both threads have completed their motion.

                ManualResetEvent[] manualEvents = new ManualResetEvent[]
                {
                    new ManualResetEvent(false),
                    new ManualResetEvent(false)
                };

                // Start servo motion thread.
                Thread servoThread = new Thread(new ParameterizedThreadStart(MoveServos));
                servoThread.Start(new SequenceThreadData(frame, manualEvents[0]));

                // Start wheel motion thread.
                Thread wheelsThread = new Thread(new ParameterizedThreadStart(MoveWheels));
                wheelsThread.Start(new SequenceThreadData(frame, manualEvents[1]));

                // Wait until both servo motion and wheel motion has completed.
                WaitHandle.WaitAll(manualEvents);
            }

            ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Info, "RunSequenceThread(): sequence '" + runningSequence.name + "' completed.");

            lock (sequenceLock)
            {
                sequenceIsRunning = false;
            }
        }