<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Loop or logic blocks in Events</title>
		<link>http://aseba.wikidot.com/forum/t-3240749/loop-or-logic-blocks-in-events</link>
		<description>Posts in the discussion thread &quot;Loop or logic blocks in Events&quot; - Is it possible to put a Loop or a logic block in an Event?</description>
				<copyright></copyright>
		<lastBuildDate>Sat, 08 Aug 2026 04:46:59 +0000</lastBuildDate>
		
					<item>
				<guid>http://aseba.wikidot.com/forum/t-3240749#post-3582337</guid>
				<title>Re: Loop or logic blocks in Events</title>
				<link>http://aseba.wikidot.com/forum/t-3240749/loop-or-logic-blocks-in-events#post-3582337</link>
				<description></description>
				<pubDate>Thu, 31 Aug 2017 13:26:21 +0000</pubDate>
				<wikidot:authorName>riedo</wikidot:authorName>				<wikidot:authorUserId>875981</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hi!</p> <p>I think your main problem is with the usage of the timers. Once a timer is set, for example at a period of 800&#160;ms, the timer event will keep happening every 800&#160;ms. thus once the 2 timers are set in your program, it becomes very confusing.</p> <p>I suggest you think in terms of what we call a state machine. This means that you should think about the behaviour your robot could have, and the conditions for your robot to switch from one behaviour to the other.</p> <p>Just to give you an idea, here is what I came up with:<br /> (I had programmed in blockly at first but because blockly uses <em>when</em> for the conditions on proximity sensors it did not work as I had intended, so I switched to text mode and replaced <em>when</em> with <em>if</em>)</p> <div class="code"> <pre><code>var compteur[1] var state[1] var checking[1] timer.period[0] = 1 state[0] = 0 checking[0] = 1 compteur[0] = 0 motor.left.target = 100 motor.right.target = 100 onevent prox if prox.horizontal[2] &gt; 2000 then if checking[0] == 1 and state[0] == 0 then motor.left.target = -300 motor.right.target = 300 compteur[0] = 800 state[0] = 1 checking[0] = 0 elseif checking[0] == 1 and state[0] == 1 then motor.left.target = 300 motor.right.target = -300 compteur[0] = 1300 state[0] = 2 checking[0] = 0 end end if prox.horizontal[2] &lt; 1000 then if checking[0] == 1 then motor.left.target = 100 motor.right.target = 100 compteur[0] = 0 state[0] = 0 checking[0] = 1 end end onevent timer0 if compteur[0] &gt; 0 then compteur[0] = compteur[0] - 1 elseif compteur[0] == 0 then checking[0] = 1 end</code></pre></div> <p>As you can see I used variables to remember what I am doing. basically I setup a timer that runs continuously, then if I need to measure a certain amount of time I use a <strong>counter</strong> variable that is decremented. Then the <strong>state</strong> variable says if I'm going forward, turning left or turning right. Finally the <strong>checking</strong> variable informs me if I should check the sensors or not (while I'm turning 90°, I don't want the change on the sensors to affect me until I'm done turning. I could also use the counter value to check that, as when counter &gt;0 it means I'm turning)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://aseba.wikidot.com/forum/t-3240749#post-3568272</guid>
				<title>Loop or logic blocks in Events</title>
				<link>http://aseba.wikidot.com/forum/t-3240749/loop-or-logic-blocks-in-events#post-3568272</link>
				<description></description>
				<pubDate>Thu, 10 Aug 2017 12:21:28 +0000</pubDate>
				<wikidot:authorName>Marvin H</wikidot:authorName>				<wikidot:authorUserId>3286865</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I want to programm the Thymio, so he can find his way thru a Labyrinth (there are no dead ends in the labyrinth). But i'm trying to increase the Programm by kind of telling Thymio, from which way he came from.</p> <p>So if there is a wall in front of him, he turns 90-degree to the right. If there is still a wall in front of him, he's turning 180-degree to left (or right) and move forward. If there is no wall after a his first 90-degree turn, then he moves forwards.</p> <p>So there is no chance of going in the direction he came from.</p> <p>My code from the Blockly looks like this:</p> <p>onevent button.forward<br /> when button.forward == 1 do<br /> call leds.top(6,32,6)<br /> motor.left.target = 100<br /> motor.right.target = 100<br /> end</p> <p>onevent prox<br /> when prox.horizontal[2] &gt; 2000 do<br /> call leds.top(32,0,0)<br /> timer.period[0] = 800<br /> motor.left.target = 300<br /> motor.right.target = -300<br /> end</p> <p>onevent timer0<br /> call leds.top(26,6,26)<br /> if (prox.horizontal[2] &gt; 2000 or prox.horizontal[3] &gt; 2000) or prox.horizontal[1] &gt; 2000 then<br /> timer.period[1] = 1300<br /> motor.left.target = -300<br /> motor.right.target = 300<br /> else<br /> motor.left.target = 100<br /> motor.right.target = 100<br /> end</p> <p>onevent timer1<br /> call leds.top(32,19,0)<br /> motor.left.target = 100<br /> motor.right.target = 100</p> <p>Can anyone help me please?</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>