
kamaroman68
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?Code:
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
Chris
Thanks Chris
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.
Code:
Chris
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***
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
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
Chris
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...
Code:
Code:
Code:
I could be wrong but It may be moving too fast and skipping a needed command. Try placing a Sleep() command between:
Code:
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.
Faengelm I will try that later tonight when I return home this evening. Hopefully that works.
Chris
Chris
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
Chris
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