Asked — Edited

Script Help Needed

I am having a little bit of trouble with this script. Everything works until I get to the "if" statement at the left and right sensor. So what it is supposed to do is not allow movement if tracks are disabled which upon startup they are. Once track motors are enabled and the command robot turn left is given the head is to turn left and down, again which it does. But then it never gets to the send serial commands. There is something missing, endif, elseif, end repeat? BTW I troubleshot by commenting out lines of code until figuring out where the problem began. I appreciate the help. Also how do I use code tags on this website?


if($movement = "false")
print("movement prohibited")
SayEzb("my track motors are disabled")
Else 
print("moving")

ControlCommand("Script Manager ", ScriptStart, "Head_Left")
ControlCommand("Script Manager ", ScriptStart, "Head Down")
sleep(500)

if ($leftsensor <60)And ($rightsensor <60)
sleep(500)
SendSerial(D0,38400,1)
SendSerial(D0,38400,255)
Sleep(5000)
SendSerial(D0,38400,0)
ElseIf 
SendSerial(D0,38400,0) 
SayEZB("i have detected something in my path") 
EndIf


ARC Pro

Upgrade to ARC Pro

ARC Pro will give you immediate updates and new features needed to unleash your robot's potential!

PRO
Synthiam
#1  

ARC is giving you a clear error when attempting to format the code..

User-inserted image

*HINT: Count the ENDIF's

#3  

Yes I get the error but Im not sure where to put the end if's. Im sure I am overthinking this as usual. Thanks again!

#4  

if you meant for the ELSE clause to really contain the IF clause, put another ENDIF at the end of the program

If you really meant for the ELSE clause to end before the next IF, put the ENDIF there

Hint, indents will help you see the nesting

#5  

I'm still missing something here....

if($movement = "false") print("movement prohibited") SayEzb("my track motors are disabled") Else print("moving")

ControlCommand("Script Manager ", ScriptStart, "Head_Left") ControlCommand("Script Manager ", ScriptStart, "Head Down") sleep(1500)

$leftsensor = getadc(adc5) $topsensor = getadc(adc7) $rightsensor = getadc(adc6)

if ($leftsensor <60)And ($rightsensor <60) sleep(2500) SendSerial(D0,38400,1) SendSerial(D0,38400,255) Sleep(5000) SendSerial(D0,38400,0) Elseif ($leftsensor >60 And ($rightsensor >60) SendSerial(D0,38400,0)
SayEZB("i have detected something in my path") EndIf

The way I am reading this code is IF the left sensor and the right sensor are less than 60 wait 2.5 seconds and start the serial commands for 5 seconds and then stop. Otherwise if the sensors are greater than 60 immediately send serial stop command and say I have detected something in my path.

endif.?

Still don't know where to put the end if's?

#6  

Try this;


if($movement = &quot;false&quot;)
print(&quot;movement prohibited&quot;)
SayEzb(&quot;my track motors are disabled&quot;)
Else 
print(&quot;moving&quot;)
#I think you need an Endif here
Endif
ControlCommand(&quot;Script Manager &quot;, ScriptStart, &quot;Head_Left&quot;)
ControlCommand(&quot;Script Manager &quot;, ScriptStart, &quot;Head Down&quot;)
sleep(500)

if ($leftsensor &lt;60)And ($rightsensor &lt;60)
sleep(500)
SendSerial(D0,38400,1)
SendSerial(D0,38400,255)
Sleep(5000)
SendSerial(D0,38400,0)
ElseIf 
SendSerial(D0,38400,0) 
SayEZB(&quot;i have detected something in my path&quot;) 
EndIf

You need to have an Endif for every If statement

#7  

@bhouston

Shouldn't that ELSEIF be an ELSE ?

#8  

Thank you very much. Makes sense now! Now I can build upon this. I didn't realize the problem was so far up in the code. Thanks again!

                                Chris