forked from tuuzdu/lua_pioneer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc4d_test.lua
88 lines (73 loc) · 1.63 KB
/
c4d_test.lua
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
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
local clock = os.clock
function sleep(n) -- seconds
local t0 = clock()
while clock() - t0 <= n do end
end
local timeOs = os.time
function time()
t = timeOs()
print("getGlobal: " .. t)
return t
end
function deltaTime()
return 0
end
Ev = {ALTITUDE_REACHED = 61, POINT_REACHED = 21, COPTER_LANDED = 23, MCE_TAKEOFF = 1, MCE_PREFLIGHT = 2, MCE_LANDING = 3}
ap = {}
function ap.push(e)
if e == Ev.MCE_TAKEOFF then
print("TAKEOFF")
elseif e == Ev.MCE_PREFLIGHT then
print("MCE_PREFLIGHT")
elseif e == Ev.POINT_REACHED then
print("POINT_REACHED")
elseif e == Ev.MCE_LANDING then
print("MCE_LANDING")
end
end
function ap.goToLocalPoint(x, y, z)
print('goToLocalPoint: '..x..' '..y..' '..z)
end
Timer = {}
function Timer.callLate(n, func)
local t0 = clock()
while clock() - t0 <= n do end
func()
end
function Timer.callAtGlobal(n, func)
while timeOs() - n <= 0 do end
print('callAtGlobal: '..n)
func()
end
Ledbar = {}
function Ledbar.new(count)
local obj = {leds = count}
Ledbar.__index = Ledbar
print('Ledbar: '.. count)
return setmetatable(obj, Ledbar)
end
function Ledbar:set(i, r, g, b)
print('led_'..i..' : '..r..' '..g..' '..b)
end
return {
dump = dump,
Ev = Ev,
ap = ap,
sleep = sleep,
time = time,
deltaTime = deltaTime,
Timer = Timer,
Ledbar = Ledbar
}