polling input while executing G code

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

polling input while executing G code

Postby dhanger » Thu Dec 29, 2022 3:47 pm

How does one poll for an input pin while using exec.Code for an axis move? I have a pair of crash sensors (push/pull) on a rotary changer and want to be able to stop motion if one of the sensors gets activated, for example if the drawbar does not open when commanded to. The sensors are working, I can activate them manually and show up on diagnostic screen. UCCNC appears to ignore inputs while using exec.Code. Here's a snippet I tried:

// Z up
if (Debug) { MessageBox.Show("Debug: Z up!"); }

exec.Code("G01 f100.0 G53 Z"+RetractZ);

//MessageBox.Show("Done sending code, proceeding into loop");

while(exec.IsMoving()) {
if (!AS3.GetLED(in_pullSensor_pin)) {
MessageBox.Show("Tool not released! Stopping tool change.");
exec.Stop();
}
exec.Wait(JamDetect_wait);
}

The while loop does not get activated until the exec.Code line is completed and returns to the macro so that didn't work. I also tried setting an input trigger for the 2 sensors with a trigger of 130 (cycle stop)--this works reliably outside of the macro when I set the Z axis moving using MDI and activate the sensors manually, but this also gets ignored while using the macro and the axis is moving. If I try to activate the sensors manually during the macro run the status screen does show 'cycle stop' from the input trigger but it does not stop motion.

I thought this would be easy and it probably is, just not for this novice.

Dan
dhanger
 
Posts: 127
Joined: Thu Aug 29, 2019 1:57 pm

Re: polling input while executing G code

Postby ger21 » Thu Dec 29, 2022 4:42 pm

Check the state of the input LED before making your move, and exit the macro if the sensor is activated.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: polling input while executing G code

Postby dhanger » Thu Dec 29, 2022 5:04 pm

Gerry-

That's the problem, I need to check the input state continuously while moving but I haven't found a way to do that.
dhanger
 
Posts: 127
Joined: Thu Aug 29, 2019 1:57 pm

Re: polling input while executing G code

Postby dezsoe » Thu Dec 29, 2022 8:11 pm

Does the message show up? If yes then simply change the order of the lines to stop first and only show the message after you stopped. The MessageBox.Show will not return until you press OK, so the exec.Stop will be executed after you pressed OK.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: polling input while executing G code

Postby dhanger » Thu Dec 29, 2022 8:30 pm

dezsoe wrote:Does the message show up? If yes then simply change the order of the lines to stop first and only show the message after you stopped. The MessageBox.Show will not return until you press OK, so the exec.Stop will be executed after you pressed OK.


I don't think I'm explaining my issue very well. I need to have the sensor input monitored and acted upon *while the G code is being executed*. So for example if the spindle is moving down to pick up a new tool--the drawbar should be open and ready--if it's not (lost air pressure) it will push down on the tool and carousel and trip the sensor. Likewise if the drawbar does not release the tool when commanded but is still holding it while the G code says move up, it will pull on the tool and carousel and trip another sensor. Whenever either sensor changes state *while executing exec.code* I want the macro to halt, indicating a jam in the ATC.

There are 2 message boxes, the first one is commented and used for troubleshooting just to verify whether the exec.code needed to complete before continuing the macro. The other message box doesn't show up because the condition is never met, i.e. this code isn't doing what I had hoped so it's currently irrelevant.
dhanger
 
Posts: 127
Joined: Thu Aug 29, 2019 1:57 pm

Re: polling input while executing G code

Postby dezsoe » Thu Dec 29, 2022 9:28 pm

Your while loop should work, just delete "exec.Wait(JamDetect_wait);". You may replace it with a Thread.Sleep(5);.

Another way is to create a timer and check for the inputs in e.g. every 10 ms. (If I can recall, UCCNC updates the LEDs in every 20 ms, but you don't know when it happens, so 10 ms is far enough.) You can use a "global" variable (global in your code, so you can set it and the timer can read it) to select which input to check for which state and if the condition matches then you can call stop from the timer. In your main code you just have to check for Ismacrostopped.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: polling input while executing G code

Postby dhanger » Thu Dec 29, 2022 10:42 pm

dezsoe wrote:Your while loop should work, just delete "exec.Wait(JamDetect_wait);". You may replace it with a Thread.Sleep(5);.


But the while loop doesn't even get executed until the exec.code line finishes, in which case it's too late to do any good since the Z move in which I want to poll the input is all done.
dhanger
 
Posts: 127
Joined: Thu Aug 29, 2019 1:57 pm

Re: polling input while executing G code

Postby fsli » Thu Dec 29, 2022 11:59 pm

dhanger wrote:I also tried setting an input trigger for the 2 sensors with a trigger of 130 (cycle stop)

Dan,

I think you're on the right path here. If the motion command is ignoring the Cycle Stop signal, then I'd suggest trying other triggers which should force motion to stop.

  • Set the input trigger to the Reset button (144).
  • Assign the input pin to one (or both) probe inputs on the settings page, and enable safe probe mode in the macro.
  • Couple the crash sensor to the e-stop circuit (after all, crashing into something would certainly qualify as an emergency).
  • Couple the crash sensor to an axis limit circuit.
In addition, after your while(exec.Ismoving()) loop, you'll want to check the exec.Ismacrostopped() flag to prevent continuing your macro statements if a crash happened.
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: polling input while executing G code

Postby dhanger » Fri Dec 30, 2022 1:33 pm

Frank-

I'll give your suggestions a try although I'm wondering now if anything will work (except maybe coupling to estop) as it seems apparent that the macro gives up control momentarily while the exec.code command is executing. Almost as if the macro and UCCNC are pointing fingers at each other and saying 'that's your job' LOL.

It seems pointless to rely on the while loop for anything after the the exec.code command as long as it's not even referenced until the move is completed, and if the trigger function worked as intended there would be no need for the loop at all, so I'm kinda stumped what's going on. I'll also take a look at Dezsoe's other suggestion about the timer once I get a grasp on it, this is harder than I had thought for a non-programmer.
dhanger
 
Posts: 127
Joined: Thu Aug 29, 2019 1:57 pm

Re: polling input while executing G code

Postby ger21 » Fri Dec 30, 2022 1:47 pm

That's the problem, I need to check the input state continuously while moving


I don't see the need to check the state while the machine is moving. The $180,000 machine I use checks before moving.
1) Check if drawbar is open.
2) If yes, move down.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 12 guests