Macro loop input time delay

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

Macro loop input time delay

Postby Mcasey » Wed Nov 03, 2021 4:05 pm

Hi guys,

I am using a collision detect head on a plasma head and the problem I have is that my proximity sensors are too sensitive, if the head barely touches the smallest bit of dross it stops the machine, I want to make a macro loop that will have a time delay of approx 0.5sec before it sends a signal, this will allow the head to have a small amount of movement before it actives the limit. I have been pulling my hair out trying to do this, can anyone shed some light on how to add a time delay to an input.
Mcasey
 
Posts: 21
Joined: Sun Apr 11, 2021 6:10 pm

Re: Macro loop input time delay

Postby dezsoe » Wed Nov 03, 2021 4:19 pm

Do you want to write the macro or just a solution to delay the sensor? If the second then try the Fault signals plugin: it has a delay on the input signal.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Macro loop input time delay

Postby Mcasey » Thu Nov 04, 2021 11:14 am

I would like to write it if possible, I'm trying to learn how to write macros, I've done quite a few simple macros just executing g code, but just can't figure this out
Mcasey
 
Posts: 21
Joined: Sun Apr 11, 2021 6:10 pm

Re: Macro loop input time delay

Postby dezsoe » Thu Nov 04, 2021 11:55 am

OK, then you need to know some basics.
- Your macroloop code will be executed 20 times per second. (In fact, your code is inserted into a loop which ends with a 50 ms delay.) So, you can have a counter which counts the 50 ms loops: 10 will be a half second.
- To use variables that are not recreated in all loop iterations you have to declare them after the #Events code.

Your macroloop should look like this (in pseudo-code, because you want to write it):

Code: Select all
bool inputstate = getled(inputportpin)

if inputstate <> lastinputstate
  // state changed
  if inputstate
    // changed and become active -> reset counter to delay in 50 ms steps
    counter = 10
  // save input state
  lastinputstate = inputstate

if inputstate and counter > 0
  // the input is active and no time-out
  --counter
  if counter = 0
    // timed out
    // do your stuff here

#Events

int counter = 0
bool lastinputstate = false
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary


Return to Macros

Who is online

Users browsing this forum: No registered users and 2 guests

cron