<!DOCTYPE aesl-source>
<network>


<!--list of global events-->
<event size="2" name="ObstacleDetected"/>
<event size="0" name="FreeOfObstacle"/>
<event size="0" name="Start"/>
<event size="0" name="Stop"/>


<!--list of constants-->


<!--source code of node left motor-->
<node name="left motor">var isRunning = 1
speed = 300

onevent Start
isRunning = 1
speed = 300

onevent Stop
isRunning = 0
speed = 0

onevent ObstacleDetected
if isRunning == 1 then
	speed = 300 + (args[0] + args[1]) * 4
end

onevent FreeOfObstacle
if isRunning == 1 then
	speed = 300
end
</node>


<!--source code of node right motor-->
<node name="right motor">var isRunning = 1
speed = 300

onevent Start
isRunning = 1
speed = 300

onevent Stop
isRunning = 0
speed = 0

onevent ObstacleDetected
if isRunning == 1 then
	speed = 300 + (args[0] - args[1]) * 4
end

onevent FreeOfObstacle
if isRunning == 1 then
	speed = 300
end</node>


<!--source code of node proximity sensors-->
<node name="proximity sensors"># angles = pi/48:pi/12:(47*2*pi)/48
# vectorX = round(-cos(angles)*255)
# vectorY = round(-sin(angles)*255)

# vector field obstacle avoidance
var vectorX[24] = -254, -241, -212, -168, -113,  -50, 17, 82, 142, 192, 229, 250, 254, 241, 212,  168, 113, 50, -17, -82, -142, -192, -229, -250
var vectorY[24] = -17, -82, -142, -192, -229, -250, -254, -241, -212, -168, -113, -50, 17, 82  , 142, 192, 229, 250, 254, 241, 212, 168, 113, 50
var threshold = 100
var eventBuffer[2]

var activation

onevent timer

call math.dot(eventBuffer[0], bumpers, vectorX, 11)
call math.dot(eventBuffer[1], bumpers, vectorY, 11)
call math.dot(activation, eventBuffer, eventBuffer, 0)

if activation > threshold then
	emit ObstacleDetected eventBuffer
end
when activation &lt;= threshold do
	emit FreeOfObstacle
end
	</node>


<!--source code of node distance sensors-->
<node name="distance sensors"></node>


</network>
