コード例 #1
0
		/// <summary>
		/// Start this instance.
		/// </summary>
	    public void start()
	    {
			dataUpdated =  false;
	        while (true)
	        {
				
	            if (newData)
	            {
	                if (packetMutex.WaitOne())
	                {
	                    try
	                    {
	                        newData = false;
	
	                        if (lastPackets[5] == 0x31)
	                            datapacket = new XsEulerPacket(lastPackets);
	                        else
	                            datapacket = new XsQuaternionPacket(lastPackets);
	                    }
	                    catch
	                    {
	
	                    }
	                    finally
	                    {
	                        packetMutex.ReleaseMutex();
	
	                        if (lastPoseMutex.WaitOne())
	                        {
	                            try
	                            {	
	                                lastPosePositions = datapacket.pose.positions;
	                                lastPoseOrientations = datapacket.pose.orientations;
									
									dataUpdated = true;
	                            }
	                            catch
	                            {
	
	                            }
	                            finally
	                            {
	                                lastPoseMutex.ReleaseMutex();
	                            }
	                        }
	                    }
	                }
	            }
				
	            Thread.Sleep(1);
	        }
	    }
コード例 #2
0
        /// <summary>
        /// Start this instance.
        /// The datapacket will be set to one of the supported mode, based on it's type.
        /// </summary>
        public void start()
        {
            dataUpdated = false;
            while (true)
            {
                if (newData)
                {
                    if (packetMutex.WaitOne(1000))
                    {
                        try
                        {
                            newData = false;

                            //create the proper Data Packet based on the packet's type
                            int ptype = lastPackets[5];                            
                            if ( ptype == 0x31)
                                datapacket = new XsEulerPacket(lastPackets);
                            else if ( ptype == 0x32)
                                datapacket = new XsQuaternionPacket(lastPackets);
                            else
                                Debug.LogError("[xsens] Not supported packet type ("+ptype+")!");
                        }
                        finally
                        {
                            packetMutex.ReleaseMutex();

                            if (poseMutex.WaitOne(1000))
                            {
                                try
                                {
                                    XsMvnPose pose = datapacket.getPose();
                                    if(pose != null)
                                    {
                                        lastPosePositions = pose.positions;
                                        lastPoseOrientations = pose.orientations;
                                        dataUpdated = true;
                                    }
                                }
                                finally
                                {
                                    poseMutex.ReleaseMutex();

                                }
                            }//if poseMutex
                        }
                    }//if packetMutex
                }

                Thread.Sleep(1);
            }//while
        }
コード例 #3
0
        /// <summary>
        /// Start this instance.
        /// The datapacket will be set to one of the supported mode, based on it's type.
        /// </summary>
        public void start()
        {
            dataUpdated = false;
            while (true)
            {
                if (newData)
                {
                    if (packetMutex.WaitOne(1000))
                    {
                        try
                        {
                            newData = false;

                            //create the proper Data Packet based on the packet's type
                            int ptype = lastPackets[5];
                            if ( ptype == 0x31)
                                datapacket = new XsEulerPacket(lastPackets);
                            else if ( ptype == 0x32)
                                datapacket = new XsQuaternionPacket(lastPackets);
                            else
                                Debug.LogError("[xsens] Not supported packet type ("+ptype+")!");
                        }
                        finally
                        {
                            packetMutex.ReleaseMutex();

                            if (poseMutex.WaitOne(1000))
                            {
                                try
                                {
                                    XsMvnPose pose = datapacket.getPose();
                                    if(pose != null)
                                    {
                                        lastPosePositions = pose.positions;
                                        lastPoseOrientations = pose.orientations;
                                        dataUpdated = true;
                                    }
                                }
                                finally
                                {
                                    poseMutex.ReleaseMutex();

                                }
                            }//if poseMutex
                        }
                    }//if packetMutex
                }

                Thread.Sleep(1);
            }//while
        }
コード例 #4
0
        /// <summary>
        /// Start this instance.
        /// The datapacket will be set to one of the supported mode, based on its type.
        /// </summary>
        public void start()
        {
            dataUpdated = false;
            while (true)
            {
                if (newData)
                {
                    if (packetMutex.WaitOne(1000))
                    {
                        try
                        {
			                newData = false;

                            //create the proper Data Packet based on the packets type
							string ptypeString = System.String.Empty;
							ptypeString += (char)(lastPackets[4]);
							ptypeString += (char)(lastPackets[5]); // last two chars contain packet ID type
							int ptype = Convert.ToInt32(ptypeString);      
							switch ((StreamingProtocol)ptype)
							{
							case StreamingProtocol.SPPoseEuler:
									datapacket = new XsEulerPacket(lastPackets);
								break;
							case StreamingProtocol.SPPoseQuaternion:
							case StreamingProtocol.SPPoseUnity3D:
								// technically this one should be handled differently
								datapacket = new XsQuaternionPacket(lastPackets);
								break;
							case StreamingProtocol.SPMetaScalingLegacy:
							case StreamingProtocol.SPMetaPropInfoLegacy:
							case StreamingProtocol.SPMetaMoreMeta:
							case StreamingProtocol.SPMetaScaling:
								// ignored packet containing not useful meta-data information for the unity plug-in. 
								break;
							case StreamingProtocol.SPPosePositions:
							case StreamingProtocol.SPTagPositionsLegacy:
								Debug.LogError("[xsens] Wrong protocol identified. Try to change the protocol type in the Network Streamer preferences panel in MVN Studio.");
								break;
							default:
								Debug.LogError("[xsens] Not supported packet type ("+ ptype +")!");
								break;
							}
                        }
                        finally
                        {
                            packetMutex.ReleaseMutex();

                            if (poseMutex.WaitOne(1000))
                            {
                                try
                                {
                                    XsMvnPose pose = datapacket.getPose();
                                    if(pose != null)
                                    {
                                        lastPosePositions = pose.positions;
                                        lastPoseOrientations = pose.orientations;
                                        dataUpdated = true;
                                    }
                                }
                                finally
                                {
                                    poseMutex.ReleaseMutex();

                                }
                            }//if poseMutex
                        }
                    }//if packetMutex
                }

                Thread.Sleep(1);
            }//while
        }