/// <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> /// Opens the file load dialog. /// </summary> /// <param name="sender">Not used</param> /// <param name="e">Not used</param> private void fileLoadButton_Click(object sender, EventArgs e) { DialogResult result; OpenFileDialog dialog; Stream stream; String[] filenames; logger.Debug("Enter: fileLoadButton_Click(object, EventArgs)"); dialog = new OpenFileDialog(); dialog.DefaultExt = "csv"; dialog.Filter = "Recording files (*.csv)|*.csv"; dialog.Multiselect = true; dialog.InitialDirectory = ConfigurationManager.AppSettings["TrialRecordingsDirectory"]; result = dialog.ShowDialog(); if (result == DialogResult.OK) { // Operator selected one or more files. Loop through them and add to the list of timepoints. Recordings.Clear(); recordingFilenamesListBox.Items.Clear(); try { filenames = dialog.FileNames; Array.Sort(filenames); foreach (String s in filenames) { stream = File.OpenRead(s); if (stream != null) { recordingFilenamesListBox.Items.Add(s); Recordings.Read(Path.GetFileName(s)); } } goButton.Enabled = true; } catch (Exception) { MessageBox.Show("Error: Could not open file(s)."); } } }
/// <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(); } }