Waiting inside M1nn code

More
18 Dec 2016 12:21 #84356 by soroosh.av
I have a milling machine with a rotary table. the table has 4 positions on every 90 degrees and it is being controlled with an external system. All I need to do is to send the requested position using two bits(Position 00, 01, 10 or 11) to the external PLC and wait for the done signal by PLC. I'm going to use four special m code( for example M101, M102, M103, M104) for each position.
The problem is that I need to wait for the done signal by PLC inside the M code program and I don't know how can I do it. Any body have an Idea?
I found this wiki.linuxcnc.org/cgi-bin/wiki.pl?CustomMcodesToHal
But I can't understand what exactly he/she did.

Please Log in or Create an account to join the conversation.

More
18 Dec 2016 23:40 #84379 by andypugh
Replied by andypugh on topic Waiting inside M1nn code
You probably can wait inside the M-code, but it might be better to wait in the G-code using M66
linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m66
This allows you to set a timeout period and then branch the G-code on failure.

Please Log in or Create an account to join the conversation.

More
20 Dec 2016 10:41 #84446 by soroosh.av
Replied by soroosh.av on topic Waiting inside M1nn code
But in my case I prefer to use waiting inside M code( because I'm not the only one who will work with the machine and I'm not sure about my partners!). Can you tell me how to wait inside M code and why do you suggest to use M66 instead?
Thanks.

Please Log in or Create an account to join the conversation.

More
20 Dec 2016 12:07 #84449 by andypugh
Replied by andypugh on topic Waiting inside M1nn code

But in my case I prefer to use waiting inside M code( because I'm not the only one who will work with the machine and I'm not sure about my partners!). Can you tell me how to wait inside M code and why do you suggest to use M66 instead?
Thanks.


M66 allows you to set a timeout for the wait, and the G-code can be written to take a specific action if a timeout occurs.

You can wait in an M-code. At that point it might be more adaptable for the M-code to be Python rather than bash.
That would allow the M-code (for example) to use c.abort() to halt G-code execution if there is a problem.
linuxcnc.org/docs/2.7/html/config/python-interface.html

Please Log in or Create an account to join the conversation.

More
25 Dec 2016 13:13 - 25 Dec 2016 13:50 #84679 by soroosh.av
Replied by soroosh.av on topic Waiting inside M1nn code
Actually there is no need to do something if there was a problem!! Execution should wait until done signal is received and if it didn't, just continue waiting. For any possible problem PLC will stop everything with emergency stop. So I just need to send two bits and wait until the rise trig of another input.

I'm new to linuxcnc and the worst part is that i didn't worked with python interface before.
1- Where should I write python codes?(I think inside user M code file)
2- Where can I find more explanations or simple examples (related to my case) about python?
3- If it's a simple work, I'll appreciate if someone send me the right codes.
Last edit: 25 Dec 2016 13:50 by soroosh.av.

Please Log in or Create an account to join the conversation.

More
27 Dec 2016 01:20 #84725 by andypugh
Replied by andypugh on topic Waiting inside M1nn code

1- Where should I write python codes?(I think inside user M code file)

Yes. The user M-code can call any executable file, and any file you make executable that begins with #! python will be run by the Python interpreter.

2- Where can I find more explanations or simple examples (related to my case) about python?

Do you want the python code to create HAL pins or do you want it to "know" what to do in HAL? (the former is more portable)

This might help with the first option.
linuxcnc.org/docs/2.7/html/hal/halmodule.html

Please Log in or Create an account to join the conversation.

More
27 Dec 2016 05:43 #84736 by soroosh.av
Replied by soroosh.av on topic Waiting inside M1nn code
I need to read two inputs from HAL and send three outputs to it with some logic instructions.
That link is very helpful. In the example, there is a connection with HAL but it is a float number and i need bits. I think I need these:
h.newpin("in", hal.HAL_BIT, hal.HAL_IN)
h.newpin("out", hal.HAL_BIT, hal.HAL_OUT)

But I need two inputs and three outputs. how is it possible to separate them? Maybe something like:
h.newpin("in1", hal.HAL_BIT, hal.HAL_IN)
h.newpin("in2", hal.HAL_BIT, hal.HAL_IN)

Actually I need both, How to create HAL pins using python and how to link them to parports inside HAL file.

Thank you for your help.
regards.

Please Log in or Create an account to join the conversation.

More
27 Dec 2016 21:09 #84763 by andypugh
Replied by andypugh on topic Waiting inside M1nn code

But I need two inputs and three outputs. how is it possible to separate them? Maybe something like:
h.newpin("in1", hal.HAL_BIT, hal.HAL_IN)
h.newpin("in2", hal.HAL_BIT, hal.HAL_IN)


Yes, exactly like that.

Actually I need both, How to create HAL pins using python and how to link them to parports inside HAL file.


This is why I asked how you want to do it.

In a HAL file you load the Python component exactly like any other component (but with a loadusr rather than loadrt as any Python module has to be Userspace). Then connect the pins up in the usual way.

The other way is to have a Python script that is run once whenever called from a user M-code.

I don't _think_ that you can combine the two methods, ie have a HAL component that connects to HAL pins that also has a function that is callable from an M-code. But it is possible that I am wrong about that.
The following user(s) said Thank You: soroosh.av

Please Log in or Create an account to join the conversation.

Time to create page: 0.093 seconds
Powered by Kunena Forum