Esempio n. 1
0
        static void Main(string[] args)
        {
            unix_base_ts = new TimeSpan(unix_base_ticks);
            // Initialize the kinect sensor
            //kinect IS NOT AN INSTANTIABLE OBJECT - you get a 'device' from the system driver
            try
            {
                kinect = KinectSensor.Default;
            }
            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine("It appears that no Kinect sensor is connected to your computer!");
                return;
            }
            //device initialization code
            try
            {
                Console.WriteLine("Starting initialization");
                kinect.Open();
                color_reader = kinect.ColorFrameSource.OpenReader();
                depth_reader = kinect.DepthFrameSource.OpenReader();
                Console.WriteLine("Initialization successful");
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Failed trying to set up the kinect. Is the device connected, on, and not being used by another application?");
                return;
            }
            // Initialize the socket bridge
            color_tx = new ROS_CS.SocketBridge.SocketTX <ROS_CS.sensor_msgs.Image>(9001);
            depth_tx = new ROS_CS.SocketBridge.SocketTX <ROS_CS.sensor_msgs.Image>(9002);
            //color_rx = new ROS_CS.SocketBridge.SocketRX<ROS_CS.sensor_msgs.Image>("127.0.0.1", 9001, ColorImageCB);
            bool control         = true;
            long depth_timestamp = 0;
            long color_timestamp = 0;

            while (control)
            {
                //Get depth data
                DepthFrame latest_depth = depth_reader.AcquireLatestFrame();
                if (latest_depth != null)
                {
                    Console.WriteLine("Current depth timestamp: {0:D}, new timestamp: {1:D}", depth_timestamp, latest_depth.RelativeTime);
                    if (latest_depth.RelativeTime > depth_timestamp)
                    {
                        ROS_CS.sensor_msgs.Image depth_image = GetDepthImageFromRaw(latest_depth);
                        if (depth_image != null)
                        {
                            Console.WriteLine("Sending depth image");
                            depth_tx.Send(depth_image);
                        }
                        else
                        {
                            Console.WriteLine("Null depth image");
                        }
                        depth_timestamp = latest_depth.RelativeTime;
                    }
                }
                //Get color data
                ColorFrame latest_color = color_reader.AcquireLatestFrame();
                if (latest_color != null)
                {
                    Console.WriteLine("Current color timestamp: {0:D}, new timestamp: {1:D}", color_timestamp, latest_color.RelativeTime);
                    if (latest_color.RelativeTime > color_timestamp)
                    {
                        ROS_CS.sensor_msgs.Image color_image = GetColorImageFromRaw(latest_color);
                        if (color_image != null)
                        {
                            Console.WriteLine("Sending color image");
                            color_tx.Send(color_image);
                        }
                        else
                        {
                            Console.WriteLine("Null color image");
                        }
                        color_timestamp = latest_color.RelativeTime;
                    }
                }
            }
        }
Esempio n. 2
0
 static void Main(string[] args)
 {
     unix_base_ts = new TimeSpan(unix_base_ticks);
     // Initialize the kinect sensor
     //kinect IS NOT AN INSTANTIABLE OBJECT - you get a 'device' from the system driver
     try
     {
         kinect = KinectSensor.Default;
     }
     catch (ArgumentOutOfRangeException)
     {
         Console.WriteLine("It appears that no Kinect sensor is connected to your computer!");
         return;
     }
     //device initialization code
     try
     {
         Console.WriteLine("Starting initialization");
         kinect.Open();
         color_reader = kinect.ColorFrameSource.OpenReader();
         depth_reader = kinect.DepthFrameSource.OpenReader();
         Console.WriteLine("Initialization successful");
     }
     catch (InvalidOperationException)
     {
         Console.WriteLine("Failed trying to set up the kinect. Is the device connected, on, and not being used by another application?");
         return;
     }
     // Initialize the socket bridge
     color_tx = new ROS_CS.SocketBridge.SocketTX<ROS_CS.sensor_msgs.Image>(9001);
     depth_tx = new ROS_CS.SocketBridge.SocketTX<ROS_CS.sensor_msgs.Image>(9002);
     //color_rx = new ROS_CS.SocketBridge.SocketRX<ROS_CS.sensor_msgs.Image>("127.0.0.1", 9001, ColorImageCB);
     bool control = true;
     long depth_timestamp = 0;
     long color_timestamp = 0;
     while (control)
     {
         //Get depth data
         DepthFrame latest_depth = depth_reader.AcquireLatestFrame();
         if (latest_depth != null)
         {
             Console.WriteLine("Current depth timestamp: {0:D}, new timestamp: {1:D}", depth_timestamp, latest_depth.RelativeTime);
             if (latest_depth.RelativeTime > depth_timestamp)
             {
                 ROS_CS.sensor_msgs.Image depth_image = GetDepthImageFromRaw(latest_depth);
                 if (depth_image != null)
                 {
                     Console.WriteLine("Sending depth image");
                     depth_tx.Send(depth_image);
                 }
                 else
                 {
                     Console.WriteLine("Null depth image");
                 }
                 depth_timestamp = latest_depth.RelativeTime;
             }
         }
         //Get color data
         ColorFrame latest_color = color_reader.AcquireLatestFrame();
         if (latest_color != null)
         {
             Console.WriteLine("Current color timestamp: {0:D}, new timestamp: {1:D}", color_timestamp, latest_color.RelativeTime);
             if (latest_color.RelativeTime > color_timestamp)
             {
                 ROS_CS.sensor_msgs.Image color_image = GetColorImageFromRaw(latest_color);
                 if (color_image != null)
                 {
                     Console.WriteLine("Sending color image");
                     color_tx.Send(color_image);
                 }
                 else
                 {
                     Console.WriteLine("Null color image");
                 }
                 color_timestamp = latest_color.RelativeTime;
             }
         }
     }
 }