Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.
Get Started

Asked — Edited

Script Question

Please have a look at this script. Will it run all the way through or will the Halt() command in the first "if" statement cause it to stop before it gets to the "Elseif" section? Thanks for looking.

Code:


if ($ADC_Lft_Elbow => 160 )#160-350 is in Centered position
$Lft_Arm_Centered = 0 #Reset varable 1=not cnetered, 0=centered
Halt()
ELSEif ($ADC_Lft_Elbow < 160 #Below 160 is not centered
uartWrite(2, 0, "2,p2480", 0x0d) #Move Lft Elbow Motor down a little
$Lft_Arm_Centered = 0 #Reset varable 1=not centered, 0=centered
endif

AI Support Bot
Related Content
Synthiam
Synthiam
#1  
I don't understand the question?

The halt command will run if the first condition is met. The halt command will not run if the first condition is not met.

Have you tried using blockly? A visual representation might be easier for you
#2  
Hi Dave,
There are a few issues with the code. especially the use of an "Elseif" instead of an "Else" will result in errors as you end up with TWO IFs and only ONE Endif

Also you were setting $Lft_Arm_Centered to "0" in both of the tests and I don't see the need for a Halt()

Anyway, try this code

Code:

 
if ($ADC_Lft_Elbow => 160 ) #160-350 is in Centered position
$Lft_Arm_Centered = 0 #Reset variable 1=not centered, 0=centered
ELSE #Below 160 is not centered
uartWrite(2, 0, "2,p2480", 0x0d) #Move Lft Elbow Motor down a little
$Lft_Arm_Centered = 1 #Reset variable 1=not centered, 0=centered
endif


Please note that the "Else clause only moves the arm a little bit and you will need to call this code again until the reading is greater than 160.

You can test $Lft_Arm_Centered variable to see if it needs to be called again

Regards,
Frank
#3  
Thanks guys.

@DJ, you answered my question. That's exactly what I wanted to know. I wasn't sure the Halt command would override the flow and stop it right there.

@Frank, Thanks for pointing out the Else issue. I'll make that change. I didn't post the entire script. Just the section I had a question about. What I'm trying to do here is to move the arm just a little bit if the ADC reading is below 160. If the ADC reading is above 160 then the arm is centered and I don't need to move it at all. You'er right though, to make sure it's in the desired place I should take another ADC reading. :)
Synthiam
#4  
@Frank's the man with the plan

also dave, now that i'm in front of a pc... you're missing a closing bracket on one line

Code:


ELSEif ($ADC_Lft_Elbow < 160 #Below 160 is not centered
#5  
Humm, nice. Thanks for catching that. I'm surprised that the script was running without sending an error message. On the other hand, there's so much going on in the project that I could be missing it.
I'll fix it and see what happens. :)
Synthiam
#6  
Oh, you have plenty of errors in your log files. Hundreds in fact. Missing quotes, improperly formed conditions, etc.

The status debug window at the bottom of ARC displays it all. However, if it's ignored then they won't be resolved:)
#7  
Oh my, how embarrassing. I do know I've been going through all my scripts lately and either rewriting them or cleaning them up. I have been finding and creating lots of errors. Maybe this is what you're seeing. I'll be watching that debug window closer now.
Synthiam
#8  
Nothing to be embarrassed about. Learning is harmless. watch the window. Here's some examples from yesterday...

Quote:


12/26/2016 3:21:14 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:21:42 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:21:42 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 45: Variable not defined: $Rt_Carrage_Position
12/26/2016 3:24:27 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:24:27 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 45: Variable not defined: $Rt_Carrage_Position
12/26/2016 3:25:24 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:25:24 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 45: Variable not defined: $Rt_Carrage_Position
12/26/2016 3:25:26 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:25:26 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 45: Variable not defined: $Rt_Carrage_Position
12/26/2016 3:25:35 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:25:35 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 45: Variable not defined: $Rt_Carrage_Position
12/26/2016 3:32:46 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:33:33 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:33:34 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 89: Missing ) in Expression
12/26/2016 3:35:58 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:35:58 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:36:31 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBSaved C:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZB
12/26/2016 3:37:03 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:37:03 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:37:04 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:37:49 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBSaved C:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZB
12/26/2016 3:44:20 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:47:11 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBSaved C:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZB
12/26/2016 3:47:28 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 3:59:26 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBSaved C:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZB
12/26/2016 4:01:20 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBSaved C:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZB
12/26/2016 4:01:37 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 4:02:27 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 4:03:45 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "


and

Quote:


12/26/2016 5:15:28 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 22: Variable not defined: $Rt_Carrage_Position
12/26/2016 5:36:40 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBSaved C:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZB
12/26/2016 5:46:43 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 25: Missing String Quotes or Invalid Expression at index 14: "
12/26/2016 5:46:47 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 3: Line 14. Unable to find label for goto(:Move_Rt_Elbow)
12/26/2016 5:48:55 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError: Line 14. Unable to find label for goto(:Move_Rt_Elbow)
12/26/2016 5:49:50 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 3: Missing 1 closing statement (ENDIF/ENDREPEAT/ENDREPEATUNTIL/REPEATWHILE/ENDREPEATWHILE/etc)
12/26/2016 5:50:37 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError: Missing 1 closing statement (ENDIF/ENDREPEAT/ENDREPEATUNTIL/REPEATWHILE/ENDREPEATWHILE/etc)
12/26/2016 6:01:55 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 14: Missing String Quotes or Invalid Expression at index 0: elsif
12/26/2016 6:03:18 PMC:\Users\Robot Control\Documents\EZ-Builder\My Projects\B9 Robot Control.EZBError on line 15: Missing String Quotes or Invalid Expression at index 0: elsif


It goes on like that for pages and pages :D. Now, some of that may be during your testing as well. When your robot project runs, the debug window should never have to raise. It should only need to raise when...

1) project is loaded
2) ezb is connected
3) camera is connected
#9  
@DJ Hey no fair, no hangin' out peoples dirty laundry man:P Oops I guess I'm next:)
Synthiam
#10  
Hey - that's helpful information for David. Far from dirty laundry. At least i suspect he'd see it as helpful:D
#11  
Yes , I do see this as helpful. Looking at the dates listed these were back in december when I was having "qiote" issues because I was having trouble with understanding Bianery among other things. You made some changes in ARC and I made some adjustments and that issue was solved.

I don't mind my "dirty laundry" hanging out for all to see. Hopefull others can learn from my mistakes. I know I try to. LOL. I don't fear failure at all. However, it does get flustrating sometimes. ;)

I went through all my scripts again last night and was able to get them all to eun error free. No Debug popup bugging me. I'm sure I'll make more as I move along. It seems like I cant write a script without an error popping up after the first draft. I'll be sure to use the debug wondow from now one. Thanks again. :)
Synthiam
#12  
That's excellent to hear! Happy robot:)