Пример #1
0
    void Start()
    {
        Debug.Log("Starting Vicon");
        mConnected = false;
        pClient    = new ViconDataStreamSDK.DotNET.Client();
        Debug.Log("Connecting to Vicon");
        Output_Connect connect_result = pClient.Connect("localhost:801");

        if (connect_result.Result == Result.Success)
        {
            Debug.Log("Connected");
            mConnected = true;
        }
        else
        {
            Debug.Log("Not Connected");
        }

        pClient.EnableSegmentData();
        pClient.SetStreamMode(StreamMode.ClientPull);
        pClient.SetAxisMapping(Direction.Forward, Direction.Left, Direction.Up);
    }
Пример #2
0
	void Start () {

		Debug.Log ("Starting Vicon");
		mConnected = false;
		pClient = new ViconDataStreamSDK.DotNET.Client();
		Debug.Log ("Connecting to Vicon");
		Output_Connect connect_result = pClient.Connect ("localhost:801");
		if (connect_result.Result == Result.Success)
		{
			Debug.Log ("Connected");
			mConnected = true;
		} else {
			Debug.Log ("Not Connected");
		}

		pClient.EnableSegmentData();
		pClient.SetStreamMode (StreamMode.ClientPull);
		pClient.SetAxisMapping (Direction.Forward, Direction.Left, Direction.Up);



	}
        static void Main(string[] args)
        {
            // Program options
            bool TransmitMulticast = false;
            bool EnableHapticTest = false;
            bool bReadCentroids = false;
            List<String> HapticOnList = new List<String>();
            int Counter = 1;

            string HostName = "localhost:801"; // connect to Vicon system locally
               // string HostName = "192.168.1.1:801";
            if (args.Length > 0)
            {
                HostName = args[0];
            }

            // parsing all the haptic arguments
            for (int j = 1; j < args.Length; ++j)
            {
                string HapticArg = "--enable_haptic_test";
                if (String.Compare(args[j], HapticArg) == 0)
                {
                    EnableHapticTest = true;
                    ++j;
                    while (j < args.Length && String.Compare(args[j], 0, "--", 0, 2) != 0)
                    {
                        HapticOnList.Add(args[j]);
                        ++j;
                    }
                }

                string CentroidsArg = "--centroids";
                if (String.Compare(args[j], CentroidsArg) == 0)
                {
                    bReadCentroids = true;
                }
            }
            // Make a new client
            ViconDataStreamSDK.DotNET.Client MyClient = new ViconDataStreamSDK.DotNET.Client();

            // Connect to a server
            Console.Write("Connecting to {0} ...", HostName);
            while (!MyClient.IsConnected().Connected)
            {
                // Direct connection
                MyClient.Connect(HostName);

                // Multicast connection
                // MyClient.ConnectToMulticast( HostName, "224.0.0.0" );

                System.Threading.Thread.Sleep(200);
                Console.Write(".");
            }
            Console.WriteLine();

            // Enable some different data types
            MyClient.EnableSegmentData();
            MyClient.EnableMarkerData();
            MyClient.EnableUnlabeledMarkerData();
            MyClient.EnableDeviceData();
            if (bReadCentroids)
            {
                MyClient.EnableCentroidData();
            }

            Console.WriteLine("Segment Data Enabled: {0}", MyClient.IsSegmentDataEnabled().Enabled);
            Console.WriteLine("Marker Data Enabled: {0}", MyClient.IsMarkerDataEnabled().Enabled);
            Console.WriteLine("Unlabeled Marker Data Enabled: {0}", MyClient.IsUnlabeledMarkerDataEnabled().Enabled);
            Console.WriteLine("Device Data Enabled: {0}", MyClient.IsDeviceDataEnabled().Enabled);
            Console.WriteLine("Centroid Data Enabled: {0}", MyClient.IsCentroidDataEnabled().Enabled);

            // Set the streaming mode
            MyClient.SetStreamMode(ViconDataStreamSDK.DotNET.StreamMode.ClientPull);
            // MyClient.SetStreamMode( ViconDataStreamSDK.DotNET.StreamMode.ClientPullPreFetch );
            // MyClient.SetStreamMode( ViconDataStreamSDK.DotNET.StreamMode.ServerPush );

            // Set the global up axis
            MyClient.SetAxisMapping(ViconDataStreamSDK.DotNET.Direction.Forward,
                                     ViconDataStreamSDK.DotNET.Direction.Left,
                                     ViconDataStreamSDK.DotNET.Direction.Up); // Z-up
            // MyClient.SetAxisMapping( ViconDataStreamSDK.DotNET.Direction.Forward,
            //                          ViconDataStreamSDK.DotNET.Direction.Up,
            //                          ViconDataStreamSDK.DotNET.Direction.Right ); // Y-up

            Output_GetAxisMapping _Output_GetAxisMapping = MyClient.GetAxisMapping();
            Console.WriteLine("Axis Mapping: X-{0} Y-{1} Z-{2}", Adapt(_Output_GetAxisMapping.XAxis),
                                                                  Adapt(_Output_GetAxisMapping.YAxis),
                                                                  Adapt(_Output_GetAxisMapping.ZAxis));

            // Discover the version number
            Output_GetVersion _Output_GetVersion = MyClient.GetVersion();
            Console.WriteLine("Version: {0}.{1}.{2}", _Output_GetVersion.Major,
                                                       _Output_GetVersion.Minor,
                                                       _Output_GetVersion.Point);

            if (TransmitMulticast)
            {
                MyClient.StartTransmittingMulticast("localhost", "224.0.0.0");
            }

            // Let the user set the IP Address and Port for sending out OSC info
            Console.WriteLine("Enter IP Address of Remote Computer receiving data: ");
            String oscIP = Console.ReadLine();
            Console.WriteLine("Enter PORT of Remote Computer receiving data: ");
            String oscPORT = Console.ReadLine();

            // offer a use a default IP / PORT
            if (oscIP.Length == 0 && oscPORT.Length == 0)
            {
                oscIP = "192.168.125.20";
                oscPORT = "55555";
                Console.WriteLine("...Set to default IP and PORT: "+oscIP+":"+oscPORT);

            }

            // Setup OSC sender to remote computer
            var sender = new SharpOSC.UDPSender(oscIP, Int32.Parse(oscPORT));// "10.140.76.75", 55555);

            Console.WriteLine();
            Console.WriteLine("Ready to Stream!");
            Console.WriteLine("+ + + + + + + + + + + + ");

            // Stream Mocap Data
            while (true)
            {
                ++Counter;
                // Console.KeyAvailable throws an exception if stdin is a pipe (e.g.
                // with TrackerDssdkTests.py), so we use try..catch:
                try {
                    if (Console.KeyAvailable){
                        break;
                    }
                }
                catch (InvalidOperationException){}

                // Get a frame
                //Console.Write("Waiting for new frame...");
                while (MyClient.GetFrame().Result != ViconDataStreamSDK.DotNET.Result.Success){
                    System.Threading.Thread.Sleep(200);
                    //Console.Write(".");
                }

                // stream out data to remote location via OSC
                sendRigidBodies(MyClient, sender);
                sendLocalRotationQuaternion(MyClient, sender);
                sendLabledMarkers(MyClient, sender);
                sendUnlabeledMarkers(MyClient,sender);

            }

            // shut down and disconnect

            if (TransmitMulticast){
                MyClient.StopTransmittingMulticast();
            }

            // Disconnect and dispose
            MyClient.Disconnect();
            MyClient = null;
        }