Пример #1
0
        /// <summary>
        /// Gradually stops any rotation of the HULK, using the currently specified
        /// deceleration parameters. Called when the operator clicks the Soft Stop button.
        /// </summary>
        /// <param name="stateInfo">Not used. Here so that the method can be called by a worker thread.</param>
        internal void SoftStop(Object stateInfo)
        {
            MotionCommand newCommand;

            logger.Debug("Enter: SoftStop(Object)");

            logger.Info("Decelerating.");

            Hulk.SetCommandType(Hulk.CommandType.Velocity);

            newCommand = new MotionCommand();
            newCommand.innerVelocity     = 0;
            newCommand.outerVelocity     = 0;
            newCommand.innerAcceleration = Hulk.NORMAL_ACCELERATION;
            newCommand.outerAcceleration = Hulk.NORMAL_ACCELERATION;

            Hulk.SetCommand(newCommand);

            while ((Hulk.CurrentMotion.innerVelocity > 0.1) || (Hulk.CurrentMotion.outerVelocity > 0.1))
            {
                Thread.Sleep(100);
            }

            Hulk.StopTask();
        }
        /// <summary>
        /// Called from the main control loop whenever the task is running.
        /// DO NOT call this method directly from BalanceTask or BalancePanel.
        /// </summary>
        public override void ContinueTask()
        {
            if (!InputController.IsJoystickConnected)
            {
                logger.Warn("No joystick found. Stopping balance task.");
                Hulk.StopTask();
                return;
            }

            switch (trial.TrialStatus)
            {
            case Trial.Status.Moving:
                HandleStateMoving();
                break;

            case Trial.Status.BalancingDOBChanging:         // DO NOT add a break here
            case Trial.Status.BalancingDOBStable:
                HandleStateBalancing();
                break;

            case Trial.Status.Resetting:
                HandleResetting();
                break;

            case Trial.Status.Complete:
                HandleStateComplete();
                break;
            }
        }
        /// <summary>
        /// Called from the main control loop whenever the task is running.
        /// DO NOT call this method directly from DelayMeasurementTask or DelayMeasurementPanel.
        /// </summary>
        public override void ContinueTask()
        {
            ControlInput      controlInput;
            FunctionTimepoint function;
            MotionCommand     command;
            double            elapsedTime;

            elapsedTime = runningStopwatch.ElapsedMilliseconds * 1.0 / 1000;

            function = ForcingFunctions.GetForcingFunction(elapsedTime);

            controlInput = (Hulk.InnerAxis == Hulk.Axis.Roll) ?
                           new ControlInput(function.Input.roll, function.Input.pitch, false, false) :
                           new ControlInput(function.Input.yaw, function.Input.pitch, false, false);

            command = new MotionCommand();
            command.innerVelocity     = controlInput.x * amplitude;
            command.outerVelocity     = controlInput.y * amplitude;
            command.innerAcceleration = 300;
            command.outerAcceleration = 300;

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

            LogData(elapsedTime, Hulk.CurrentMotion, command, controlInput);

            if (elapsedTime >= ForcingFunctions.GetForcingFunctionMaxTime())
            {
                Hulk.StopTask();

                return;
            }
        }
Пример #4
0
        /// <summary>
        /// Stops the task.
        /// This method should ONLY contain a call to Hulk.StopTask().
        /// Any other post-task cleanup should be handled in DelayMeasurementTask.StopTask() or DelayMeasurementPanel.CleanUp().
        /// </summary>
        /// <param name="sender">Not used</param>
        /// <param name="e">Not used</param>
        private void stopButton_Click(object sender, EventArgs e)
        {
            logger.Debug("Enter: stopButton_Click(object, EventArgs)");

            if (Hulk.CheckCommandAllowed())
            {
                Hulk.StopTask();
            }
        }
Пример #5
0
 /// <summary>
 /// Called from the main control loop whenever the task is running.
 /// DO NOT call this method directly from RotationTask or RotationPanel.
 /// </summary>
 public override void ContinueTask()
 {
     if ((stopTime != DateTime.MinValue) && (DateTime.Now.CompareTo(stopTime) >= 0))
     {
         // Duration limit reached.
         Hulk.StopTask();
     }
     else
     {
         Hulk.ContinueTask();
     }
 }
Пример #6
0
        /// <summary>
        /// Stops the task.
        /// This method should ONLY contain a call to Hulk.StopTask().
        /// Any other post-task cleanup should be handled in BalanceTask.StopTask() or ModeledControllerWithHmdPanel.CleanUp().
        /// </summary>
        /// <param name="sender">Not used</param>
        /// <param name="e">Not used</param>
        private void stopButton_Click(object sender, EventArgs e)
        {
            logger.Debug("Enter: stopButton_Click(object, EventArgs)");

            if (Hulk.CheckCommandAllowed())
            {
                protocolStopwatch.Stop();
                protocolStopwatch.Reset();

                Hulk.StopTask();

                ICommand c = new ICommand();
                c.CommandType = (int)eCommands.FadeOut;
                AppMain.ServerHandler.sendCommandToRegisteredClients(c, null);
            }
        }
        /// <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();
                }
            }
        }
Пример #8
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();
            }
        }