-
Notifications
You must be signed in to change notification settings - Fork 0
/
showcase.aesl
149 lines (113 loc) · 2.98 KB
/
showcase.aesl
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
<!DOCTYPE aesl-source>
<network>
<!--list of global events-->
<!--node Thymio A0 on lbruegger-puzzle - 31-->
<node name="Thymio A0 on lbruegger-puzzle - 31" nodeId="{9890cba0-a13f-407e-9e3e-641e868413dd}"><![CDATA[
var isBlue = 1
var trailing = 0
var prox_trigger = 0
var prox_max = 4000
var trail_speed = 800
var random_value = 0
var patrolling = 0
var reversing = 0
var patrol_speed = 400
call sound.system(-1)
call leds.top(0, 0, 0)
call leds.bottom.left(0, 0, 0)
call leds.bottom.right(0, 0, 0)
call leds.circle(0, 0, 0, 0, 0, 0, 0, 0)
onevent timer0
if isBlue == 1 then
call leds.top(32,0,0)
isBlue = 0
# call sound.freq(770, 30)
else
call leds.top(0,0,32)
isBlue = 1
# call sound.freq(550, 30)
end
onevent timer1
if reversing == 1 then
reversing = 0
else
patrolling = patrolling + 1
end
onevent prox
trailing = 1
if prox.horizontal[2] > prox_trigger then
motor.left.target = trail_speed
motor.right.target = trail_speed
elseif prox.horizontal[0] > prox_trigger then
motor.left.target = 0
motor.right.target = trail_speed
elseif prox.horizontal[1] > prox_trigger then
motor.left.target = trail_speed / 2
motor.right.target = trail_speed
elseif prox.horizontal[3] > prox_trigger then
motor.left.target = trail_speed / 2
motor.right.target = trail_speed
elseif prox.horizontal[4] > prox_trigger then
motor.left.target = trail_speed
motor.right.target = 0
else
trailing = 0
end
if prox.horizontal[2] > prox_max or prox.horizontal[1] > prox_max or
prox.horizontal[2] > prox_max or prox.horizontal[3] > prox_max or
prox.horizontal[4] > prox_max then
callsub stop
end
if trailing == 1 then
timer.period[0] = 500
patrolling = 0
else
timer.period[0] = 0
call leds.top(16,0,0)
call leds.top(16,0,0)
if patrolling == 0 then
callsub stop
callsub random_turn_length
timer.period[1] = random_value
callsub random_turn_direction
if random_value == 0 then
motor.left.target = patrol_speed
motor.right.target = 0
else
motor.left.target = 0
motor.right.target = patrol_speed
end
patrolling = 1
elseif patrolling == 2 then
callsub stop
motor.left.target = patrol_speed
motor.right.target = patrol_speed
callsub random_patrolling_length
timer.period[1] = random_value
patrolling = 3
elseif patrolling == 4 then
callsub stop
patrolling = 0
end
end
if prox.ground.reflected[0] < 200 or prox.ground.reflected[1] < 200 then
reversing = 1
callsub reverse
end
sub random_patrolling_length
call math.rand(random_value)
random_value = (abs(random_value) % 12)*500 + 1000
sub random_turn_length
call math.rand(random_value)
random_value = (abs(random_value) % 6)*500 + 1000
sub random_turn_direction
call math.rand(random_value)
random_value = abs(random_value) % 2
sub stop
motor.left.target = 0
motor.right.target = 0
sub reverse
motor.left.target = -patrol_speed
motor.right.target = -patrol_speed
]]></node>
</network>