SHARE
TWEET

Untitled

a guest Jun 22nd, 2012 290 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * This file is part of the OpenKinect Project. http://www.openkinect.org
  3.  *
  4.  * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
  5.  * for details.
  6.  *
  7.  * Andrew Miller <amiller@dappervision.com>
  8.  *
  9.  * This code is licensed to you under the terms of the Apache License, version
  10.  * 2.0, or, at your option, the terms of the GNU General Public License,
  11.  * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
  12.  * or the following URLs:
  13.  * http://www.apache.org/licenses/LICENSE-2.0
  14.  * http://www.gnu.org/licenses/gpl-2.0.txt
  15.  *
  16.  * If you redistribute this file in source form, modified or unmodified, you
  17.  * may:
  18.  *   1) Leave this header intact and distribute it under the same terms,
  19.  *      accompanying it with the APACHE20 and GPL20 files, or
  20.  *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
  21.  *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file
  22.  * In all cases you must keep the copyright notice intact and include a copy
  23.  * of the CONTRIB file.
  24.  *
  25.  * Binary distributions must follow the binary distribution requirements of
  26.  * either License.
  27.  */
  28.  
  29. #include "libfreenect.h"
  30. #include "libfreenect_sync.h"
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <time.h>
  34.  
  35. #ifndef _WIN32
  36.   #include <unistd.h>
  37. #else
  38.   // Microsoft Visual C++ does not provide the <unistd.h> header, but most of
  39.   // its contents can be found within the <stdint.h> header:
  40.   #include <stdint.h>
  41.   // except for the UNIX sleep() function that has to be emulated:
  42.   #include <windows.h>
  43.   // http://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html
  44.   // According to the link above, the semantics of UNIX sleep() is as follows:
  45.   // "If sleep() returns because the requested time has elapsed, the value
  46.   //  returned shall be 0. If sleep() returns due to delivery of a signal, the
  47.   //  return value shall be the "unslept" amount (the requested time minus the
  48.   //  time actually slept) in seconds."
  49.   // The following function does not implement the return semantics, but
  50.   // will do for now... A proper implementation would require Performance
  51.   // Counters before and after the forward call to the Windows Sleep()...
  52.   unsigned sleep(unsigned seconds)
  53.   {
  54.     Sleep(seconds*1000);  // The Windows Sleep operates on milliseconds
  55.     return(0);
  56.   }
  57.   // Note for MinGW-gcc users: MinGW-gcc also does not provide the UNIX sleep()
  58.   // function within <unistd.h>, but it does provide usleep(); trivial wrapping
  59.   // of sleep() aroung usleep() is possible, however the usleep() documentation
  60.   // (http://docs.hp.com/en/B2355-90682/usleep.2.html) clearly states that:
  61.   // "The useconds argument must be less than 1,000,000. (...)
  62.   //  (...) The usleep() function may fail if:
  63.   //  [EINVAL]
  64.   //     The time interval specified 1,000,000 or more microseconds."
  65.   // which means that something like below can be potentially dangerous:
  66.   // unsigned sleep(unsigned seconds)
  67.   // {
  68.   //   usleep(seconds*1000000);  // The usleep operates on microseconds
  69.   //   return(0);
  70.   // }
  71.   // So, it is strongly advised to stick with the _WIN32/_MSC_VER
  72.   // http://www.xinotes.org/notes/note/439/
  73. #endif//_WIN32
  74.  
  75.  
  76.  
  77. /* This is a simple demo. It connects to the kinect and plays with the motor,
  78.    the accelerometers, and the LED. It doesn't do anything with images. And,
  79.    unlike the other examples, no OpenGL is required!
  80.  
  81.    So, this should serve as the reference example for working with the motor,
  82.    accelerometers, and LEDs.   */
  83.  
  84. void no_kinect_quit(void)
  85. {
  86.         printf("Error: Kinect not connected?\n");
  87.         exit(1);
  88. }
  89.  
  90. int main(int argc, char *argv[])
  91. {
  92.         srand(time(0));
  93.         char *data = 0;
  94.         short *depth = 0;
  95.         uint32_t ts;
  96.  
  97.         while (1) {
  98.                 // Pick a random tilt and a random LED state
  99.                 freenect_led_options led = (freenect_led_options) (rand() % 6); // explicit cast
  100.                 int tilt = (rand() % 30)-15;
  101.                 freenect_raw_tilt_state *state = 0;
  102.                 double dx, dy, dz;
  103.  
  104.                 // Set the LEDs to one of the possible states
  105.                 if (freenect_sync_set_led(led, 0)) no_kinect_quit();
  106.  
  107.                 // Set the tilt angle (in degrees)
  108.                 if (freenect_sync_set_tilt_degs(tilt, 0)) no_kinect_quit();
  109.  
  110.                 // Get the raw accelerometer values and tilt data
  111.                 if (freenect_sync_get_tilt_state(&state, 0)) no_kinect_quit();
  112.  
  113.                 // Get the processed accelerometer values (calibrated to gravity)
  114.                 freenect_get_mks_accel(state, &dx, &dy, &dz);
  115.  
  116.                 printf("led[%d] tilt[%d] accel[%lf,%lf,%lf]\n", led, tilt, dx,dy,dz);
  117.  
  118.                 printf("try and get the camera data\n");
  119.                 if( freenect_sync_get_video( (void**)&data, &ts, 0, FREENECT_VIDEO_RGB ) != 0 )
  120.                         return 1;
  121.                 else
  122.                         printf("got the camera data\n");
  123.  
  124.                 if( freenect_sync_get_depth( (void**)&depth, &ts, 0, FREENECT_DEPTH_11BIT ) != 0 )
  125.                         return 2;
  126.                 else
  127.                         printf("got the depth data\n" );
  128.  
  129.                 sleep(3);
  130.         }
  131. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top