Sleep or wait for some time in OpenPnP scripts?

216 views
Skip to first unread message

Erich Styger

unread,
Apr 7, 2020, 2:58:03 AM4/7/20
to OpenPnP
Hello,
I might miss the obvious thing, but.....
in my scripts (e.g. Script Nozzle.AfterPlace.js) I need to actuate the solenoid for blowing air (to puff the part) and wait say 50 ms.
I have not found a good way to wait for a given time in the .js scripts.
I tried to use Thread.sleep(), but this was not availble?

   blow.actuate(true); /* BLOW on */
   print('waiting....'); /* any better way? Thread.sleep() is not available? */
   for(i=0; i<100000; i++) {
     j++;
   }
   blow.actuate(false); /* BLOW off */
That realtime synchronisation 'works', but obviously is not ideal. Any better way?

This is OpenPnP v2 if it matters.

Thanks,
Erich

Marek T.

unread,
Apr 7, 2020, 3:49:39 AM4/7/20
to OpenPnP
Thread.sleep(50)

Jim

unread,
Apr 7, 2020, 4:55:34 AM4/7/20
to OpenPnP
On Tuesday, April 7, 2020 at 8:58:03 AM UTC+2, Erich Styger wrote:
I tried to use Thread.sleep(), but this was not availble?

Hi Erich,

Have you tried this?

function waitms(ms) {
 
var ms1 = new Date().getTime() + ms;
 
var loop = true;
 
while (loop) {
   
var ms2 = new Date().getTime();
   
if (ms2 > ms1) loop = false;    
 
}
}

Jim

Jim

unread,
Apr 7, 2020, 5:23:22 AM4/7/20
to OpenPnP
Or simpler:

java.lang.Thread.sleep(100);

Results are 105 to 125 ms on my computer - not very accurate.

mojalovaa1

unread,
Apr 7, 2020, 10:37:31 AM4/7/20
to OpenPnP
On place comand put G4P0.1
For sample on my machine.
M23 ;turn off vacuum
M24 ;turn On air
G4P0.1 ; delay 0.1 sec
M25 ; turn off air

I use Gcode driver

Erich Styger

unread,
Apr 7, 2020, 2:34:12 PM4/7/20
to ope...@googlegroups.com
Jim,
thank you! The
java.lang.Thread.sleep(100);
is exactly what I needed (and works). I'm aware that it will not be very precise, but that's fine in that situation.

Erich

PS: Note to myself: Stupid me not considering me extending the namespace (still learning Java....)

--
You received this message because you are subscribed to the Google Groups "OpenPnP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpnp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openpnp/ba78dea6-250a-4296-b9f0-9a1f220b05c1%40googlegroups.com.

Erich Styger

unread,
Apr 7, 2020, 2:35:15 PM4/7/20
to ope...@googlegroups.com
Thanks, I tried that already, but missed to extend the name space like this:
java.lang.Thread.sleep(100);
So the above is perfect for me.
Erich

On Tue, Apr 7, 2020 at 9:49 AM Marek T. <marek.tw...@gmail.com> wrote:
Thread.sleep(50)


--
You received this message because you are subscribed to the Google Groups "OpenPnP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpnp+u...@googlegroups.com.

Marek T.

unread,
Apr 7, 2020, 5:49:24 PM4/7/20
to OpenPnP
It's strange Erich, I always write only short Thread.sleep(value); and it works. But the fact is that all my scripts are .bsh, maybe it makes a difference so.

Erich Styger

unread,
Apr 8, 2020, 1:19:04 AM4/8/20
to ope...@googlegroups.com
I'm using it in the Java scripts, and I get an error if just using Thread.sleep(100);:
grafik.png
java.lang.Thread.sleep(100);
works.

On Tue, Apr 7, 2020 at 11:49 PM Marek T. <marek.tw...@gmail.com> wrote:
It's strange Erich, I always write only short Thread.sleep(value); and it works. But the fact is that all my scripts are .bsh, maybe it makes a difference so.

--
You received this message because you are subscribed to the Google Groups "OpenPnP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpnp+u...@googlegroups.com.

ma...@makr.zone

unread,
Apr 8, 2020, 9:52:30 AM4/8/20
to OpenPnP
Hi Erich

If it is actually the machine that should wait, then mojalovaa1 is right, you should let the controller do the dwell (sleep), so it is in sync with the motion and other machine actions (and I assume it is much more "real-time"):

G4 P100 ; wait 100 ms

In Smoothieware the P param is milliseconds, the S param seconds.


Sending the G code from a script should be possible.

_Mark

Marek T.

unread,
Apr 8, 2020, 10:10:23 AM4/8/20
to OpenPnP
It is possible, I do it in some scripts.

Erich Styger

unread,
Apr 11, 2020, 12:17:20 PM4/11/20
to ope...@googlegroups.com
Hi Mark,
can you share an example how you do it?

Thanks,
Erich

--
You received this message because you are subscribed to the Google Groups "OpenPnP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpnp+u...@googlegroups.com.

ma...@makr.zone

unread,
Apr 11, 2020, 12:46:04 PM4/11/20
to ope...@googlegroups.com

Säli Erich

Marek may have an example. :-)

I was just speaking from a conceptual point. There are several places where OpenPNP currently uses a Thread sleep, where it should use a controller dwell instead.

It is currently irrelevant because OpenPNP waits for each command to complete. But that is one of the reasons why OpenPNP is slow compared to commercial PnPs. It should send commands to the controller asynchronously and let the controller execute the commands in sequence, in real-time, using a queue to decouple the two systems and their latencies. The controller can execute a move, then open a valve, then dwell a few milliseconds, then measure the vacuum pressure etc. all in sequence and all decoupled from OpenPNP (that might in turn be bogged down with optimizing the next planner move, for instance). There are only very few occasions, where the two need to be in sync. Actually I'm only aware of one situation and that's when computer vision needs to capture an image. 

Some things can be done in overlaps, such sending the controller a command to read a vacuum value and then moving the nozzle to the next location. If the vacuum level turns out faulty, the move will have been in vain, but because this is a rare event, it is still a winner, overall.

https://en.wikipedia.org/wiki/Speculative_execution

So it was from this thought process, that I made my initial remark here :-)

_Mark

Marek T.

unread,
Apr 11, 2020, 1:57:48 PM4/11/20
to OpenPnP
Yes I may :-)

If it is going about to send gcode from the script, I use it only in case of the jobStarting.bsh.
Just have tested a sec before it works:

setAccessibility(true);
machine.getDriver().sendCommand("G4P100");
or
machine.getDriver().subDrivers.get(0).sendCommand("G4P100");
Reply all
Reply to author
Forward
0 new messages