Sleep or wait for some time in OpenPnP scripts?

216 visualizzazioni
Passa al primo messaggio da leggere

Erich Styger

da leggere,
7 apr 2020, 02:58:0307/04/20
a 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.

da leggere,
7 apr 2020, 03:49:3907/04/20
a OpenPnP
Thread.sleep(50)

Jim

da leggere,
7 apr 2020, 04:55:3407/04/20
a 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

da leggere,
7 apr 2020, 05:23:2207/04/20
a OpenPnP
Or simpler:

java.lang.Thread.sleep(100);

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

mojalovaa1

da leggere,
7 apr 2020, 10:37:3107/04/20
a 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

da leggere,
7 apr 2020, 14:34:1207/04/20
a 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

da leggere,
7 apr 2020, 14:35:1507/04/20
a 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.

da leggere,
7 apr 2020, 17:49:2407/04/20
a 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

da leggere,
8 apr 2020, 01:19:0408/04/20
a 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

da leggere,
8 apr 2020, 09:52:3008/04/20
a 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.

da leggere,
8 apr 2020, 10:10:2308/04/20
a OpenPnP
It is possible, I do it in some scripts.

Erich Styger

da leggere,
11 apr 2020, 12:17:2011/04/20
a 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

da leggere,
11 apr 2020, 12:46:0411/04/20
a 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.

da leggere,
11 apr 2020, 13:57:4811/04/20
a 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");
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi