Пример #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();
        }
Пример #2
0
        /// <summary>
        /// Starts the task. Called when the operator clicks the Go button.
        /// </summary>
        /// <param name="command">The movement command (velocity, acceleration)</param>
        /// <param name="duration">The duration of movement</param>
        internal void Go(MotionCommand command, double duration)
        {
            logger.Debug("Enter: Go(MotionCommand, double)");

            if (command.innerPosition == Hulk.ANY_MOTION)
            {
                // Moving with given velocity/acceleration and (optionally) duration.

                logger.Info("Starting rotation task with given velocity, acceleration, and duration.");

                Hulk.SetCommandType(Hulk.CommandType.Velocity);

                if (duration == -1.0)
                {
                    stopTime = DateTime.MinValue;
                }
                else
                {
                    stopTime = DateTime.Now.AddSeconds(duration);
                }

                Hulk.SetCommand(command);
                Hulk.StartTask();
            }
            else
            {
                // Moving to the given position.

                logger.Info("Starting rotation task to given position.");

                Hulk.SetCommandType(Hulk.CommandType.ModulusPosition);
                Hulk.SetCommand(command);
                Hulk.StartDefinedMove(false);
            }
        }
Пример #3
0
        /// <summary>
        /// Starts the task. Called when the operator clicks the Go button.
        /// </summary>
        internal void Go()
        {
            MotionCommand newMotionCommand;

            logger.Debug("Enter: Go()");

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

            previousTrigger = false;
            numClicks       = 0;

            lastPositionOuter = Hulk.CurrentMotion.outerPosition;
            lastPositionInner = Hulk.CurrentMotion.innerPosition;

            currentTrialNumber = Recordings.GetFirstTrialNumber();

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

            runningStopwatch.Reset();
            runningStopwatch.Start();

            Hulk.SetCommandType(Hulk.CommandType.ModulusPosition);

            newMotionCommand = new MotionCommand {
                outerVelocity     = POSITIONING_VELOCITY,
                innerVelocity     = POSITIONING_VELOCITY,
                outerAcceleration = POSITIONING_ACCELERATION,
                innerAcceleration = POSITIONING_ACCELERATION
            };

            Hulk.SetCommand(newMotionCommand);
            Hulk.StartTask();
        }
        /// <summary>
        /// Starts the task. Called when the operator clicks the Go button.
        /// </summary>
        /// <param name="sender">Not used</param>
        /// <param name="e">Not used</param>
        internal void Go()
        {
            MotionCommand newMotionCommand;

            logger.Debug("Enter: Go()");

            Hulk.Halt();

            startOuterPosition = Hulk.CurrentMotion.outerPosition;
            startInnerPosition = Hulk.CurrentMotion.innerPosition;

            logger.Info("Starting position task with center at OUTER=" + startOuterPosition.ToString("F1") +
                        " INNER=" + startInnerPosition.ToString("F1") + ".");

            Hulk.SetCommandType(Hulk.CommandType.ModulusPosition);

            newMotionCommand = new MotionCommand {
                outerVelocity     = POSITIONING_VELOCITY,
                innerVelocity     = POSITIONING_VELOCITY,
                outerAcceleration = POSITIONING_ACCELERATION,
                innerAcceleration = POSITIONING_ACCELERATION
            };

            Hulk.SetCommand(newMotionCommand);
            Hulk.StartTask();
        }
        /// <summary>
        /// Called by the control loop when the participant exceeds the max allowable angle from the DOB.
        /// </summary>
        private void HandleResetting()
        {
            MotionCommand moveCommand;

            // Restart with balancing once reset is complete
            trial.TrialStatus = Trial.Status.Moving;

            Hulk.Halt();

            trial.PlayResetStartSound();

            queueResetEndSound = true;

            // Move back to the DOB

            moveCommand = new MotionCommand {
                innerVelocity     = Hulk.NORMAL_VELOCITY,
                outerVelocity     = Hulk.NORMAL_VELOCITY,
                innerAcceleration = Hulk.NORMAL_ACCELERATION,
                outerAcceleration = Hulk.NORMAL_ACCELERATION
            };

            // calculate random offset from DOB to return the chair to

            double dobOffsetY = _calculateDOBOffset(trial.RestartDOBOffsetMinYaw, trial.RestartDOBOffsetMaxYaw);
            double dobOffsetP = _calculateDOBOffset(trial.RestartDOBOffsetMinPitch, trial.RestartDOBOffsetMaxPitch);
            double dobOffsetR = _calculateDOBOffset(trial.RestartDOBOffsetMinRoll, trial.RestartDOBOffsetMaxRoll);

            if (Math.Abs(dobOffsetY) > trial.MaxAngle)
            {
                logger.Warn("The calculated random offset for the DOB yaw return position is outside of the maximum angle specified for this trial. Using a random offset of 0!");
                dobOffsetY = 0;
            }
            if (Math.Abs(dobOffsetP) > trial.MaxAngle)
            {
                logger.Warn("The calculated random offset for the DOB pitch return position is outside of the maximum angle specified for this trial. Using a random offset of 0!");
                dobOffsetP = 0;
            }
            if (Math.Abs(dobOffsetR) > trial.MaxAngle)
            {
                logger.Warn("The calculated random offset for the DOB roll return position is outside of the maximum angle specified for this trial. Using a random offset of 0!");
                dobOffsetR = 0;
            }

            double resetDobY = trial.MovingDirectionOfBalance.yaw + dobOffsetY;
            double resetDobP = trial.MovingDirectionOfBalance.pitch + dobOffsetP;
            double resetDobR = trial.MovingDirectionOfBalance.roll + dobOffsetR;

            moveCommand.innerPosition = (Hulk.InnerAxis == Hulk.Axis.Roll) ? resetDobR : resetDobY;
            moveCommand.outerPosition = resetDobP;

            Hulk.SetCommandType(Hulk.CommandType.ModulusPosition);
            Hulk.SetCommand(moveCommand);

            Hulk.StartDefinedMove(true);

            logger.Info("Participant lost control. Resetting to orientation: yaw " + resetDobY.ToString("0.##") + " pitch " + resetDobP.ToString("0.##") + " roll " + resetDobR.ToString("0.##"));

            _sendCommandStopTrial();
        }
        /// <summary>
        /// Starts the task. Called when the operator clicks the Go button.
        /// </summary>
        /// <param name="command">The movement command (velocity, acceleration)</param>
        /// <param name="duration">The duration of movement</param>
        internal void Go(MotionCommand command, double duration)
        {
            logger.Debug("Enter: Go(MotionCommand, double)");

            if (command.innerPosition == Hulk.ANY_MOTION)
            {
                // Moving with given velocity/acceleration and (optionally) duration.

                logger.Info("Starting UnrealLandscapesDemoTask with given duration.");

                Hulk.SetCommandType(Hulk.CommandType.Velocity);

                Hulk.SetCommand(command);
                Hulk.StartTask();
            }
            else
            {
                // Moving to the given position.

                logger.Info("Starting UnrealLandscapesDemoTask to given position.");

                Hulk.SetCommandType(Hulk.CommandType.ModulusPosition);
                Hulk.SetCommand(command);
                Hulk.StartDefinedMove(false);
            }
        }
        /// <summary>
        /// Starts the task. Called when the operator clicks the Go button.
        /// </summary>
        /// <param name="stateInfo">Not used. Here so that the method can be called by a worker thread.</param>
        internal void Go(Object stateInfo)
        {
            MotionCommand moveCommand;

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

            Trials.CurrentTrialIndex = 0;
            trial = Trials.CurrentTrial;

            SendPlottingAxesCenterChange();

            queueResetEndSound = false;

            StartLogging();

            // Begin moving to the starting location of the first trial

            logger.Info("Moving to location for beginning of balance trial: " + trial.TrialNumber);

            trial.MovingDirectionOfBalance.yaw   = trial.DirectionOfBalance.yaw;
            trial.MovingDirectionOfBalance.pitch = trial.DirectionOfBalance.pitch;
            trial.MovingDirectionOfBalance.roll  = trial.DirectionOfBalance.roll;

            trial.TrialStatus = Trial.Status.Moving;
            trial.PlayMoveSound();

            moveCommand = new MotionCommand {
                innerVelocity     = Hulk.NORMAL_VELOCITY,
                outerVelocity     = Hulk.NORMAL_VELOCITY,
                innerAcceleration = Hulk.NORMAL_ACCELERATION,
                outerAcceleration = Hulk.NORMAL_ACCELERATION
            };
            if (trial.BeginAt == null)
            {
                moveCommand.innerPosition = (Hulk.InnerAxis == Hulk.Axis.Roll) ?
                                            trial.DirectionOfBalance.roll : trial.DirectionOfBalance.yaw;
                moveCommand.outerPosition = trial.DirectionOfBalance.pitch;
            }
            else
            {
                moveCommand.innerPosition = (Hulk.InnerAxis == Hulk.Axis.Roll) ?
                                            trial.BeginAt.roll : trial.BeginAt.yaw;
                moveCommand.outerPosition = trial.BeginAt.pitch;
            }

            Hulk.SetCommandType(Hulk.CommandType.ModulusPosition);
            Hulk.SetCommand(moveCommand);
            Hulk.StartDefinedMove(true);
        }
        /// <summary>
        /// Starts the task. Called when the operator clicks the Go button.
        /// </summary>
        /// <param name="functionFilename">The filename of the CSV file containing the forcing function</param>
        /// <param name="selectedAmplitude">The amplitude of the forcing function</param>
        /// <param name="selectedOffset">???</param>
        internal void Go(string functionFilename, double selectedAmplitude, double selectedOffset)
        {
            MotionCommand newMotionCommand;

            logger.Debug("Enter: Go()");

            logger.Info("Starting delay measurement task.");

            amplitude = selectedAmplitude;

            // Move to the start location

            Hulk.SetCommandType(Hulk.CommandType.ModulusPosition);

            newMotionCommand = new MotionCommand();
            newMotionCommand.innerPosition     = selectedOffset;
            newMotionCommand.outerPosition     = 0.0;
            newMotionCommand.outerVelocity     = Hulk.NORMAL_VELOCITY;
            newMotionCommand.innerVelocity     = Hulk.NORMAL_VELOCITY;
            newMotionCommand.outerAcceleration = Hulk.NORMAL_ACCELERATION;
            newMotionCommand.innerAcceleration = Hulk.NORMAL_ACCELERATION;

            Hulk.SetCommand(newMotionCommand);
            Hulk.StartDefinedMove(false);

            while (Hulk.SystemStatus != Hulk.Status.Idling)
            {
                Thread.Sleep(100);
            }

            // Prepare for trial

            DataLogger.AcquireDataLog(Path.GetFileNameWithoutExtension(functionFilename) +
                                      "_Amplitude" + amplitude.ToString("F1") + "_Offset" + selectedOffset.ToString("F1") + "_data.csv", dataLogHeader);

            runningStopwatch.Reset();
            runningStopwatch.Start();

            // Start task

            Hulk.SetCommandType(Hulk.CommandType.Velocity);
            Hulk.StartTask();
        }
        /// <summary>
        /// Sets up timing and movement commands for the start of a new trial.
        /// </summary>
        private void StartTrial()
        {
            logger.Debug("Enter: StartTrial()");
            logger.Info("Starting balance trial: " + trial.TrialNumber);

            ICommand c = new ICommand();

            c.CommandType = (int)eCommands.SelectTrial;
            c.addParameter((int)eSelectTrialCommandParameters.TrialNumber, trial.TrialNumber.ToString());

            trial.PlayStartSound();

            trialStopwatch = new Stopwatch();
            trialStopwatch.Start();
            previousMillis = trialStopwatch.ElapsedMilliseconds;

            trial.TrialStatus = Trial.Status.BalancingDOBChanging;

            Hulk.SetCommandType(Hulk.CommandType.Velocity);
        }