Module: Freenect::Driver

Extended by:
FFI::Library
Included in:
Context, Interface
Defined in:
lib/freenect/driver.rb

Defined Under Namespace

Classes: FreenectFormat, FreenectFrameMode, FreenectRawTiltState

Constant Summary collapse

FREENECT_COUNTS_PER_G =

Ticks per G for accelerometer as set per www.kionix.com/Product%20Sheets/KXSD9%20Product%20Brief.pdf

819
FREENECT_DEVICE_FLAGS =

Flags representing devices to open when freenect_open_device() is called. In particular, this allows libfreenect to grab only a subset of the devices in the Kinect, so you could (for instance) use libfreenect to handle audio and motor support while letting OpenNI have access to the cameras. If a device is not supported on a particular platform, its flag will be ignored.

enum(
  :freenect_device_motor,   0x01,
  :freenect_device_camaers, 0x02,
  :freenect_device_audio,   0x04
)
FREENECT_RESOLUTION =

Enumeration of available resolutions. Not all available resolutions are actually supported for all video formats. Frame modes may not perfectly match resolutions. For instance, FREENECT_RESOLUTION_MEDIUM is 640x488 for the IR camera.

enum(
  :freenect_resolution_low,    0,           # QVGA - 320x240 
  :freenect_resolution_medium, 1,           # VGA  - 640x480 
  :freenect_resolution_high,   2,           # SXGA - 1280x1024
  :freenect_resolution_dummy,  2147483647   # Dummy value to force enum to be 32 bits wide
)
FREENECT_VIDEO_FORMAT =

Enumeration of video frame information states. See openkinect.org/wiki/Protocol_Documentation#RGB_Camera for more information.

enum(
  :freenect_video_rgb,             0,          # Decompressed RGB mode (demosaicing done by libfreenect)
  :freenect_video_bayer,           1,          # Bayer compressed mode (raw information from camera)
  :freenect_video_ir_8bit,         2,          # 8-bit IR mode
  :freenect_video_ir_10bit,        3,          # 10-bit IR mode
  :freenect_video_ir_10bit_packed, 4,          # 10-bit packed IR mode
  :freenect_video_yuv_rgb,         5,          # YUV RGB mode
  :freenect_video_yuv_raw,         6,          # YUV Raw mode
  :freenect_video_dummy,           2147483647  # Dummy value to force enum to be 32 bits wide
)
FREENECT_DEPTH_FORMAT =

Enumeration of depth frame states See openkinect.org/wiki/Protocol_Documentation#RGB_Camera for more information.

enum(
  :freenect_depth_11bit,        0,         # 11 bit depth information in one uint16_t/pixel
  :freenect_depth_10bit,        1,         # 10 bit depth information in one uint16_t/pixel
  :freenect_depth_11bit_packed, 2,         # 11 bit packed depth information
  :freenect_depth_10bit_packed, 3,         # 10 bit packed depth information
  :freenet_depth_dummy,         2147483647 # Dummy value to force enum to be 32 bits wide 
)
FREENECT_LED_OPTIONS =

Enumeration of LED states See openkinect.org/wiki/Protocol_Documentation#Setting_LED for more information.

enum(
  :led_off,               0, # Turn LED off
  :led_green,             1, # Turn LED to Green
  :led_red,               2, # Turn LED to Red
  :led_yellow,            3, # Turn LED to Yellow
  :led_blink_green,       4, # Make LED blink Green
  :led_blink_red_yellow,  6  # Make LED blink Red/Yellow
)
FREENECT_TILT_STATUS_CODE =

Enumeration of tilt motor status

enum(
  :tilt_status_stopped, 0x00, # Tilt motor is stopped
  :tilt_status_limit,   0x01, # Tilt motor has reached movement limit
  :tilt_status_moving,  0x04  # Tilrequire 'ffi't motor is currently moving to new position
)
FREENECT_LOGLEVEL =

Enumeration of message logging levels

enum( 
  :freenect_log_fatal,   0, # Log for crashing/non-recoverable errors
  :freenect_log_error,   1, # Log for major errors
  :freenect_log_warning, 2, # Log for warning messages
  :freenect_log_notice,  3, # Log for important messages
  :freenect_log_info,    3, # Log for normal messages
  :freenect_log_debug,   5, # Log for useful development messages
  :freenect_log_spew,    6, # Log for slightly less useful messages
  :freenect_log_flood,   7  # Log EVERYTHING. May slow performance.
)

Instance Method Summary collapse

Instance Method Details

#freenect_find_depth_modeObject

Convenience function to return a mode descriptor matching the specified resolution and depth camera pixel format, if one exists.

Parameters:

  • res

    Resolution desired

  • fmt

    Pixel format desired

Returns:

  • A freenect_frame_mode that matches the arguments specified, if such a valid mode exists; otherwise, an invalid freenect_frame_mode.



409
# File 'lib/freenect/driver.rb', line 409

attach_function :freenect_find_depth_mode, [FREENECT_RESOLUTION, FREENECT_DEPTH_FORMAT], FreenectFrameMode.by_value

#freenect_find_video_modeObject

Convenience function to return a mode descriptor matching the specified resolution and video camera pixel format, if one exists.

Parameters:

  • res

    Resolution desired

  • fmt

    Pixel format desired

Returns:

  • A freenect_frame_mode that matches the arguments specified, if such a valid mode exists; otherwise, an invalid freenect_frame_mode.



400
# File 'lib/freenect/driver.rb', line 400

attach_function :freenect_find_video_mode,  [FREENECT_RESOLUTION, FREENECT_VIDEO_FORMAT], FreenectFrameMode.by_value

#freenect_get_current_depth_modeObject

Get the frame descriptor of the current depth mode for the specified freenect device.

Parameters:

  • dev

    Which device to return the currently-set depth mode for

Returns:

  • A freenect_frame_mode describing the current depth mode of the specified device



333
# File 'lib/freenect/driver.rb', line 333

attach_function :freenect_get_current_depth_mode, [:freenect_device], FreenectFrameMode.by_value

#freenect_get_current_video_modeObject

Get the frame descriptor of the current video mode for the specified freenect device.

Parameters:

  • dev

    Which device to return the currently-set video mode for

Returns:

  • A freenect_frame_mode describing the current video mode of the specified device



325
# File 'lib/freenect/driver.rb', line 325

attach_function :freenect_get_current_video_mode, [:freenect_device], FreenectFrameMode.by_value

#freenect_get_depth_modeObject

Get the frame descriptor of the nth supported depth mode for the depth camera.

Parameters:

  • n

    Which of the supported modes to return information about

Returns:

  • A freenect_frame_mode describing the nth depth mode



391
# File 'lib/freenect/driver.rb', line 391

attach_function :freenect_get_depth_mode, [:int], FreenectFrameMode.by_value

#freenect_get_depth_mode_countObject

Get the number of depth camera modes supported by the driver. This includes both RGB and IR modes.

Returns:

  • Number of depth modes supported by the driver



383
# File 'lib/freenect/driver.rb', line 383

attach_function :freenect_get_depth_mode_count, [], :int

#freenect_get_tilt_degsObject

Return the tilt state, in degrees with respect to the horizon

Parameters:

  • state

    The tilt state struct from a device

Returns:

  • Current degree of tilt of the device



288
# File 'lib/freenect/driver.rb', line 288

attach_function :freenect_get_tilt_degs, [FreenectRawTiltState], :double

#freenect_get_tilt_stateObject

Retrieve the tilt state from a device

Parameters:

  • dev

    Device to retrieve tilt state from

Returns:

  • The tilt state struct of the device



281
# File 'lib/freenect/driver.rb', line 281

attach_function :freenect_get_tilt_state, [:freenect_device], FreenectRawTiltState

#freenect_get_tilt_statusObject

Return the movement state of the tilt motor (moving, stopped, etc…)

freenect_tilt_st:freenect_get_tilt_statusatus_code enum for more info.

Parameters:

  • state

    Raw state struct to get the tilt status code from

Returns:

  • Status code of the tilt device. See



308
# File 'lib/freenect/driver.rb', line 308

attach_function :freenect_get_tilt_status, [FreenectRawTiltState], FREENECT_TILT_STATUS_CODE

#freenect_get_userObject

Retrieve the pointer to user data from the device struct

Parameters:

  • dev

    Device from which to get user data

Returns:

  • Pointer to user data



205
# File 'lib/freenect/driver.rb', line 205

attach_function :freenect_get_user, [:freenect_device], :pointer

#freenect_get_video_modeObject

Get the frame descriptor of the nth supported video mode for the video camera.

Parameters:

  • n

    Which of the supported modes to return information about

Returns:

  • A freenect_frame_mode describing the nth video mode



378
# File 'lib/freenect/driver.rb', line 378

attach_function :freenect_get_video_mode, [:int], FreenectFrameMode.by_value

#freenect_get_video_mode_countObject

Get the number of video camera modes supported by the driver. This includes both RGB and IR modes.

Returns:

  • Number of video modes supported by the driver



370
# File 'lib/freenect/driver.rb', line 370

attach_function :freenect_get_video_mode_count, [], :int

#freenect_initObject

Initialize a freenect context and do any setup required for platform specific USB libraries.

Parameters:

  • ctx

    Address of pointer to freenect context struct to allocate and initialize

  • usb_ctx

    USB context to initialize. Can be NULL if not using multiple contexts.

Returns:

  • 0 on success, < 0 on error



128
# File 'lib/freenect/driver.rb', line 128

attach_function :freenect_init, [:freenect_context, :freenect_usb_context], :int

#freenect_num_devicesObject

Return the number of kinect devices currently connected to the system

Parameters:

  • ctx

    Context to access device count through

Returns:

  • Number of devices connected, < 0 on error



164
# File 'lib/freenect/driver.rb', line 164

attach_function :freenect_num_devices, [:freenect_context], :int

#freenect_open_deviceObject

Opens a kinect device via a context. Index specifies the index of the device on the current state of the bus. Bus resets may cause indexes to shift.

Parameters:

  • ctx

    Context to open device through

  • dev

    Device structure to assign opened device to

  • index

    Index of the device on the bus

Returns:

  • 0 on success, < 0 on error



185
# File 'lib/freenect/driver.rb', line 185

attach_function :freenect_open_device, [:freenect_context, :freenect_device, :int], :int

#freenect_process_eventsObject

Calls the platform specific usb event processor

Parameters:

  • ctx

    context to process events for

Returns:

  • 0 on success, other values on error, platform/library dependant



156
# File 'lib/freenect/driver.rb', line 156

attach_function :freenect_process_events, [:freenect_context], :int

#freenect_set_depth_modeObject

Sets the current depth mode for the specified device. The mode cannot be changed while streaming is active.

Parameters:

  • dev

    Device for which to set the depth mode

  • mode

    Frame mode to set

Returns:

  • 0 on success, < 0 if error



354
# File 'lib/freenect/driver.rb', line 354

attach_function :freenect_set_depth_mode, [:freenect_device, FreenectFrameMode.by_value], :int

#freenect_set_ledObject

Set the state of the LED. Uses blocking control message call to update device.

Parameters:

  • dev

    Device to set the LED state

  • option

    LED state to set on device. See freenect_led_options enum.

Returns:

  • 0 on success, < 0 on error



317
# File 'lib/freenect/driver.rb', line 317

attach_function :freenect_set_led, [:freenect_device, FREENECT_LED_OPTIONS], :int

#freenect_set_tilt_degsObject

Set the tilt state of the device, in degrees with respect to the horizon. Uses blocking control message call to update device. Function return does not reflect state of device, device may still be moving to new position after the function returns. Use freenect_get_tilt_status() to find current movement state.

Parameters:

  • dev

    Device to set tilt state

  • angle

    Angle the device should tilt to

Returns:

  • 0 on success, < 0 on error.



300
# File 'lib/freenect/driver.rb', line 300

attach_function :freenect_set_tilt_degs, [:freenect_device, :double], :int

#freenect_set_video_bufferObject

Set the buffer to store depth information to. Size of buffer is dependant on video format. See FREENECT_VIDEO_*_SIZE defines for more information.

Parameters:

  • dev

    Device to set video buffer for.

  • buf

    Buffer to store video information to.

Returns:

  • 0 on success, < 0 on error



237
# File 'lib/freenect/driver.rb', line 237

attach_function :freenect_set_video_buffer, [:freenect_device, :pointer], :int

#freenect_set_video_modeObject

Sets the current video mode for the specified device. If the freenect_frame_mode specified is not one provided by the driver e.g. from freenect_get_video_mode() or freenect_find_video_mode() then behavior is undefined. The current video mode cannot be changed while streaming is active.

Parameters:

  • dev

    Device for which to set the video mode

  • mode

    Frame mode to set

Returns:

  • 0 on success, < 0 if error



345
# File 'lib/freenect/driver.rb', line 345

attach_function :freenect_set_video_mode, [:freenect_device, FreenectFrameMode.by_value], :int

#freenect_shutdownObject

Closes the device if it is open, and frees the context

Parameters:

  • ctx

    freenect context to close/free

Returns:

  • 0 on success



135
# File 'lib/freenect/driver.rb', line 135

attach_function :freenect_shutdown, [:freenect_context], :int

#freenect_start_depthObject

Start the depth information stream for a device.

Parameters:

  • dev

    Device to start depth information stream for.

Returns:

  • 0 on success, < 0 on error



244
# File 'lib/freenect/driver.rb', line 244

attach_function :freenect_start_depth, [:freenect_device], :int

#freenect_start_videoObject

Start the video information stream for a device.

Parameters:

  • dev

    Device to start video information stream for.

Returns:

  • 0 on success, < 0 on error



251
# File 'lib/freenect/driver.rb', line 251

attach_function :freenect_start_video, [:freenect_device], :int

#freenect_stop_depthObject

Stop the depth information stream for a device

Parameters:

  • dev

    Device to stop depth information stream on.

Returns:

  • 0 on success, < 0 on error



258
# File 'lib/freenect/driver.rb', line 258

attach_function :freenect_stop_depth, [:freenect_device], :int

#freenect_stop_videoObject

Stop the video information stream for a device

Parameters:

  • dev

    Device to stop video information stream on.

Returns:

  • 0 on success, < 0 on error



265
# File 'lib/freenect/driver.rb', line 265

attach_function :freenect_stop_video, [:freenect_device], :int

#freenect_update_tilt_stateObject

Updates the accelerometer state using a blocking control message call.

device struct.

Parameters:

  • dev

    Device to get accelerometer data from

Returns:

  • 0 on success, < 0 on error. Accelerometer data stored to



274
# File 'lib/freenect/driver.rb', line 274

attach_function :freenect_update_tilt_state, [:freenect_device], :int