CGR Localization
 All Classes Namespaces Files Functions Variables Macros Pages
motors.c
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  * This code is licensed to you under the terms of the Apache License, version
8  * 2.0, or, at your option, the terms of the GNU General Public License,
9  * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
10  * or the following URLs:
11  * http://www.apache.org/licenses/LICENSE-2.0
12  * http://www.gnu.org/licenses/gpl-2.0.txt
13  *
14  * If you redistribute this file in source form, modified or unmodified, you
15  * may:
16  * 1) Leave this header intact and distribute it under the same terms,
17  * accompanying it with the APACHE20 and GPL20 files, or
18  * 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
19  * 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
20  * In all cases you must keep the copyright notice intact and include a copy
21  * of the CONTRIB file.
22  *
23  * Binary distributions must follow the binary distribution requirements of
24  * either License.
25  */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <math.h>
32 
33 #include "freenect_internal.h"
34 // The kinect can tilt from +31 to -31 degrees in what looks like 1 degree increments
35 // The control input looks like 2*desired_degrees
36 const double MAX_TILT_ANGLE = 31;
37 const double MIN_TILT_ANGLE = -31;
38 
39 
40 int freenect_set_tilt_in_degrees(freenect_device *dev, double angle)
41 {
42  int ret;
43  uint8_t empty[0x1];
44  angle = (((angle<MIN_TILT_ANGLE)?MIN_TILT_ANGLE:angle)>MAX_TILT_ANGLE)?MAX_TILT_ANGLE:((angle<MIN_TILT_ANGLE)?MIN_TILT_ANGLE:angle);
45  angle = angle * 2;
46  ret = fnusb_control(&dev->usb_motor, 0x40, 0x31, (uint16_t)angle, 0x0, empty, 0x0);
47  return ret;
48 
49 }
50 
51 int freenect_set_tilt_in_radians(freenect_device *dev, double angle)
52 {
53  int ret;
54  angle = angle/M_PI*180;
55  ret = freenect_set_tilt_in_degrees(dev,angle);
56  return ret;
57 
58 }
59 
60 int freenect_set_led(freenect_device *dev, freenect_led_options option)
61 {
62  int ret;
63  uint8_t empty[0x1];
64  ret = fnusb_control(&dev->usb_motor, 0x40, 0x06, (uint16_t)option, 0x0, empty, 0x0);
65  return ret;
66 
67 }
68 
69