/// <summary>
        /// Called from the main control loop whenever the task should be stopped.
        /// DO NOT call this method directly from BalanceTask or BalancePanel.
        /// </summary>
        public override void StopTask()
        {
            logger.Debug("Enter: StopTask()");

            if (trial.TrialStatus == Trial.Status.Complete)
            {
                logger.Info("Completed set of balance trials.");
            }
            else
            {
                logger.Info("Aborting balance trial: " + trial.TrialNumber);
                trial.TrialStatus = Trial.Status.Complete;
            }

            DataLogger.CloseDataLog();

            Hulk.Halt();

            ((BalanceWithHmdPanel)panel).CleanUp();

            logStopwatch   = null;
            trialStopwatch = null;

            _sendCommandStopTrial();
            _sendCommandFadeOut();
        }
Esempio n. 2
0
        /// <summary>
        /// Called from the main control loop whenever the task should be stopped.
        /// DO NOT call this method directly from PassiveMovementTask or PassiveMovementPanel.
        /// </summary>
        public override void StopTask()
        {
            logger.Debug("Enter: StopTask()");

            logger.Info("Stopping passive movement task.");

            Hulk.Halt();

            ((PassiveMovementPanel)panel).CleanUp();
            runningStopwatch.Stop();
            DataLogger.CloseDataLog();
        }
        /// <summary>
        /// Called by th control loop when the trial's time limit has been reached.
        /// </summary>
        private void HandleStateComplete()
        {
            logger.Info("Completed balance trial: " + trial.TrialNumber);

            DataLogger.CloseDataLog();

            bool advanceToNextTrial = true;

            if ((trial.NumberIndications == 0) && trial.JoystickIndicationsMandatory)
            {
                logger.Warn("Participant did not indicate during this trial - restarting trial");

                StartLogging();

                StartTrial();

                advanceToNextTrial = false;
            }

            if (advanceToNextTrial)
            {
                trial.PlayEndSound();

                if (Trials.CurrentTrialIndex == (Trials.List.Count - 1))
                {
                    // Entire protocol has been completed
                    Hulk.StopTask();
                }
                else
                {
                    // Continue to following trial
                    Trials.CurrentTrialIndex++;

                    trial = Trials.CurrentTrial;

                    StartLogging();

                    trial.MovingDirectionOfBalance.roll  = Trials.PreviousTrial.MovingDirectionOfBalance.roll;
                    trial.MovingDirectionOfBalance.pitch = Trials.PreviousTrial.MovingDirectionOfBalance.pitch;
                    trial.MovingDirectionOfBalance.yaw   = Trials.PreviousTrial.MovingDirectionOfBalance.yaw;

                    StartTrial();
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Called from the main control loop whenever the task is running.
        /// DO NOT call this method directly from PassiveMovementTask or PassiveMovementPanel.
        /// </summary>
        public override void ContinueTask()
        {
            MotionCommand      command;
            RecordingTimepoint recording;
            double             elapsedTime;
            double             angleDiff;

            elapsedTime = runningStopwatch.ElapsedMilliseconds * 1.0 / 1000;

            // Check whether the entire block is complete
            if (Recordings.IsEndOfRecordingSeries(currentTrialNumber, elapsedTime))
            {
                // Play the last recording timepoint
                recording = Recordings.GetRecording(currentTrialNumber, elapsedTime);

                command = new MotionCommand();
                command.outerPosition = recording.Angles.pitch;
                if (Hulk.ChairMount == Hulk.MountType.Back)
                {
                    command.innerPosition = recording.Angles.roll;
                }
                else
                {
                    command.innerPosition = recording.Angles.yaw;
                }

                Hulk.SetCommand(command);
                Hulk.ContinueTask();

                // Stop the HULK and return to idling

                Hulk.StopTask();

                return;
            }

            // Check whether the current trial is complete
            if (Recordings.IsEndOfRecordingTrial(currentTrialNumber, elapsedTime))
            {
                // Clean up from last trial
                DataLogger.CloseDataLog();
                runningStopwatch.Reset();

                // Prepare for next trial

                runningStopwatch.Start();

                currentTrialNumber++;
                numClicks = 0;

                ((PassiveMovementPanel)panel).UpdateListbox();

                DataLogger.AcquireDataLog(String.Format("recording{0:000}.csv", currentTrialNumber), dataLogHeader);

                return;
            }

            // Determine the control input for this simulation step
            if (Recordings.HasRecording())
            {
                // Check whether the trigger has just been pressed
                if (!previousTrigger && InputController.JoystickInput.trigger)
                {
                    numClicks++;
                }
                previousTrigger = InputController.JoystickInput.trigger;

                recording = Recordings.GetRecording(currentTrialNumber, elapsedTime);

                command = new MotionCommand();
                command.outerPosition = recording.Angles.pitch;
                if (Hulk.ChairMount == Hulk.MountType.Back)
                {
                    command.innerPosition = recording.Angles.roll;
                }
                else
                {
                    command.innerPosition = recording.Angles.yaw;
                }

                // Stop if a large angle change is commanded. A large angle change could be dangerous at these accelerations.
                angleDiff = Math.Abs(lastPositionInner - command.innerPosition);
                if ((angleDiff > 3.0) && (angleDiff < 357.0))
                {
                    logger.Warn("SAFETY: Instantaneous INNER move >3 deg prevented. Current=" +
                                lastPositionInner.ToString("F2") + " New=" + command.innerPosition.ToString("F2"));

                    Hulk.StopTask();

                    return;
                }
                angleDiff = Math.Abs(lastPositionOuter - command.outerPosition);
                if ((angleDiff > 3.0) && (angleDiff < 357.0))
                {
                    logger.Warn("SAFETY: Instantaneous OUTER move >3 deg prevented. Current=" +
                                lastPositionOuter.ToString("F2") + " New=" + command.outerPosition.ToString("F2"));

                    Hulk.StopTask();

                    return;
                }

                lastPositionOuter = command.outerPosition;
                lastPositionInner = command.innerPosition;

                LogData(elapsedTime, Hulk.CurrentMotion, command, recording, InputController.JoystickInput);

                Hulk.SetCommand(command);
                Hulk.ContinueTask();
            }
        }