aseba icon indicating copy to clipboard operation
aseba copied to clipboard

Program Thymio II with buttons and an array (delay-problem?)

Open budumlu opened this issue 7 years ago • 2 comments

I try to setup the Thymio so that the kids can "program" the Thymio with the arrow buttons and start there programm onevent button.center. Input example:

< ^ v ^ o

But the Thymio is just executing the last input, no matter hier I make use of the timer...

But my array doesn't work as expected. The robot should drive one command after the other, instead of just executing the last command in the array.

How do I have to fix it?

var go[5] = [0,0,0,0,0]
var j = 0
var i
var i2 = 0
var richtung
# stop timer 0
# timer.period[0] = 0
# reset outputs
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 button.center
	when button.center == 1 do
		while i < 5 do
			if go[i] == 0 then
				call leds.circle(32,0,0,0,0,0,0,0)
				motor.left.target = 300
				motor.right.target = 300
			elseif go[i] == 1 then
				call leds.circle(0,0,32,0,0,0,0,0)
				motor.left.target = 300
				motor.right.target = 0
			elseif go[i] == 2 then
				call leds.circle(0,0,0,0,32,0,0,0)
				motor.left.target = -300
				motor.right.target = -300
				#timer.period[0] = 1000
			elseif go[i] == 3 then
				call leds.circle(0,0,0,0,0,0,32,0)
				motor.left.target = 0
				motor.right.target = 300
				
			end
			
			i = i + 1
		end
		#emit pair_run 5
	end


onevent button.forward
	when button.forward == 1 do
		richtung = 0
		go[i2] = 0
		i2 = i2 + 1
		#emit pair_run 0
	end


onevent button.right
	when button.right == 1 do
		richtung = 1
		go[i2] = richtung
		i2 = i2 + 1
	end


onevent button.left
	when button.left == 1 do
		richtung = 3
		go[i2] = richtung
		i2 = i2 + 1
		#emit pair_run 2
	end


onevent button.backward
	when button.backward == 1 do
		richtung = 2
		go[i2] = richtung
		i2 = i2 + 1
		#emit pair_run 3
	end

onevent timer0
	timer.period[0] = 0
	motor.left.target = 0
	motor.right.target = 0
	call leds.bottom.left(32,0,0)
	call leds.bottom.right(32,0,0)

budumlu avatar Sep 22 '18 17:09 budumlu

Hi Torsten,

Do your Thymios have the dequeue native function library? It was designed to make it easy to build queues of actions to be executed sequentially.

davidjsherman avatar Sep 27 '18 10:09 davidjsherman

Oooh, I think that's what I`m searching for...it was hard to find in the documentation...https://www.thymio.org/en:asebastdnativedeque Thanks!

But I can hardly figure out, how I could make use of it properly...could you please give me more hints, how to handle my problem with deqeue? And how can I know, wether my Thymios have the dequeuelibrary or not?

budumlu avatar Sep 27 '18 19:09 budumlu