-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.lua
155 lines (131 loc) · 3.27 KB
/
robot.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
-- robot.lua
actors = {
motorLeft,
motorRight,
HeadStepper,
}
sensors = {
ultrasonicSensor,
camera,
batteryVoltage,
batteryCurrent,
batteryCharge,
motorPositionLeft,
motorPositionRight,
motorCurrentLeft,
motorCurrentRight,
}
function vision()
local img = camera.image()
objectDetector(img)
motionDetector(img)
end
function onEvent_BatteryVoltageLow()
end
function onEvent_BatteryVoltageHigh()
end
function onEvent_BatteryChargeLow()
end
function monitor_BatteryCharge()
if requiredChargeForMoveToCharger > batteryCharge then
fireEvent(chargeRangeExeeded)
end
end
function monitor_DistanceToCharger()
requiredChargeForMoveToCharger = distanceToCharger * maximumChargePerMeter * CHARGE_MOVEMENT_UNCERTAINITY
end
function objectDetector(image)
end
function compareImages(img1, img2)
local i1,i2=sameSize(img1, img2)
end
--- get a prixel from image wrapping around
function getPrixelWrap(img,x,y)
while x > img.w do x = x - img.w end -- wrap x from right to left
while x < 0 do x = x + img.w end -- wrap x from left to right
while y > img.h do y = y - img.h end -- wrap y from high to low
while y < 0 do y = y + img.h end -- wrap y from low to high
return img[y][x]
end
--- get a prixel from image wrapping around
function getPrixelClip(img,x,y)
while x > img.w do x = img.w end -- wrap x from right to left
while x < 0 do x = 0 end -- wrap x from left to right
while y > img.h do y = img.h end -- wrap y from high to low
while y < 0 do y = 0 end -- wrap y from low to high
return img[y][x]
end
function diffImage(img1, img2)
local img3={w=img1.w,h=img1.h,}
for y=1,img1.h do
for x=1,img.w do
img3[y]=img3[y] or {}
img3[y][x]=img1[y][x]-img2[y][x]
end
end
return img3
end
--[[
+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | |*|*| | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+
| | | |*| | |*| | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | |*|*| | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+
]]
function diffPattern(img,pat,xo,yo)
local ymax = img.h - pat.h -- maximum vertical area to be computed
local xmax = img.w - pat.w -- maximum horozontal are to be computed
local diffSum = 0
for y = 1, pat.h do
for x = 1, pat.w do
local d = math.abs(pat[y][x]-img[y+yo][x+xo])
diffSum = diffSum + d
end
end
return diffSum
end
function findPattern(img,pat)
-- pattern must be located on image completly
local ymax = img.h - pat.h -- maximum vertical area to be computed
local xmax = img.w - pat.w -- maximum horozontal are to be computed
local c={}
for yo=0,ymax do
for xo=0,xmax do
c[yo][xo]=diffPattern(img,pat,xo,yo)
end
end
end
--[[
objectives
onLowBattery:
destination = nextCharger
motionMode = mostEfficientMotion
travelToDestination
onBatteryFull:
- stopCharging
- exploreEnvironment
exploreEnvironment
explore moving objects
Actor.set(value)
Actor.inputType(boolean, integer(a..b), float(a..b), double(a..b))
Actor.range.min
Actor.range.max
Actor.unit
Actor.off
selfCalibration
turnOffActors()
]]