Asked — Edited

Ultra Sonic Sensor Script

Hello,

i need help for a script for the Ultrasonic Sensor.

How i can make a script for diffrent commands on diffent distances?

My exampel Script



:loop

$proxclose = 30

$proxsense = GetPing(D21,D22)

IF($proxsense < $proxclose)

SayEZB("You are to near")

EndIf 

$proxclose = 100

$proxsense = GetPing(D21,D22)

IF($proxsense < $proxclose)

SayEZB("Still to near")

EndIf

Sleep( 2000 ) 

goto(loop)

Has somebody an idea?


ARC Pro

Upgrade to ARC Pro

Discover the limitless potential of robot programming with Synthiam ARC Pro – where innovation and creativity meet seamlessly.

#1  

It looks like you are on the right path. Does it not work for you?

#2  

Hi JustinRatliff,

no,

The EZB only say the last one for "100"

$proxclose = 100

$proxsense = GetPing(D21,D22)

IF($proxsense < $proxclose)

SayEZB("Still to near")

For the "30" it never comes!

How i can make a command "between"?

It must be :

IF($proxsense is between 70 and 100)

but how to write it correct?

Boris

#3  

I can't test this but I think you need to define 2 $proxclose variables. Try this script hopefully more seasoned script writers will jump in and help you out if this doesn't work


:loop

$proxclose = 30
$proxclose2 = 100
$proxsense = GetPing(D21,D22)


IF($proxsense &lt; $proxclose)

SayEZB(&quot;You are to near&quot;)

EndIf 

sleep(2000)

$proxsense = GetPing(D21,D22)

IF($proxsense &gt; $proxclose and $proxsense&lt; $proxclose2)

SayEZB(&quot;Still to near&quot;)

EndIf

Sleep( 2000 ) 

goto(loop)


#4  

@Boris You need to use SayEZBWait on at least the first SayEZB command or the second one will cancel out the first before it has a chance to speak...


:loop

$proxclose = 30

$proxsense = GetPing(D21,D22)

IF($proxsense &lt; $proxclose)

SayEZBWait(&quot;You are to near&quot;) #changed this line
sleep(1000) #put a pause in too

EndIf 

$proxclose = 100

$proxsense = GetPing(D21,D22)

IF($proxsense &lt; $proxclose)

SayEZB(&quot;Still to near&quot;)

EndIf

Sleep( 2000 ) 

goto(loop)

United Kingdom
#5  

My Ping Roam script (which either it's a huge coincidence you chose the same variables I did or you have seen already) should walk you through making adjustments. My notes on Ping Roam should also be a huge help too. Check this topic, I included all of my notes and hand scribbled changes.

Rather than give you the fish I want you to learn to fish. So no code examples here! But you are looking at the IF statement command

IF($x &gt; $y)

And the ElseIf and Else commands.

IF($x = 1)
  Say(&quot;1&quot;)
ElseIF($x = 2)
  Say(&quot;2&quot;)
ElseIF($x = 3)
  Say(&quot;3&quot;)
Else
  Say(&quot;x is not between 1 and 3&quot;)
EndIF

Use different distance values and either the =, < or > for different actions. Use ControlCommand() to start other scripts, controls, autopositions etc.

And for between values, use the AND or the OR operator

if($x &gt; 50 AND $x &lt; 90)