/// <summary> /// Returns the number of connected cameras as an int /// </summary> public int CameraCount() { return(MotionCaptureController.GetConnectedCameraCount()); }
/// <summary> /// Starts the Motion Capture Engine /// </summary> public void MotionCaptureStart() { bool errors = false; int result = -1; string filepath = null; msg = null; filepath = SETTINGSFOLDER; if (MotionCaptureController.APIRunning == false) // Only start motion capture if it isn't already running { result = MotionCaptureController.Initialize(); msg += "Initializing Tracking Tools Motion Caputre API :\n" + MotionCaptureController.GetErrorMessage(result); if (result != 0) { errors = true; } result = MotionCaptureController.LoadCalibration(filepath + "cali.cal"); msg += "\nLoading Calibration File \"cali.cal\" :\n" + MotionCaptureController.GetErrorMessage(result); if (result != 0) { errors = true; } result = MotionCaptureController.LoadTrackables(filepath + "Trackables.tra"); msg += "\nLoading Trackable File \"Trackables.tra\" :\n" + MotionCaptureController.GetErrorMessage(result); if (result != 0) { errors = true; } result = DataProcessing.JointProcessor.LoadJointDefinition(filepath + "joints.xml"); if (result == 0) { msg += "\nLoading Joint File \"joints.xml\" :\nSuccess"; } else { errors = true; msg += "\nLoading Joint File \"joints.xml\" :\nFailed"; } if (errors) { Thread messageBoxThread = new Thread(new ThreadStart(ShowMessageBox)); if (_viewingMsg == false) { messageBoxThread.Start(); } MotionCaptureStop(); // Falied to start correctly so shut it down } else { msg = null; // Clear the log as there weren't any problems StartUpdateTimer(); if (camerasStartedEvent != null) { camerasStartedEvent(); } } } }
/// <summary> /// Shuts down the api and drivers so that the program can exit /// </summary> public void FinalShutdown() { MotionCaptureController.FinalShutdown(); }
/// <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; } } } }
/// <summary> /// Stops the Motion Capture Engine /// </summary> public void MotionCaptureStop() { StopUpdateTimer(); MotionCaptureController.Shutdown(); }