Thymio Sushi-Bar
Thymio Sushi-Bar
par Mobsya
Fait avec 5+ Thymio
Mots-clés:
Utile
Robotique et algorithmes
Projets avec plusieurs Thymio
Découvrez notre Sushi-bar Thymio.
Créé pour le Vernissage de l'exposition Pop Art, mon Amour de la Maison d'Ailleurs au Théâtre Benno Besson !
Une vraie flotte automatisée de robots pour vous servir !
Solution
<!DOCTYPE aesl-source>
<network>
<!--list of global events-->
<!--list of constants-->
<constant value="0" name="STATE_BLACK"/>
<constant value="1" name="STATE_WHITE"/>
<constant value="-1" name="DIR_LEFT"/>
<constant value="-2" name="DIR_L_LEFT"/>
<constant value="1" name="DIR_RIGHT"/>
<constant value="2" name="DIR_L_RIGHT"/>
<constant value="10" name="DIR_LOST"/>
<constant value="0" name="DIR_FRONT"/>
<constant value="300" name="SPEED_LINE"/>
<!--show keywords state-->
<keywords flag="true"/>
<!--node thymio-II-->
<node nodeId="1" name="thymio-II">var black_level = 200
var white_level = 400
var led_pulse
var temp
var s[2]
var dir
var speed = SPEED_LINE
var run =0
var block=0
var leds_rainbow[160]
var j
var led_i
var r
var g
var b
var run_rainbow
var sound_activate = 1
call _system.settings.write(0,0)
motor.left.target = 0
motor.right.target = 0
timer.period[0] = 0
call math.fill(leds_rainbow,0)
for j in 0:52 do
leds_rainbow[j] = j*2
end
for j in 53:105 do
leds_rainbow[j] = 53*2 - (j - 53) * 2
end
onevent rc5
if rc5.command == 53 then #GO
run=1
dir = DIR_FRONT
timer.period[0] = 25
elseif rc5.command == 87 then #STOP
run=0
motor.left.target = 0
motor.right.target = 0
timer.period[0] = 0
timer.period[1] = 0
r = 0
g = 0
b = 0
call leds.top(r,g,b)
call leds.bottom.left(b,r,g)
call leds.bottom.right(g,b,r)
call leds.circle(0,0,0,0,0,0,0,0)
elseif rc5.command == 16 then #Sound activate
sound_activate = 1
elseif rc5.command == 17 then #Sound deactivate
sound_activate = 0
end
onevent buttons
when button.center==1 do
if run==0 then
run=1
dir = DIR_FRONT
timer.period[0] = 25
else
run=0
motor.left.target = 0
motor.right.target = 0
timer.period[0] = 0
timer.period[1] = 0
end
end
if button.backward==1 and button.forward==1 then
black_level = (prox.ground.delta[0] + prox.ground.delta[1]) / 2
black_level = black_level+150
end
if button.left==1 and button.right==1 then
white_level = (prox.ground.delta[0] + prox.ground.delta[1]) / 2
if(white_level < 150) then
white_level = 200
end
white_level = white_level-150
end
onevent timer0
led_i = (led_i + 2) % 160
r = (led_i) % 160
r = leds_rainbow[r] / 4
g = (led_i+ 53) % 160
g = leds_rainbow[g] / 4
b = (led_i + 106) % 160
b = leds_rainbow[b] / 4
call leds.top(r,g,b)
call leds.bottom.left(b,r,g)
call leds.bottom.right(g,b,r)
onevent timer1
block++
if block>2 then
if sound_activate == 1 then
call sound.system(4)
end
call leds.top(31,0,0)
call leds.bottom.left(31,0,0)
call leds.bottom.right(31,0,0)
timer.period[0] = 0
end
onevent prox
if run==1 then
#Line Follower
if prox.ground.delta[0] < black_level then
s[0] = STATE_BLACK
end
if prox.ground.delta[0] > white_level then
s[0] = STATE_WHITE
end
if prox.ground.delta[1] < black_level then
s[1] = STATE_BLACK
end
if prox.ground.delta[1] > white_level then
s[1] = STATE_WHITE
end
if s[0] == STATE_BLACK and s[1] == STATE_BLACK then
# Black line right under us
dir = DIR_FRONT
elseif s[0] == STATE_WHITE and s[1] == STATE_BLACK then
dir = DIR_RIGHT
elseif s[1] == STATE_WHITE and s[0] == STATE_BLACK then
dir = DIR_LEFT
else
# Lost
if dir > 0 then
dir = DIR_L_RIGHT
elseif dir < 0 then
dir = DIR_L_LEFT
else
dir = DIR_LOST
end
end
#Obstacle Stop
if prox.horizontal[0] >2000 or prox.horizontal[1]>2000 or prox.horizontal[2]>2000 or prox.horizontal[3]>2000 or prox.horizontal[4]>2000 then
speed= 0 #stop
when timer.period[1]==1000 do
block=0
end
timer.period[1]=1000
elseif prox.horizontal[0] >800 or prox.horizontal[1]>800 or prox.horizontal[2]>800 or prox.horizontal[3]>800 or prox.horizontal[4]>800 then
speed= SPEED_LINE/2 #sloweer
else
speed= SPEED_LINE
timer.period[1]=0
timer.period[0] = 25#activate rainbow
end
if dir == DIR_FRONT then
motor.left.target = speed
motor.right.target = speed
call leds.circle(32,0,0,0,32,0,0,0)
elseif dir == DIR_RIGHT then
motor.left.target = speed
motor.right.target = 0
call leds.circle(0,32,0,32,0,0,0,0)
elseif dir == DIR_LEFT then
motor.left.target = 0
motor.right.target = speed
call leds.circle(0,0,0,0,0,32,0,32)
elseif dir == DIR_L_LEFT then
motor.left.target = -speed
motor.right.target = speed
call leds.circle(0,0,0,0,0,0,32,0)
elseif dir == DIR_L_RIGHT then
motor.left.target = speed
motor.right.target = -speed
call leds.circle(0,0,32,0,0,0,0,0)
elseif dir == DIR_LOST then
motor.left.target = speed
motor.right.target = -speed
end
end</node>
</network>
Télécharger le code
Lien vers plus d'infos
*
Commentez cette création !