forked from andrew/drone-xbox-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drone-xbox.coffee
137 lines (103 loc) · 3.21 KB
/
drone-xbox.coffee
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
XboxController = require "xbox-controller"
arDrone = require 'ar-drone'
xbox = new XboxController
options = {ip: '192.168.1.1'}
client = arDrone.createClient(options)
client.config('control:outdoor', 'FALSE')
client.config('control:flight_without_shell', 'TRUE')
#in millimeters
client.config('control:altitude_max', 30000)
client.config('control:altitude_min', 3000)
#set to record to usb
client.config('video:video_on_usb', 'TRUE')
yaw = 3.05
euler = 0.26
vz = 1000
setSpeed = (delta) ->
yaw = yaw + delta
yaw = 6.11 if yaw > 6.11
yaw = 0.7 if yaw < 0.7
delta = delta / 10.7 #make the increase smaller for euler
euler = euler + delta
euler = 0.52 if euler > 0.52
euler = 0.1 if euler < 0.1
delta = delta * 10.7 * 100 #make the increase larger for vz
vz = vz + delta
vz = 2000 if vz > 2000
vz = 200 if vz < 200
console.log("Setting yaw: " + yaw + " - euler: " + euler + " - vz: " + vz)
#change to set rotation speed - 0.7 to 6.11
client.config('control:control_yaw', yaw)
#change to set tilt (left, right, front, back)
#0 to 0.52 is max
client.config('control:euler_angle_max', euler)
#speed to go up and down 200 to 2000
client.config('control:control_vz_max', vz)
setSpeed(0)
maxAngle = 32768
#change from 1 to -1 to change controller directions
invert = -1
client.on "batteryChange", (battery) ->
if battery > 75
xbox.setLed(0x09)
else if battery > 50
xbox.setLed(0x08)
else if battery > 25
xbox.setLed(0x07)
else if battery > 15
xbox.setLed(0x06)
client.on "lowBattery", (battery) ->
xbox.setLed(0x01)
xbox.on "start:press", (key) ->
console.log "start press (takeoff or land)"
if client._lastState == 'CTRL_LANDED'
client.takeoff()
else
client.land()
xbox.on "xboxbutton:press", (key) ->
console.log "xboxbutton press (reset)"
client.disableEmergency()
xbox.on "leftshoulder:press", (key) ->
console.log "leftshoulder - decreasing speed"
setSpeed(-1)
xbox.on "rightshoulder:press", (key) ->
console.log "rightshoulder - increasing speed"
setSpeed(1)
xbox.on "left:move", (position) ->
x = parseFloat(position.x / maxAngle)
y = parseFloat(position.y / maxAngle)
console.log "left:move", {x: x, y: y}
client.stop() if x == 0 && y == 0
if x != 0
client.right(x)
if y != 0
client.front(invert * y)
xbox.on "right:move", (position) ->
x = parseFloat(position.x / maxAngle)
y = parseFloat(position.y / maxAngle)
console.log "right:move", {x: x, y: y}
if x != 0
client.clockwise(x)
if y != 0
client.up(invert * y)
xbox.on "dup:press", (key) ->
console.log('D up (flip front)')
client.animate('flipAhead', 1500);
xbox.on "ddown:press", (key) ->
console.log('D down (flip back)')
client.animate('flipBehind', 1500);
xbox.on "dleft:press", (key) ->
console.log('D left (flip left)')
client.animate('flipLeft', 1500);
xbox.on "dright:press", (key) ->
console.log('D right (flip right)')
client.animate('flipRight', 1500);
xbox.on "x:press", (key) ->
client.animateLeds('fire', 5, 2)
xbox.on "y:press", (key) ->
client.animateLeds('blinkStandard', 5, 2)
xbox.on "rightstick:press", (key) ->
console.log 'rightstick press'
client.animate('turnaround', 5000);
xbox.on "a:press", (key) ->
console.log('a')