
Charel

Should I use the sleep(timeMs)
EZ-Script API command in Synthiam ARC, or is it better to use the standard Python sleep
function, such as import time; time.sleep(0.05)
?
I have been programming using the time.sleep()
function, which is standard practice in Python for introducing delays in scripts. However, I recently noticed the sleep(timeMs)
command available in the EZ-Script environment within Synthiam ARC. I'm curious about the implications of using time.sleep()
in this context and whether it might pose any issues when integrating with ARC.
Are there specific advantages or limitations to using the sleep(timeMs)
EZ-Script command instead of sticking with the Python standard library's time.sleep()
? Any insights into performance or compatibility differences between these two sleep functions would be greatly appreciated, especially considering ARC's programming environment and how it interacts with robot control processes.
I like that Athena is helping me to spell correct, etc. But changing the question is not such a great idea. .. Tried to edit the question but it keeps changing back. This is not an EZ-Script question. It is a question about the python API, the sleep root command in the python API
Below is some background on the two approaches and our recommendation:
ARC’s Root sleep() Command
- When you call sleep(timeMs) in ARC’s Python API, you’re using a function that’s part of ARC’s core scripting root commands.
- It accepts time in milliseconds (so sleep(50) pauses for 50 ms) and is integrated with ARC’s event scheduling and control system.
- Using ARC’s sleep() ensures that your delay works consistently within the framework and that any ARC-specific handling (such as debugging or internal timing adjustments) is taken into account.
Standard time.sleep() from Python’s time Module
- This is the native sleep function from Python and expects time in seconds (so you’d write time.sleep(0.05) for 50 ms).
- Though it works well in standalone Python scripts, it hasn’t been specifically optimized for ARC’s environment.
So Which Should You Use?
- In Synthiam ARC, if you’re writing your scripts using the ARC API (even in Python), it’s better to use the ARC-provided sleep() root command.
- Doing so removes potential unit confusion (milliseconds vs. seconds) and maintains consistency with the rest of ARC’s scripting environment.
- This ensures that pause operations are handled in a way that’s fully compatible with the robot’s control processes and ARC’s timing architecture.
For example, in ARC Python code you can simply do:
print("Starting delay") sleep(50) # Pauses for 50 milliseconds print("Delay complete!")
In contrast, using the standard Python approach would require converting milliseconds to seconds:
import time print("Starting delay") time.sleep(0.05) # Also 50 milliseconds pause print("Delay complete!")
While both work as delays, using sleep(50) ties your code more directly into ARC’s system and avoids additional conversions.
Do you have a specific scenario where timing accuracy or integration with other ARC robot skills is critical? Let me know, and we can dive deeper into any performance or compatibility nuances for your project.
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.
First, I know nothing about writing scripts in Python. I've recently learned to stumble through Javascript. I had many, many scripts in my ARC Project written in EZ Script. I decided I was going to rewrite them all in Javascript (not going into the reason here. Your welcome.
LOL).
To your point, @Athena mentions ARC's Python API root command for sleep. I think using that sleep command is probably the way to go when you are working in the ARC environment. However as you know the Python time.sleep() function works just as well. As for which is better and why @DJ would need to dig into that.
Here's the ARC's Python API root command for sleep and an example:
So I wrote the following before I reread your question and realized that I misunderstood what you were asking. I I put a lot of thought into it so I just will keep it here. Maybe it will help someone else. LOL. cool I think the AI generated title of your post through me. Sorry:
I will say one deciding reason to switch to Javascript was because Javascript (and probably Python) runs so much smoother and faster then EZ Script. EZ Script is @DJ's brilliant brain child that is suppose to make it easier and quicker for people like me to learn and write script to make your robot work with ARC. The EZ Script commands you write are supported by millions (maybe more, maybe less) of lines of code DJ wrote and are stored somewhere in the back of ARC. EZ Script works like magic but it's slow and Synthiam does not support it or help it to grow anymore.
DJ and his team has has also included the ability to use other languages like my JavaScript and your Python. Both are superior to EZ Script and Synthiam suggests you use them over EZ Script. There is also Blockly and Roboscratch that will help us write scripts.
One feature of ARC, as you know, is that you can write different scripts to make things happen with your robot. Now, here's the thing. You can mix up your scripts in ARC between these different computer languages and ARC will run them as needed. However you can not write code from the different languages in one script. You will get an error. When you open a new Scripting Control to write a script, you can choose the language you want to use towards the top left corner.
If you haven't already you may want to read over the Support section. It's loaded with most answers. Here is a section on the different ways to program and how they work togather: https://synthiam.com/Support/Programming/Overview I hope this helps a little.
Oh, also, if you don't want to have Athena reformat your question there is a check box you can UN check at the bottom of the page unser where you type. It's the first question on the list where they ask you to Agree to Terms before you post your question.
Below is a summary reply incorporating Dave_Schulpius’s observations and explaining our recommendations regarding sleep commands in Synthiam ARC, especially in the context of the Python API:
Key Points:
ARC Python API sleep() Root Command:
sleep(timeMs)
root command is designed to pause script execution for the specified number of milliseconds.Standard Python time.sleep() Function:
time.sleep()
function is also available but requires you to work in seconds instead of milliseconds (e.g.,time.sleep(0.05)
for 50 milliseconds).Why Use the ARC sleep() Command?
Mixing Languages in ARC:
Other Thoughts:
time.sleep()
and have built scripts in EZ-Script before, using ARC’s native sleep command in your Python scripts will be more aligned with how the robot’s control processes expect delays to be handled.Conclusion:
For Synthiam ARC, while you can use Python’s standard
time.sleep()
, it is generally better to use the ARC Python API rootsleep(timeMs)
command. This ensures that your delay timing is in milliseconds, integrates more naturally with ARC’s internal event handling, and avoids potential unit conversion issues.If you have any further questions or want to discuss specific timing scenarios in your project, please let me know!
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.
You can't call ezscript from python. Within the python code editor tab, you can only use python commands. However, the python tab has a sleep() and a time.sleep() as you pointed out.
I'd recommend using the ARC's sleep() vs importing time to use time.sleep(). This is because the imported time.sleep is blocking, which means you can't stop a script while it's sleeping. When the python sleep is called, the script has to wait for time.sleep to expire because stopping the script.
With the ARC's sleep(), the script will exit when the script has stopped even if it is sleeping.
Lastly, the sleep() of ARC is millisecond resolution, where time.sleep() is second resolution.
I will use ARC sleep, thank you for the recommendations. The first pieces of codes are running in Python. Really nice EZ-Script and Python can coexist together, that way I can migrate step by step. Also the try-except in Python is very powerful, didn't have that in EZ-script. The old EZB script did hang sometimes on an I2C read and I needed to restart the whole droid. I hope this problem is now gone with the try-except in Python.
The i2c command for any supported language in ARC will block on i2c communication errors between the i2c device and the ezb.
This is due to i2c communication works by blocking during receiving. The way to prevent blocking is to ensure the i2c device is securely and correctly connected to the ezb. Also, ensuring correct resistance and that cabling is away from power sources, such as power supplies, motor controllers and radio static like relays.