
kamaroman68
USA
Asked
— Edited
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 is giving you a clear error when attempting to format the code..
*HINT: Count the ENDIF's
Yep. DJ got it. No endif's.
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!
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
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?
Try this;
You need to have an Endif for every If statement
@bhouston
Shouldn't that ELSEIF be an ELSE ?
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!