static void Main(string[] args) { Console.WriteLine("Establishing connection..."); RTProtocol rtProtocol = EstablishConnection(qtmName); if (rtProtocol.IsConnected()) { Console.WriteLine("Streaming 6DOF (Euler) data to port {0} of {1}...", udpToPort, udpToIP); Task.Run(() => { while (true) { rtProtocol.StreamFrames( StreamRate.RateFrequency, 20, ComponentType.Component6dEuler, udpToPort, udpToIP); } }); } else { Console.WriteLine("Cannot continue without QTM connection and bodies."); } Console.WriteLine("Press ESC to quit."); if (Console.ReadKey(true).Key == ConsoleKey.Escape) { return; } }
static bool StartStreaming(RTState state, RTProtocol rtProtocol, StreamRate streamRate, short udpPort) { if (rtProtocol.StreamFrames(streamRate, -1, state.componentsInStream, udpPort) == false) { state.isStreaming = false; } else { state.isStreaming = true; } return(state.isStreaming); }
public bool ConnectStream(short udpPort, StreamRate streamRate, bool stream6d, bool stream3d) { List <ComponentType> streamedTypes = new List <ComponentType>(); if (stream3d) { streamedTypes.Add(ComponentType.Component3d); } if (stream6d) { streamedTypes.Add(ComponentType.Component6d); } //Start streaming and get the settings if (mProtocol.StreamFrames(streamRate, -1, false, streamedTypes, udpPort)) { if (stream3d) { if (!Get3DSettings()) { Debug.Log("Error retrieving settings"); return(false); } } if (stream6d) { if (!Get6DOFSettings()) { Debug.Log("Error retrieving settings"); return(false); } } // we register our function "process" as a callback for when protocol receives real time data packets // (eventDataCallback is also available to listen to events) mProtocol.RealTimeDataCallback += Process; mProtocol.EventDataCallback += Events; //Tell protocol to start listening to real time data mProtocol.ListenToStream(); mStreamingStatus = true; return(true); } else { Debug.Log("Error Creating Connection to server"); } return(false); }
public bool ConnectStream(short udpPort, StreamRate streamRate, bool stream6d, bool stream3d, bool streamgaze) { List <ComponentType> streamedTypes = new List <ComponentType>(); if (stream3d) { streamedTypes.Add(ComponentType.Component3d); } if (stream6d) { streamedTypes.Add(ComponentType.Component6d); } if (streamgaze) { streamedTypes.Add(ComponentType.ComponentGazeVector); } if (!mProtocol.GetGeneralSettings()) { Debug.Log("Error retrieving general QTM streaming settings"); return(false); } if (stream3d) { if (!Get3DSettings()) { Debug.Log("Error retrieving 3d settings from stream"); return(false); } } if (stream6d) { if (!Get6DOFSettings()) { Debug.Log("Error retrieving 6dof settings from stream"); return(false); } } if (streamgaze) { if (!GetGazeVectorSettings()) { // Don't fail too hard since gaze only has been available for a short while... but still give an error in the log. Debug.Log("Error retrieving gaze settings from stream"); } } // we register our function "process" as a callback for when protocol receives real time data packets // (eventDataCallback is also available to listen to events) mProtocol.RealTimeDataCallback += Process; mProtocol.EventDataCallback += Events; //Start streaming and get the settings if (mProtocol.StreamFrames(streamRate, -1, streamedTypes, udpPort)) { //Tell protocol to start listening to real time data mProtocol.ListenToStream(); mStreamingStatus = true; return(true); } else { Debug.Log("Error creating connection to server"); } return(false); }
private void Timer_Tick(object sender, EventArgs e) { // Try and connect if (!rtProtocol.IsConnected()) { if (!rtProtocol.Connect(ipAddress)) { Color.BackColor = System.Drawing.Color.Red; return; } Color.BackColor = System.Drawing.Color.OrangeRed; } // Check for available 6DOF data in the stream if (rtProtocol.Settings6DOF == null) { if (!rtProtocol.Get6dSettings()) { return; } Color.BackColor = System.Drawing.Color.Yellow; if (sixDofBodyNameToUse.Length > 0) { for (int bodyIndex = 0; bodyIndex < rtProtocol.Settings6DOF.BodyCount; bodyIndex++) { if (string.Equals(rtProtocol.Settings6DOF.Bodies[bodyIndex].Name, sixDofBodyNameToUse, StringComparison.OrdinalIgnoreCase)) { bodyIndexToUse = bodyIndex; break; } } } else { if (rtProtocol.Settings6DOF.BodyCount > 0) { sixDofBodyNameToUse = rtProtocol.Settings6DOF.Bodies[0].Name; bodyIndexToUse = 0; } } eulerNames = rtProtocol.Settings6DOF.EulerNames; // Start streaming 6dof euler residual data at 10Hz frequency rtProtocol.StreamFrames(StreamRate.RateFrequency, 10, QTMRealTimeSDK.Data.ComponentType.Component6dEulerResidual); Thread.Sleep(500); } // Get RTPacket from stream PacketType packetType; rtProtocol.ReceiveRTPacket(out packetType, false); // Handle data packet if (packetType == PacketType.PacketData) { Color.BackColor = System.Drawing.Color.Green; var sixDofData = rtProtocol.GetRTPacket().Get6DOFEulerResidualData(); if (sixDofData != null) { // Put 6dof data information in the labels if (sixDofData.Count > bodyIndexToUse) { var sixDofBody = sixDofData[bodyIndexToUse]; this.Body.Text = sixDofBodyNameToUse; this.X.Text = float.IsNaN(sixDofBody.Position.X) ? "X:---" : string.Format("X:{0:F1}", sixDofBody.Position.X); this.Y.Text = float.IsNaN(sixDofBody.Position.Y) ? "Y:---" : string.Format("Y:{0:F1}", sixDofBody.Position.Y); this.Z.Text = float.IsNaN(sixDofBody.Position.Z) ? "Z:---" : string.Format("Z:{0:F1}", sixDofBody.Position.Z); this.Residual.Text = float.IsNaN(sixDofBody.Residual) ? "Residual:---" : string.Format("Residual:{0:F1}", sixDofBody.Residual); this.First.Text = float.IsNaN(sixDofBody.Rotation.First) ? string.Format("{0}:---", eulerNames.First) : string.Format("{0}:{1:F1}", eulerNames.First, sixDofBody.Rotation.First); this.Second.Text = float.IsNaN(sixDofBody.Rotation.Second) ? string.Format("{0}:---", eulerNames.Second) : string.Format("{0}:{1:F1}", eulerNames.Second, sixDofBody.Rotation.Second); this.Third.Text = float.IsNaN(sixDofBody.Rotation.Third) ? string.Format("{0}:---", eulerNames.Third) : string.Format("{0}:{1:F1}", eulerNames.Third, sixDofBody.Rotation.Third); } } } // Handle event packet if (packetType == PacketType.PacketEvent) { var qtmEvent = rtProtocol.GetRTPacket().GetEvent(); switch (qtmEvent) { case QTMEvent.EventConnectionClosed: case QTMEvent.EventCaptureStopped: case QTMEvent.EventCalibrationStopped: case QTMEvent.EventRTFromFileStopped: case QTMEvent.EventQTMShuttingDown: // If QTM is shutting down then handle it, disconnect and empty labels rtProtocol.StreamFramesStop(); rtProtocol.Disconnect(); Color.BackColor = System.Drawing.Color.Red; this.Body.Text = "Body"; this.X.Text = "X"; this.Y.Text = "Y"; this.Z.Text = "Z"; this.Residual.Text = "Residual"; this.First.Text = eulerNames.First; this.Second.Text = eulerNames.Second; this.Third.Text = eulerNames.Third; break; } } }
public bool ConnectStream(short udpPort, StreamRate streamRate, bool stream6d, bool stream3d, bool stream3dNoLabels, bool streamGaze, bool streamAnalog, bool streamSkeleton) { List <ComponentType> streamedTypes = new List <ComponentType>(); if (!mProtocol.GetGeneralSettings()) { Debug.Log("Error retrieving general QTM streaming settings"); return(false); } if (stream3d || stream3dNoLabels) { if (Get3DSettings()) { if (stream3d) { streamedTypes.Add(ComponentType.Component3dResidual); } if (stream3dNoLabels) { streamedTypes.Add(ComponentType.Component3dNoLabelsResidual); } } else { Debug.Log("Error retrieving 3d settings from stream"); return(false); } } if (stream6d) { if (Get6DOFSettings()) { streamedTypes.Add(ComponentType.Component6d); } else { Debug.Log("Error retrieving 6dof settings from stream"); } } if (streamGaze) { if (GetGazeVectorSettings()) { streamedTypes.Add(ComponentType.ComponentGazeVector); } else { // Don't fail too hard since gaze only has been available for a short while... but still give an error in the log. Debug.Log("Error retrieving gaze settings from stream"); } } if (streamAnalog) { if (GetAnalogSettings()) { streamedTypes.Add(ComponentType.ComponentAnalog); } else { // Don't fail too hard since gaze only has been available for a short while... but still give an error in the log. Debug.Log("Error retrieving analog settings from stream"); } } if (streamSkeleton) { if (GetSkeletonSettings()) { streamedTypes.Add(ComponentType.ComponentSkeleton); } else { Debug.Log("Error retrieving skeleton settings from stream"); } } //Start streaming and get the settings if (mProtocol.StreamFrames(streamRate, -1, streamedTypes, udpPort)) { //Tell protocol to start listening to real time data mProtocol.ListenToStream(); mStreamingStatus = true; return(true); } else { Debug.Log("Error creating connection to server"); } return(false); }
void StartStreaming(string ipAddress) { Debug.LogFormat("Starting stream from {0}...", ipAddress); // Init protocol rtProtocol = new RTProtocol(); if (!rtProtocol.IsConnected()) { // Check if connection to QTM is possible if (!rtProtocol.IsConnected()) { if (!rtProtocol.Connect(ipAddress)) { Debug.Log("QTM: Trying to connect..."); return; } Debug.Log("QTM: Connected!"); } // Get settings and start stream if (rtProtocol.GeneralSettings == null) { if (!rtProtocol.GetGeneralSettings()) { Debug.Log("QTM: Trying to get General settings..."); return; } Debug.Log("QTM: General settings available."); // Print camera settings to console Debug.LogFormat("QTM: Frequency: {0}", rtProtocol.GeneralSettings.CaptureFrequency); Debug.Log("QTM: Cameras:"); foreach (var camera in rtProtocol.GeneralSettings.CameraSettings) { Debug.LogFormat("\t{0}", camera.Model); } // Reset mocap gameobject foreach (Transform child in mocapGameObject.transform) { GameObject.Destroy(child.gameObject); } // Init components to stream List <QTMRealTimeSDK.Data.ComponentType> componentsToStream = new List <QTMRealTimeSDK.Data.ComponentType>(); // Start 2D data stream and print to console if (print2DToConsole) { Debug.Log("QTM: Starting to stream 2D data, printing to console."); componentsToStream.Add(QTMRealTimeSDK.Data.ComponentType.Component2d); } // Start 3D data stream... if (print3DToConsole || render3D) { Debug.Log("QTM: Starting to stream 3D data."); componentsToStream.Add(QTMRealTimeSDK.Data.ComponentType.Component3dResidual); // ...and print to console... if (print3DToConsole) { Debug.Log("QTM: 3D data stream will print to console."); } // ...and/or render as balls if (render3D) { Debug.Log("QTM: 3D data stream will render in world."); rtProtocol.Get3dSettings(); balls = new GameObject[rtProtocol.Settings3D.Labels.Count]; for (int i = 0; i < balls.Length; i++) { balls[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere); balls[i].transform.parent = mocapGameObject.transform; balls[i].transform.localScale = new Vector3(0.03f, 0.03f, 0.03f); } } } // Start 6D data stream and render if (render6D) { rtProtocol.Get6dSettings(); List <QTMRealTimeSDK.Settings.Settings6DOF> qtmBodies = rtProtocol.Settings6DOF.Bodies; foreach (QTMRealTimeSDK.Settings.Settings6DOF body in qtmBodies) { Debug.LogFormat("QTM: Found 6DOF body: {0}", body.Name); } cubes = new GameObject[qtmBodies.Count]; for (int i = 0; i < cubes.Length; i++) { cubes[i] = GameObject.CreatePrimitive(PrimitiveType.Cube); cubes[i].transform.parent = mocapGameObject.transform; cubes[i].transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); } Debug.LogFormat("QTM: Starting to stream 6D data, rendering in world."); componentsToStream.Add(QTMRealTimeSDK.Data.ComponentType.Component6dResidual); } rtProtocol.StreamFrames(StreamRate.RateFrequency, streamFrequency, componentsToStream); } } }