|
31 | 31 | #include <math.h>
|
32 | 32 |
|
33 | 33 | #include "freenect_internal.h"
|
| 34 | + |
| 35 | +// The kinect can tilt from +31 to -31 degrees in what looks like 1 degree increments |
| 36 | +// The control input looks like 2*desired_degrees |
| 37 | +#define MAX_TILT_ANGLE 31 |
| 38 | +#define MIN_TILT_ANGLE (-31) |
| 39 | + |
34 | 40 | #define GRAVITY 9.80665
|
35 | 41 |
|
36 |
| -int freenect_get_raw_accelerometers(freenect_device *dev, int16_t* x, int16_t* y, int16_t* z) |
| 42 | +int freenect_set_tilt_degs(freenect_device *dev, double angle) |
| 43 | +{ |
| 44 | + int ret; |
| 45 | + uint8_t empty[0x1]; |
| 46 | + |
| 47 | + angle = (angle<MIN_TILT_ANGLE) ? MIN_TILT_ANGLE : ((angle>MAX_TILT_ANGLE) ? MAX_TILT_ANGLE : angle); |
| 48 | + angle = angle * 2; |
| 49 | + |
| 50 | + ret = fnusb_control(&dev->usb_motor, 0x40, 0x31, (uint16_t)angle, 0x0, empty, 0x0); |
| 51 | + return ret; |
| 52 | +} |
| 53 | + |
| 54 | +int freenect_set_led(freenect_device *dev, freenect_led_options option) |
37 | 55 | {
|
38 |
| - unsigned char buf[10]; |
| 56 | + int ret; |
| 57 | + uint8_t empty[0x1]; |
| 58 | + ret = fnusb_control(&dev->usb_motor, 0x40, 0x06, (uint16_t)option, 0x0, empty, 0x0); |
| 59 | + return ret; |
| 60 | +} |
| 61 | + |
| 62 | +int freenect_get_raw_accel(freenect_device *dev, int16_t* x, int16_t* y, int16_t* z) |
| 63 | +{ |
| 64 | + uint8_t buf[10]; |
39 | 65 | uint16_t ux, uy, uz;
|
40 | 66 | int ret = fnusb_control(&dev->usb_motor, 0xC0, 0x32, 0x0, 0x0, buf, 10);
|
41 | 67 | if (ret != 10)
|
42 | 68 | printf("Error in accelerometer reading, libusb_control_transfer returned %d\n", ret);
|
43 |
| - |
| 69 | + |
44 | 70 | ux = ((uint16_t)buf[2] << 8) | buf[3];
|
45 | 71 | uy = ((uint16_t)buf[4] << 8) | buf[5];
|
46 | 72 | uz = ((uint16_t)buf[6] << 8) | buf[7];
|
47 | 73 | *x = (int16_t)ux;
|
48 | 74 | *y = (int16_t)uy;
|
49 | 75 | *z = (int16_t)uz;
|
50 |
| - |
| 76 | + |
51 | 77 | return ret;
|
52 | 78 | }
|
53 | 79 |
|
54 |
| -int freenect_get_mks_accelerometers(freenect_device *dev, double* x, double* y, double* z) |
| 80 | +int freenect_get_mks_accel(freenect_device *dev, double* x, double* y, double* z) |
55 | 81 | {
|
56 | 82 | //the documentation for the accelerometer (http://www.kionix.com/Product%20Sheets/KXSD9%20Product%20Brief.pdf)
|
57 | 83 | //states there are 819 counts/g
|
58 | 84 | int16_t ix, iy, iz;
|
59 |
| - int ret = freenect_get_raw_accelerometers(dev,&ix,&iy,&iz); |
| 85 | + int ret = freenect_get_raw_accel(dev,&ix,&iy,&iz); |
60 | 86 |
|
61 | 87 | *x = (double)ix/FREENECT_COUNTS_PER_G*GRAVITY;
|
62 | 88 | *y = (double)iy/FREENECT_COUNTS_PER_G*GRAVITY;
|
63 | 89 | *z = (double)iz/FREENECT_COUNTS_PER_G*GRAVITY;
|
64 | 90 |
|
65 | 91 | return ret;
|
66 | 92 | }
|
67 |
| - |
68 |
| - |
|
0 commit comments