Programming With Pictures icon Programming With Pictures — Use camera-detected printed cue cards (direction, pause, start) to record and run stored movement sequences for ARC robots. Try it →
Asked
Resolved Resolved by DJ Sures!
1 Participant

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 (view all EZB hardware)
EZ-B V4 by EZ-Robot
EZ-B v4 with Synthiam ARCx controls servos, sensors, camera and audio over Wi-Fi or USB serial, no firmware needed.
Wi-Fi / USB
Servos 24
Camera
Audio
UART 3
I2C
ADC 8
Digital 24

Related Robot Skills (view all robot skills)
Add custom EZ-Script functions in C# or JS; intercept unknown calls, parse parameters and return values via AdditionalFunctionEvent.
Script by Synthiam
Multi-language ARC Script: build, run and debug Blockly, JavaScript, EZ-Script or Python with Intellisense, run/save/load and Roboscratch support

ARC Pro

Upgrade to ARC Pro

Discover the limitless potential of robot programming with Synthiam ARC Pro – where innovation and creativity meet seamlessly.

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#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);

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#4  

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