Asked
Resolved Resolved by DJ Sures!

Javascript ARC Command Sleeprandom() Does Not Seem To Work

I've got a Javascript that has a few commands that send simple Serial commands to a Kangaroo/Sabertooth motor controller with the UART.hardwareUartWriteString command. I want to pause the script for random periods between each motor movement. In the Support section under the Javascript API section it lists an example of a command that will do this is sleepRandom(1000, 5000); .

When I run the script with the sleepRandom() JS command I get an error saying "Execution Error Line 16 Col 0 - sleepRandom is not defined". Delow is my simple script. Am I doing something wrond or id sleepRandom() broken?

UART.hardwareUartWriteString(0,"1, p60200 s8000\r",1); // Waist Motor to 1/4 left Position, EZB 1, Uart Port 0

sleepRandom(2000, 9000);

UART.hardwareUartWriteString(0,"1, p98261 s8000\r",1); // Waist Motor to 1/4 right Position, EZB 1, Uart Port 0

sleepRandom(2000, 12000);

UART.hardwareUartWriteString(0,"1, p78200 s8000\r",1); // Waist Motor to center Position, EZB 1, Uart Port 0


Related Hardware EZ-B v4
Related Control Sabertooth Kangaroo

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

PRO
Canada
#1  

It looks like you're encountering an issue with the sleepRandom() function in your JavaScript script within ARC. The error message "sleepRandom is not defined" suggests that the function is not recognized by the scripting environment.

In ARC, the correct function to use for pausing execution for a random period is sleepRandom(minTimeMS, maxTimeMS). This function should work as expected if used correctly. Here are a few things to check and try:

  1. Syntax Check: Ensure that there are no syntax errors around the use of sleepRandom(). Your script seems to be formatted correctly, but always double-check for any typos or missing characters.

  2. Function Availability: Make sure that the sleepRandom() function is available in the version of ARC you are using. It's possible that updates or specific configurations might affect the availability of certain functions.

  3. Alternative Method: As a workaround, you can create your own function to mimic sleepRandom() using sleep() and JavaScript's Math.random() function. Here’s how you could implement it:

function customSleepRandom(minMs, maxMs) {
    var randomMs = Math.floor(Math.random() * (maxMs - minMs + 1) + minMs);
    sleep(randomMs);
}

// Usage in your script
UART.hardwareUartWriteString(0, 1, "p60200 s8000\r", 1);
customSleepRandom(2000, 9000);
UART.hardwareUartWriteString(0, 1, "p98261 s8000\r", 1);
customSleepRandom(2000, 12000);
UART.hardwareUartWriteString(0, 1, "p78200 s8000\r", 1);
  1. Documentation and Support: Check the latest ARC documentation or support forums to see if there are any notes or updates regarding the sleepRandom() function. Sometimes, functions may be deprecated or replaced in newer versions.

  2. Script Testing: Test the script with fixed sleep() calls to ensure that other parts of your script are functioning correctly. This can help isolate the issue to the sleepRandom() function specifically.

If the problem persists after trying these steps, it might be helpful to consult the Synthiam community forums or support resources for further assistance. They might have more specific guidance or updates regarding this issue.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
PRO
Synthiam
#2  

It looks like sleeprandom doesn't exist. I'll add it quickly for the next update. but in the meantime, u can use athena's suggestion

#4  

@Athena 's script suggestion worked amazingly well. Thanks again.

PRO
Canada
#5  

You're welcome, Dave! I'm glad to hear that the script worked well for you. If you have any more questions or need further assistance with your ARC projects, feel free to ask. Happy robot building!


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.