-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathtilt-kinect.cpp.txt
66 lines (54 loc) · 1.48 KB
/
tilt-kinect.cpp.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// main.cpp
// tiltkinect
//
// Created by MINGFENWANG on 2017/6/15.
// Copyright © 2017年 MINGFENWANG. All rights reserved.
//
//#include "libfreenect.h"
#include "libfreenect.h"
#include <iostream>
#include <fstream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Please enter the tilt angle: ";
float tilt;
std::cin >> tilt;
std::cout << "Working..." << std::endl;
// Initialize libfreenect.
freenect_context* fn_ctx;
int ret = freenect_init(&fn_ctx, NULL);
if (ret < 0)
return ret;
// Use motor only.
freenect_select_subdevices(fn_ctx, FREENECT_DEVICE_MOTOR);
// Find out how many devices are connected.
int num_devices = ret = freenect_num_devices(fn_ctx);
if (ret < 0)
return ret;
if (num_devices == 0)
{
printf("No device found!\n");
freenect_shutdown(fn_ctx);
return 1;
}
// Open the first device.
freenect_device* fn_dev;
ret = freenect_open_device(fn_ctx, &fn_dev, 0);
if (ret < 0)
{
freenect_shutdown(fn_ctx);
return ret;
}
// Set the tilt angle
freenect_set_tilt_degs(fn_dev, tilt);
// Set the led light to green status
freenect_set_led(fn_dev, LED_GREEN);
freenect_close_device(fn_dev);
freenect_shutdown(fn_ctx);
std::ofstream wf("tilt-angle.txt");
wf << tilt << std::endl;
wf.close();
std::cout << "Done." << std::endl;
return 0;
}