Asked
Resolved Resolved by DJ Sures!

EZ Script Math Function Suddenly Gets Error.

First, this problem just started ever since I've been converting me EZ Scripts into JavaScripts in my project. I now have a mix of both scripts through out my project. These EZ Scripts worked before I started this process.

At some point during this process of conversion I started getting an error message from an EZ Script that uses math functions. Th error seems to center around the minus '-" function. I haven't stopped to test but it may extend to other math functions.

Below is the error I get in ARC:

> Error on line 70: Operator '-' invalid for strings.

Here is the ez sCRIPT COMMAND ON Line 70 from the script that runs. Like I mentioned above this used to work. There is no other script that depends on this script to run:

 

print("Received:" + ($Rt_Elbow_stopped-10))#Print Emergency Stop Position

I also get this error from other lines in this script using this function. Here's one:

ELSEif ($Lft_Elbow_stopped <($Lft_Elbow_Center-10) or $Rt_Elbow_stopped <($Rt_Elbow_Center-10))

Any ideas what is happening? Is my process of adding JS scripts to my project and mixing EZ Scripts with JS scripts somehow causing this? I didn't have this issue till I started adding JS Scripts.


Related Hardware EZ-B v4

ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

PRO
Synthiam
#1  

The error says


> Error on line 70: Operator '-' invalid for strings.

So the content of the variable is a string. You can't subtract from a string. You'll have to check the content of the variable that you're subtracting from.

At some place in your program, you're assigning a string to one of those variables.

#2  

Ahh, I must have another script using that var. Thanks. I'll go hunting.

#3   — Edited

Thanks again @DJ. Turns out I had to change that string into a number. I found there are many ways to do this in JS. I ended up using the Number function. Here's the working script with the command line in Bold:

//Send Request to Kangaroo Channel 1 to Get Position of Right Elbow Motor var Get_Rt_Elbow_P = "1, Getp\r"; UART.hardwareUartWrite(0,Get_Rt_Elbow_P.length,2); //UART 0 on EZB 2 UART.hardwareUartWriteString(0,Get_Rt_Elbow_P,2); //UART 0 on EZB 2

//Pause to let UART Buffer fill sleep( 100 );

//Read Full String Actual Position of Right Elbow Motor. Expecting 1,pxxx (Lowercase p - Still Moving)) or 1,Pxxx(Upper case P - Movment Stopped) var UartReadStringAvailable_RtElbow = UART.hardwareUartReadStringAvailable(0,2); print("UartReadStringAvailable_RtElbow: " + UartReadStringAvailable_RtElbow);

//Read last numbers in returned string and turn string into numbers then set golbal var var Rt_Elbow_stopped = Number(UartReadStringAvailable_RtElbow.substr(3, 7)); print ("Rt_Elbow_stopped: " + Rt_Elbow_stopped); setVar( "$Rt_Elbow_stopped", Rt_Elbow_stopped );

//Set another golbal var var Rt_Elbow_Center = Rt_Elbow_stopped; print( "Rt_Elbow_Center: " + Rt_Elbow_Center ); setVar( "$Rt_Elbow_Center",Rt_Elbow_Center);

PRO
Synthiam
#4  

Oh nice! Glad you figured it out. Now we know about Number() function :)