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!
@faengelm, yes, it should be but it will work the way he has it. The key though is to have an Endif for every If statement.
How are you guys formatting the posted code?
Thanks Chris
Use the tags to format code.
Maybe this is what you want? I "assume" the ENDIF is to be at the end of code because the next IF is comparing to see an object in the path - which i suspect means the robot is moving.
You added an ENDIF for one of the IF conditions, but not the other.
Guys after further testing this script today I found further issues. Im hoping someone can shed some light on it. What I want is if the "movement = false" I don't want any more of the script to run. What happens is if I say "robot turn left" and the movement is false, it will say "my track motors are disabled" and then the head lowers and looks in appropriate direction and if nothing detected it starts to move. It should NOT move if the track motors are disabled. Thanks guys major headache tonight.
IF ($movement = "false") print("movement prohibited") SayEzb("my track motors are disabled")
ELSE print("moving") ENDIF
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,235) sendserial(d0,38400,107) sleep(3000) sendserial(d0,38400,0) ELSE ($leftsensor >=60 Or ($rightsensor >=60) SendSerial(D0,38400,0) SayEZB("i have detected something in my path") ENDIF
ControlCommand("Script Manager ", ScriptStart, "Head_Center")
*** EDIT I need to try DJ's above script. I will try that and get back***
This doesn't answer your script question, just your question about formatting code.
Unfortunately, I can't type the UBB code, because the forum will format it, so I'll describe it...
Look in the box to the right of the text input window labeled UBB code (it will be under the window if you are on a mobile device or your screen is small).
Next to the word Code is an example...
To format code, type a left open bracket, the word "code" and a right close bracket.
Enter all of your code, then type a left open bracket, a slash, the word code, and a right close bracket.
Quoting is similar, but use the word quote instead of code.
Alan
Thanks Alan I will try that next time.
Now onto another question regarding DJ's code. What in there is defining $left sensor and $right sensor to there respective adc ports? Thanks again
I believe DJ's code will do what you are looking for
@kamaroman68 To further what Alan said
Below is an example on how to use code tags
[code #use another closing square bracket after the word code]
#everything between these code tags will be black #example code can be anything say("I am a robot")
[/code #use another closing square bracket after /code]
DJ's code altered a little...
This script still does not work completely. If I block the sensors it does not move which is correct, but it never says " I have detected something in my path".
Richard thanks for the lesson on the tags that was a big help. Other forums I visit don't require that. Thanks again.
In your following statement something looks odd to me.
I could be wrong but It may be moving too fast and skipping a needed command. Try placing a Sleep() command between:
Thinking about this more I'm sure my above post may be part of your problem. You need to give things time to complete operation before moving on to the next command. This is even more important when you're sending serial commands to other devices. Too fast and you're going to flood the channel or send a command faster then the device you're trying to control can accept and read it. I find this to be true when sending serial commands to the Kangaroo X2 I control through ARC and EZB.
To troubleshoot timing issues I sometime give Sleep() commands a stupid amount of time. This really slows down the script and lets things complete. Then I trim down the sleep() times till everything runs fast and smooth.
Try changing that ELSEIF to ELSE
Dave the reason those two serial commands are like that are to start the 2 tracks in opposite directions. I cant start 1 and then start the other after a sleep period. Thanks for the response though, I appreciate it and may try a sleep at other points to troubleshoot.
Faengelm I will try that later tonight when I return home this evening. Hopefully that works.
Yes... get rid of the elseif and use else.... You only use elseif if you are checking on an additional condition that may exist....
Thanks guys will try tomorrow, some life changes prevented me from trying tonight. It was my night with the kids! thanks again
One trick to try when testing script logic, is instead of actually moving the robot or its parts, replace those commands with Print() commands that tell you where in the script you are. Then execute the script while watching the script object window.
If using variables you can also print those so you can easily see that they are getting set the way you expect.
Once you get the logic right, then replace (or add to) the print commands with the actual Robot movement commands. This prevents uncontrolled movement when the logic is wrong, and helps isolate the logic from possible control issues.
Alan
Yes Yes Yes! A couple of further tweeks to that script after the "else" changed proved exactly what I am looking for. Very very nice. Thanks for all the help with this one.
Great to hear!
Also it's very useful to know that running the script while editing in the debug window will display the executing instruction of each line.
Running a script in the editor is a fantastic way to debug the execution. It's super useful