private static void StopPlayback()
 {
     // tell the controller to stop playing, de-register events, tell the command parser to get coordinates from live data and stop the treadmill
     VirtualMotionCaptureController.MotionCaptureDataPlayback(false);
     VirtualMotionCaptureController.VirtualMotionCaptureSubSessionPlaybackEnded -= new VirtualMotionCaptureController.VirtualMotionCaptureSubSessionPlaybackEndedEventHandler(VirtualMotionCaptureController_VirtualMotionCaptureSubSessionPlaybackEnded);
     _remoteDataManager.ServerPlayingStatus(false);
     Communication.OptitrackCommandParser_Server.VirtualMotionCaputrePlayback = false;
     Treadmill.TreadmillController.SetSpeed(0f);
 }
 /// <summary>
 /// Deletes the MC data associated with the given session
 /// </summary>
 /// <param name="session"></param>
 private static void DeleteMotionCaptureDataForSession(Session session)
 {
     foreach (SubSession sub in session.SubSessions)
     {
         if (File.Exists(VirtualMotionCaptureController.BuildSubSessionFileName(sub.SubSessionStartTime)))
         {
             File.Delete(VirtualMotionCaptureController.BuildSubSessionFileName(sub.SubSessionStartTime));
         }
     }
 }
 /// <summary>
 /// Stops recording
 /// </summary>
 private static void StopRecording()
 {
     //deregister events and stop recording.
     VirtualMotionCaptureController.VirtualMotionCaptureSubSessionRecorded -= new VirtualMotionCaptureController.VirtualMotionCaptureSubSessionRecordedEventHandler(VirtualMotionCaptureController_VirtualMotionCaptureSubSessionRecorded);
     VirtualMotionCaptureController.MotionCaptureDataRecord(false);
     //update the session and send the data back to the client
     _patients[_patientIndex].Sessions[_currentSessionIndex] = _currentSession;
     Patient_Remote_DataManager_UpdatePatientRequestedByClient(_patients[_patientIndex], _patientIndex);
     _remoteDataManager.ServerRecordingStatus(false);
 }
 /// <summary>
 /// Starts recording
 /// </summary>
 private static void StartRecording()
 {
     //register for the recording ended event, put the controller into record mode
     _currentSubSession = new SubSession();
     VirtualMotionCaptureController.MotionCaptureDataRecord(true);
     VirtualMotionCaptureController.VirtualMotionCaptureSubSessionRecorded += new VirtualMotionCaptureController.VirtualMotionCaptureSubSessionRecordedEventHandler(VirtualMotionCaptureController_VirtualMotionCaptureSubSessionRecorded);
     _remoteDataManager.ServerPlayingStatus(false);
     Communication.OptitrackCommandParser_Server.VirtualMotionCaputrePlayback = false;
     _remoteDataManager.ServerRecordingStatus(true);
 }
 /// <summary>
 /// Starts playback
 /// </summary>
 private static void StartPlayback()
 {
     //Register for the playback ended event and tell the controller to start playback as well as telling command parser to get coordinates from the virtual controller
     VirtualMotionCaptureController.VirtualMotionCaptureSubSessionPlaybackEnded += new VirtualMotionCaptureController.VirtualMotionCaptureSubSessionPlaybackEndedEventHandler(VirtualMotionCaptureController_VirtualMotionCaptureSubSessionPlaybackEnded);
     VirtualMotionCaptureController.MotionCaptureDataPlayback(true);
     Communication.OptitrackCommandParser_Server.VirtualMotionCaputrePlayback = true;
     // set the status in the remote object for the client gui
     _remoteDataManager.ServerPlayingStatus(true);
     _remoteDataManager.ServerRecordingStatus(false);
 }
        /// <summary>
        /// Gets ready to play back a session
        /// </summary>
        /// <param name="patientIndex"></param>
        /// <param name="sessionIndex"></param>
        /// <param name="subSessionIndex"></param>
        static void Patient_Remote_DataManager_OpenSessionForPlaybackRequestedByClient(int patientIndex, int sessionIndex, int subSessionIndex)
        {
            //use the indexes to load the correct subsession
            _currentSession         = _patients[patientIndex].Sessions[sessionIndex];
            _currentSubSessionIndex = subSessionIndex;
            _currentSubSession      = _currentSession.SubSessions[_currentSubSessionIndex];

            //Check the motion capture data is present on disk, if it is, open the subsession, else mark it as not pressent
            if (System.IO.File.Exists(VirtualMotionCaptureController.BuildSubSessionFileName(_currentSubSession.SubSessionStartTime)))
            {
                VirtualMotionCaptureController.OpenMotionCaptureSubSession(_currentSubSession.SubSessionStartTime);
            }
            else
            {
                //data isn't availiable
                _currentSession.MotionCaptureDataRecorded               = false;
                _currentSession.SubSessions[_currentSubSessionIndex]    = _currentSubSession;
                _patients[_patientIndex].Sessions[_currentSessionIndex] = _currentSession;
                Patient_Remote_DataManager_UpdatePatientRequestedByClient(_patients[_patientIndex], _patientIndex);
            }
        }
 /// <summary>
 /// Fired when playback ends
 /// </summary>
 /// <param name="subSessionStartTime"></param>
 static void VirtualMotionCaptureController_VirtualMotionCaptureSubSessionPlaybackEnded(DateTime subSessionStartTime)
 {
     //If there are multiple subsessions and this wasn't the last, then move onto the next subsession
     //TODO moddify this to allow looping of subsessions and of the complete session
     if (_currentSubSessionIndex < _currentSession.SubSessions.Count - 1)
     {
         _currentSubSessionIndex++;
         _currentSubSession = _currentSession.SubSessions[_currentSubSessionIndex];
         if (System.IO.File.Exists(VirtualMotionCaptureController.BuildSubSessionFileName(_currentSubSession.SubSessionStartTime)))
         {
             VirtualMotionCaptureController.OpenMotionCaptureSubSession(_currentSubSession.SubSessionStartTime);
         }
         else
         {
             StopPlayback();
         }
     }
     else
     {
         StopPlayback();
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Converts byte to command and then executes command
        /// </summary>
        /// <param name="receivedCommand"></param>
        public void handleCommand(byte[] receivedCommand)
        {
            lock (this) // Lock the code
            {
                int command = (int)receivedCommand[2];
                switch (command)
                {
                // 0 is Start Cameras
                case 0:
                    MotionCaptureStart();
                    break;

                // 1 is Stop Cameras
                case 1:
                    MotionCaptureStop();
                    break;

                // 2 is Send Camera Coordinates
                case 2:
                    if (MotionCaptureController.APIRunning)
                    {
                        MotionCaptureController.UpdateCameraList();
                        OptitrackCameraList.TransmitListOfCameras();
                    }
                    break;

                // 3 is Start Treadmill At Fixed Speed
                case 3:
                {
                    TreadmillController.SetSpeed((float)BitConverter.ToDouble(receivedCommand, 4));
                    break;
                }

                // 4 is Stop Treadmill
                case 4:
                {
                    TreadmillController.SetSpeed(0.0f);
                    break;
                }

                case 6:
                {
                    if (VirtualMotionCaputrePlayback)
                    {
                        VirtualMotionCaptureController.UpdateCoordinates();
                    }
                    else
                    {
                        MotionCaptureController.UpdateCoordinates(true, true);
                    }
                    break;
                }

                // 7 is Calibrate ground plane.
                case 7:
                {
                    //TODO: Reinstate or remove this?
                    //MotionCapture.Calibrate();
                    break;
                }

                //8 is toggle displaying feet
                case 8:
                {
                    if (ToggleFeetCommandReceivedEvent != null)
                    {
                        ToggleFeetCommandReceivedEvent(BitConverter.ToBoolean(receivedCommand, 4));
                    }
                    break;
                }

                case 9:     // Shuts down the drivers so the application can close
                {
                    FinalShutdown();
                    break;
                }

                case 10:     // Clears the CoR data - This should be called at the start of each session
                {
                    JointProcessor.ResetCoRCalculations();
                    break;
                }

                case 11:     // Requests an update for the current speed
                {
                    TreadmillController.TransmitSpeed();
                    break;
                }

                default:
                {
                    System.Diagnostics.Debug.WriteLine("Invalid command received: " + command.ToString());
                    break;
                }
                }
            }
        }