Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parent">
        /// Parent <see cref="Kinect"/> device that this Motor is part of
        /// </param>
        internal Motor(Kinect parent)
        {
            this.parentDevice = parent;

            // Set tilt to 0 to start
            this.Tilt = 0;
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parent">
        /// Parent <see cref="Kinect"/> device that this Motor is part of
        /// </param>
        internal Motor(Kinect parent)
        {
            this.parentDevice = parent;

            // Set tilt to 0 to start
            this.Tilt = 0;
        }
 /// <summary>
 /// Registers a device and its native pointer
 /// </summary>
 /// <param name="pointer">
 /// A <see cref="IntPtr"/>
 /// </param>
 /// <param name="device">
 /// A <see cref="Kinect"/>
 /// </param>
 public static void RegisterDevice(IntPtr pointer, Kinect device)
 {
     if (KinectNative.deviceMap.ContainsKey(pointer))
     {
         KinectNative.deviceMap.Remove(pointer);
     }
     KinectNative.deviceMap.Add(pointer, device);
 }
Example #4
0
        /// <summary>
        /// Handles image data from teh video camera
        /// </summary>
        /// <param name="device">
        /// A <see cref="IntPtr"/>
        /// </param>
        /// <param name="imageData">
        /// A <see cref="IntPtr"/>
        /// </param>
        /// <param name="timestamp">
        /// A <see cref="UInt32"/>
        /// </param>
        private static void HandleDataReceived(IntPtr device, IntPtr imageData, UInt32 timestamp)
        {
            // Figure out which device actually got this frame
            Kinect realDevice = KinectNative.GetDevice(device);

            // Calculate datetime from timestamp
            DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(timestamp);

            // Send out event
            realDevice.VideoCamera.DataReceived(realDevice, new DataReceivedEventArgs(dateTime, realDevice.VideoCamera.nextFrameImage));
        }
Example #5
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="parent">
		/// Parent <see cref="Kinect"/> device that this depth camera is part of
		/// </param>
		internal DepthCamera(Kinect parent) : base(parent)
		{
			// Update lsit of available modes for this camera
			this.UpdateDepthModes();
			
			// Set the mode to the first available mode
			this.Mode = this.Modes[0];
			
			// Setup callbacks
			KinectNative.freenect_set_depth_callback(parent.devicePointer, this.DataCallback);
		}
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parent">
        /// Parent <see cref="Kinect"/> device that this depth camera is part of
        /// </param>
        internal DepthCamera(Kinect parent) : base(parent)
        {
            // Update lsit of available modes for this camera
            this.UpdateDepthModes();

            // Set the mode to the first available mode
            this.Mode = this.Modes[0];

            // Setup callbacks
            KinectNative.freenect_set_depth_callback(parent.devicePointer, this.DataCallback);
        }
Example #7
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="parent">
		/// Parent <see cref="Kinect"/> device that this video camera is part of
		/// </param>
		internal VideoCamera(Kinect parent) : base(parent)
		{
			// Update modes available for this video camera
			this.UpdateVideoModes();
			
			// Use the first mode by default
			this.Mode = this.Modes[0];
			
			// Setup callbacks
			KinectNative.freenect_set_video_callback(parent.devicePointer, this.DataCallback);
		}
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parent">
        /// Parent <see cref="Kinect"/> device that this video camera is part of
        /// </param>
        internal VideoCamera(Kinect parent) : base(parent)
        {
            // Update modes available for this video camera
            this.UpdateVideoModes();

            // Use the first mode by default
            this.Mode = this.Modes[0];

            // Setup callbacks
            KinectNative.freenect_set_video_callback(parent.devicePointer, this.DataCallback);
        }
Example #9
0
        /// <summary>
        /// Base camera constructor
        /// </summary>
        /// <param name="parent">
        /// A <see cref="Kinect"/>
        /// </param>
        internal BaseCamera(Kinect parent)
        {
            // Save parent device
            this.parentDevice = parent;

            // Not running by default
            this.IsRunning = false;

            // Create callback
            this.DataCallback = new FreenectCameraDataCallback(this.HandleDataReceived);
        }
Example #10
0
		/// <summary>
		/// Driver
		/// </summary>
		/// <param name="args">
		/// A <see cref="System.String[]"/>
		/// </param>
		public static void Main (string[] args)
		{
			Console.WriteLine("----------------------------------------");
			Console.WriteLine("| Kinect.NET Wrapper Test              |");
			Console.WriteLine("----------------------------------------\n");
			
			// Try to get number of devices connected
			Console.WriteLine(" - Device Count: " + Kinect.DeviceCount);
			
			// Do more tests if there are devices present
			if(Kinect.DeviceCount > 0)
			{
				// Try to open a device
				Kinect k = new Kinect(0);
				Console.Write(" - Opening device 0...");
				k.Open();
				Console.WriteLine("Done.");
				
				// Try to set LED colors
				Console.WriteLine(" - LED Testing");
				string[] colors = Enum.GetNames(typeof(LEDColor));
				foreach(string color in colors)
				{
					var c = (LEDColor)Enum.Parse(typeof(LEDColor), color);
					Console.WriteLine("\t - Setting LED to Color: " + color);
					k.LED.Color = c;
					Thread.Sleep(3000);
				}
				
				// Try to control motor
				Console.WriteLine(" - Motor Testing");
				Console.WriteLine("\t - Setting tilt to 1 (should face all the way up)");
				k.Motor.Tilt = 1;
				Thread.Sleep(3000);
				Console.WriteLine("\t - Setting tilt to -1 (should face all the way down)");
				k.Motor.Tilt = -1;
				Thread.Sleep(3000);
				Console.WriteLine("\t - Setting tilt to 0 (should be back level)");
				k.Motor.Tilt = 0;
				Thread.Sleep(3000);
				
				// Close device
				Console.Write(" - Closing device 0...");
				k.Close();
				Console.WriteLine("Done.");
			}
			
			// Shutdown the Kinect context
			Kinect.Shutdown();

			// Pause...
			Console.ReadKey(true);
		}
Example #11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parent">
        /// Parent <see cref="Kinect"/> device that this depth camera is part of
        /// </param>
        internal DepthCamera(Kinect parent)
        {
            // Save parent device
            this.parentDevice = parent;

            // Not running by default
            this.IsRunning = false;

            // Set format to 11 bit by default
            this.DataFormat = DataFormatOption.Format11Bit;

            // Setup callbacks
            KinectNative.freenect_set_depth_callback(parent.devicePointer, DepthCallback);
        }
Example #12
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parent">
        /// Parent <see cref="Kinect"/> device that this video camera is part of
        /// </param>
        internal VideoCamera(Kinect parent)
        {
            // Save parent device
            this.parentDevice = parent;

            // Not running by default
            this.IsRunning = false;

            // Set format to RGB by default
            this.DataFormat = DataFormatOption.RGB;

            // Setup callbacks
            KinectNative.freenect_set_video_callback(parent.devicePointer, VideoCallback);
        }
Example #13
0
    public MainWindow()
    {
      this.worker = new BackgroundWorker();
      this.worker.DoWork += new DoWorkEventHandler(worker_DoWork);

      string fileName = String.Format("{0}_{1}_{2}_{3}_{4}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour,DateTime.Now.Minute);

      this.kinectWriter = new KinectWriter(@"C:\Temp\" + fileName + ".kinect");
      this.positionWriter = new PositiontWriter(@"C:\Temp\" + fileName + ".location");

      this.positionSensor = new TcpGpsSensor("127.0.0.1", 4352);
      this.positionSensor.PositionReceived += new EventHandler<PositionEventArgs>(positionSensor_PositionReceived);

      InitializeComponent();

        //startup logic from C# wrapper example
      if (Kinect.DeviceCount > 0)
      {
        kinect = new Kinect(0);

        kinect.Open();

        kinect.VideoCamera.DataBuffer = IntPtr.Zero;
        kinect.DepthCamera.DataBuffer = IntPtr.Zero;

        kinect.VideoCamera.DataReceived += VideoCamera_DataReceived;
        kinect.DepthCamera.DataReceived += DepthCamera_DataReceived;

        kinect.VideoCamera.Start();
        kinect.DepthCamera.Start();

        worker.RunWorkerAsync();
        this.positionSensor.Connect();
        this.positionSensor.Start();

        ThreadPool.QueueUserWorkItem(
          delegate
          {
            while (!_closed)
            {
              kinect.UpdateStatus();
              Kinect.ProcessEvents();

              Thread.Sleep(30);
            }
          });
      }
    }
Example #14
0
        /// <summary>
        /// Logging callback.
        /// </summary>
        /// <param name="device">
        /// A <see cref="IntPtr"/>
        /// </param>
        /// <param name="logLevel">
        /// A <see cref="Kinect.LogLevelOptions"/>
        /// </param>
        /// <param name="message">
        /// A <see cref="System.String"/>
        /// </param>
        internal static void LogCallback(IntPtr device, LoggingLevel logLevel, string message)
        {
            Kinect realDevice = KinectNative.GetDevice(device);

            Kinect.Log(null, new LogEventArgs(realDevice, logLevel, message));
        }
Example #15
0
 public LogEventArgs(Kinect device, LoggingLevel logLevel, string message)
 {
     this.Device   = device;
     this.LogLevel = logLevel;
     this.Message  = message;
 }
Example #16
0
		/// <summary>
		/// Base camera constructor
		/// </summary>
		/// <param name="parent">
		/// A <see cref="Kinect"/>
		/// </param>
		internal BaseCamera(Kinect parent)
		{
			// Save parent device
			this.parentDevice = parent;
			
			// Not running by default
			this.IsRunning = false;
			
			// Create callback
			this.DataCallback = new FreenectCameraDataCallback(this.HandleDataReceived);
		}
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="parent">
		/// Parent <see cref="Kinect"/> device that this video camera is part of
		/// </param>
		internal VideoCamera(Kinect parent)
		{
			// Save parent device
			this.parentDevice = parent;
			
			// Not running by default
			this.IsRunning = false;
			
			// Set format to RGB by default
			this.DataFormat = DataFormatOption.RGB;
			
			// Setup callbacks
			KinectNative.freenect_set_video_callback(parent.devicePointer, VideoCallback);
		}
Example #18
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="parent">
		/// Parent <see cref="Kinect"/> device that this LED is part of
		/// </param>
		internal LED(Kinect parent)
		{
			this.parentDevice = parent;
		}
Example #19
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="parent">
 /// Parent <see cref="Kinect"/> device that this LED is part of
 /// </param>
 internal LED(Kinect parent)
 {
     this.parentDevice = parent;
 }
Example #20
0
		public LogEventArgs(Kinect device, LoggingLevel logLevel, string message)
		{
			this.Device = device;
			this.LogLevel = logLevel;
			this.Message = message;
		}
Example #21
0
        private void Disconnect()
        {
            // Stop the update thread
            this.updateStatusThread.Abort();
            while(this.updateStatusThread.IsAlive)
            {
                // wait...
                Application.DoEvents();
                Thread.Sleep(1000);
                Console.WriteLine("waiting for disconnect...");
            }

            this.updateStatusThread = null;

            // Disable update timer first
            this.infoUpdateTimer.Enabled = false;

            // Disconnect from the device
            this.kinect.Close();
            this.kinect = null;

            // Disable controls again
            this.bottomPanel.Enabled = false;

            // Enable connect
            this.connectButton.Enabled = true;
            this.disconnectButton.Enabled = false;
        }
Example #22
0
 public static extern void freenect_set_log_level(IntPtr context, Kinect.LogLevelOptions level);
Example #23
0
		/// <summary>
		/// Connects to the specified device
		/// </summary>
		private void Connect(int deviceID)
		{
			// If a device is already connected, disconnect
			if(this.isRunning)
			{
				this.Disconnect();
			}
			
			// Now running
			this.isRunning = true;
			
			// Create instance
			this.kinect = new Kinect(deviceID);
			
			// Open kinect
			this.kinect.Open();
			
			// Set tilt to 0 to start with
			this.motorTiltUpDown.Value = 0;
			
			// Setup image handlers
			this.kinect.VideoCamera.DataReceived += HandleKinectVideoCameraDataReceived;
			this.kinect.DepthCamera.DataReceived += HandleKinectDepthCameraDataReceived;
			
			// LED is set to none to start
			this.kinect.LED.Color = LEDColor.None;
			this.selectLEDColorCombo.SelectedIndex = 0;
			
			// Update video/depth modes
			this.UpdateModeList();
			
			// Enable video/depth mode chooser
			this.selectVideoModeGroup.Enabled = true;
			
			// Setup update thread
			this.updateThread = new Thread(delegate()
			{
				while(this.isRunning)
				{
					try
					{
						// Update instance's status
						this.kinect.UpdateStatus();
						
						// Let preview control render another frame
						this.previewControl.Render();
					}
					catch(ThreadInterruptedException e)
					{
						return;
					}
					catch(Exception ex)
					{
						
					}
				}
			});
			
			// Start updating status
			this.statusUpdateTimer.Enabled = true;
			
			// Disable connect button and enable the disconnect one
			this.disconnectButton.Visible = true;
			this.connectButton.Visible = false;
			this.refreshButton.Visible = false;
			this.selectDeviceCombo.Enabled = false;
			
			// Enable content areas
			this.contentPanel.Enabled = true;
			
			// Start update thread
			this.updateThread.Start();
		}
Example #24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="parent">
 /// Parent <see cref="Kinect"/> device that this accelerometer is part of
 /// </param>
 internal Accelerometer(Kinect parent)
 {
     this.parentDevice = parent;
 }
Example #25
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="parent">
		/// Parent <see cref="Kinect"/> device that this depth camera is part of
		/// </param>
		internal DepthCamera(Kinect parent)
		{
			// Save parent device
			this.parentDevice = parent;
			
			// Not running by default
			this.IsRunning = false;
			
			// Set format to 11 bit by default
			this.DataFormat = DataFormatOption.Format11Bit;
			
			// Setup callbacks
			KinectNative.freenect_set_depth_callback(parent.devicePointer, DepthCallback);
		}
Example #26
0
		/// <summary>
		/// Logging callback.
		/// </summary>
		/// <param name="device">
		/// A <see cref="IntPtr"/>
		/// </param>
		/// <param name="logLevel">
		/// A <see cref="Kinect.LogLevelOptions"/>
		/// </param>
		/// <param name="message">
		/// A <see cref="System.String"/>
		/// </param>
		internal static void LogCallback(IntPtr device, Kinect.LogLevelOptions logLevel, string message)
		{
			Kinect realDevice = KinectNative.GetDevice(device);
			Kinect.Log(null, new LogEventArgs(realDevice, logLevel, message));
		}
Example #27
0
		/// <summary>
		/// Disconnects from teh currently connected Kinect device
		/// </summary>
		private void Disconnect()
		{
			// Are we running?
			if(this.isRunning == false)
			{
				return;	
			}
			
			// Stop updating status
			this.statusUpdateTimer.Enabled = false;
			
			// No longer running
			this.isRunning = false;
			
			// Wait till update thread closes down
			this.updateThread.Interrupt();
			this.updateThread.Join();
			this.updateThread = null;
			
			// Disconnect from the kinect
			this.kinect.Close();
			this.kinect = null;
			
			// Disable video/depth mode chooser
			this.selectVideoModeGroup.Enabled = false;
			
			// Disable disconnect button and enable the connect/refresh ones
			this.disconnectButton.Visible = false;
			this.connectButton.Visible = true;
			this.refreshButton.Visible = true;
			this.selectDeviceCombo.Enabled = true;
			
			// Disable content areas
			this.contentPanel.Enabled = false;
		}
Example #28
0
        private void Connect()
        {
            // Create device instance and open the connection
            this.kinect = new Kinect(this.kinectDeviceSelectCombo.SelectedIndex);
            this.kinect.Open();

            // Set the buffer to back first
            this.kinect.VideoCamera.DataBuffer = rgbHandleBack.AddrOfPinnedObject();
            this.kinect.DepthCamera.DataBuffer = depthHandleBack.AddrOfPinnedObject();

            // Set modes
            this.kinect.VideoCamera.DataFormat = VideoCamera.DataFormatOption.RGB;
            this.kinect.DepthCamera.DataFormat = DepthCamera.DataFormatOption.Format11Bit;

            // Enable controls and info
            this.bottomPanel.Enabled = true;

            // Set LED to none
            this.ledControlCombo.SelectedIndex = 0;

            // Set Motor to 0
            this.motorControlTrack.Value = 0;

            // Start video camera
            this.kinect.VideoCamera.DataReceived += new VideoCamera.DataReceivedEventHandler(this.HandleVideoDataReceived);
            this.kinect.VideoCamera.Start();

            // Start depth camera
            this.kinect.DepthCamera.DataReceived += new DepthCamera.DataReceivedEventHandler(this.HandleDepthDataReceived);
            this.kinect.DepthCamera.Start();

            // Enable disconnect
            this.connectButton.Enabled = false;
            this.disconnectButton.Enabled = true;

            // Enable update timer
            this.infoUpdateTimer.Enabled = true;

            // Start update status thread
            this.updateStatusThread = new Thread(delegate()
            {
                while(true)
                {
                    if(this.kinect == null)
                    {
                        continue;
                    }

                    // Update the status for this device
                    this.kinect.UpdateStatus();

                    // Let the kinect library handle any pending stuff on the usb streams.
                    Kinect.ProcessEvents();

                    try
                    {
                        this.imagePanel.Invalidate();
                    }
                    catch(Exception e)
                    {
                    }
                }
            });
            this.updateStatusThread.Start();
        }
Example #29
0
 /// <summary>
 /// Registers a device and its native pointer
 /// </summary>
 /// <param name="pointer">
 /// A <see cref="IntPtr"/>
 /// </param>
 /// <param name="device">
 /// A <see cref="Kinect"/>
 /// </param>
 public static void RegisterDevice(IntPtr pointer, Kinect device)
 {
     if(KinectNative.deviceMap.ContainsKey(pointer))
     {
         KinectNative.deviceMap.Remove(pointer);
     }
     KinectNative.deviceMap.Add(pointer, device);
 }
Example #30
0
 public LogEventArgs(Kinect device, Kinect.LogLevelOptions logLevel, string message)
 {
     this.Device   = device;
     this.LogLevel = logLevel;
     this.Message  = message;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="parent">
 /// Parent <see cref="Kinect"/> device that this accelerometer is part of
 /// </param>
 internal Accelerometer(Kinect parent)
 {
     this.parentDevice = parent;
 }
Example #32
0
 public LogEventArgs(Kinect device, Kinect.LogLevelOptions logLevel, string message)
 {
     this.Device = device;
     this.LogLevel = logLevel;
     this.Message = message;
 }