Script Question

 
#1

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

#2

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

#3

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

#4

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. Smile

#5

@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

#6

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. Smile

#7

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 EZ-Builder displays it all. However, if it's ignored then they won't be resolved Smile

#8

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.

#9

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 Grin. 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

#10

@DJ Hey no fair, no hangin' out peoples dirty laundry man Tongue Oops I guess I'm next Smile