Asked
— Edited

I'm getting an error message in one of my scripts that is giving me some trouble. It's a random error meaning that it will happen every few times the command is run. It's set in a loop so it will repeat. Sometimes it will even cause the connection between the EZB and computer to cut off. Here'e the error:
Error on line 25: Missing String Quotes or Invalid Expression at index 14: "
and
Error on line 25: Missing String Quotes or Invalid Expression at index 15: "
Here's the script to happens in. Seems to center around the print commands. Once I removed the print command at line 25 and the error skipped to the next one. I've also expanded the sleep() commands thinking it was running too fast but it does not help. Thanks for looking :
# This Script will return the actual position number of the left catrrage
# #from the Kangaroo withough the 1,p in the begining.
# #Returning feedback with the 1,p causes problems.
# #Do Not Delete. Other scripts depend on this script!
# -------------------------------------
# Get Roo position
uartWrite(2, 2, "2, Getp", 0x0d)
:waitForData
Sleep(30)
$y_lft = UartAvailable(2, 2)
Sleep(30)
print("Bytes in buffer:" + $y_lft)
if ($y_lft < 6)
# Go back and wait for data again because we did not receive the least number of expected bytes.
goto(waitForData)
endif
Sleep(30)
$Get_Lft_Carrage_P = UARTRead(2, 2, $y_lft)
Sleep(30)
print("Received: " + $Get_Lft_Carrage_P)
Sleep( 50 )
# -------------------------------
# Find out and print if the P is upper or lower case.
# Upper case means motor has finished move ans stoped.
# Lower Case means that motor is still moving.
$P_lft_or_p_lft = GetCharAt($Get_Lft_Carrage_P, 2) #Assign a variable to either a capitol P or Small case p returned by Kangaroo.
Print("P_lft_or_p_lft:" + $P_lft_or_p_lft)
# -----------------------------
# Defeat the P_lft_or_p_lft
if ($P_lft_or_p_lft = "p")
Goto(Lower_p_Split)
ELSEif ($P_lft_or_p_lft = "P")
Goto(Upper_P_Split)
endif
Sleep( 50 )
:Lower_p_Split
$Lft_Carrage_Position = Split($Get_Lft_Carrage_P, "p",1) #1,pXXXX is returned. Get everything after the Lower case p (P is case senceitive).
Sleep(30)
print("Received:" + $Lft_Carrage_Position)
Halt()
:Upper_P_Split
$Lft_Carrage_Position = Split($Get_Lft_Carrage_P, "P",1) #1,pXXXX is returned. Get everything after the Upper case P (P is case senceitive).
Sleep(30)
print("Received:" + $Lft_Carrage_Position)
I upgraded ARC with your new version. I can't tell for sure if the changes you made worked.
When I first ran the script I had trouble getting the thing to loop when called from another script and I would still get the error first mentioned if the script ran to fast. Then I changed the timing of the loop and limited how many times it ran. After a few tries I was able to get it to loop without an error. In the script there are several calls on the uart port. I'm wondering if reading the Uart port to fast or calling the looping script before it has completed running is causing the error?
You can't read the uart from multiple threads (i.e. different scripts) at the same time. Think about it... It's called SERIAL for a reason
Actually I was reading the variable with one thread that was changing in the looping script. That should work, shouldn't it?
Not if the variable is changed during the other script thread.
Can you not do everything in one script?
This is interesting. So, if I have a script looping and applying a different value to the same variable each time it loops, when will the value actually change globally so other scripts can see the changes? I'm also asking how long it take to have a variable value change globally once it's stated?
I can have most everything done in one script. At least the one process of moving the carriage out of the robot body and reading it's position. However once the carriage is safely out of the torso the arm animation will have to be handled by the Auto Position control. It needs to know the arm is out of the robot as soon as possible so the animation can start quickly.
Yes, other scripts will see the variable change. What DJ was saying is you can't have two scripts reading the UART. But one can read it and populatr variables, and others can act when that variable changes.
Alan
OK, Everything seems to be running smoothly now. I've combined the scripts and it's running without errors. Again, I'm not sure what really did the trick, DJ's filter, working out the timing so the Uart was not being called by different scripts at the same time or combining everything in one script. Most likely, it was all of the above. Many thanks again for helping me work through this.
Here's a video of the final result:
Love seeing it all come together.
Alan