Can we use python scripts to assign value to hal pins directly.

More
20 Apr 2017 18:13 #91712 by kpj10
Linuxcnc offers feed rates control using HAL pin motion.adaptive-feed. Is there a possible way to directly, using a python script, to assign values to "motion.adaptive-feed".

The python interface suggests
c = linuxcnc.command()
c.feedrate("ENTER REQUIRED FEED RATE")

The problem is: As I'm trying to run reciprocating wire EDM using LinuxCNC I need to reverse my feed. I'm using linuxcnc-mirror-feature-reverse branch to move reverse, but I cannot assign negative feed rates. Adding a slider with the value from -1 to 1, and attaching it to motion.adaptive-feed pin lets me do that in Axis, while the slider is embedded in Axis as pyVCP.

I want python to assign values to motion.adaptive-feed say the values as: 1, 0.65 for forwarding movement or -1, -0.65 for reversing movement.

Also, I'm not able to run reverse using c.auto(linuxcnc.AUTO_REVERSE), in my python script.

The author of feature reverse branch; Robert Ellenberg (genius) suggested a halpin for setting reverse feed, using a single bit, but I think it is still not added for the good reasons Robert know's.

I will be running my python script using the command: rip-environment.

I would be thankful if anyone can help me.

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

More
20 Apr 2017 19:01 #91715 by cmorley
the python module hal will allow you to set pins or params...
Not sure what version that is based on but I bet these commands are valid.

linuxcnc.org/docs/devel/html/hal/halmodule.html#_set_p

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

More
20 Apr 2017 19:07 #91716 by cmorley
Of course the other way is to create a python HAL component and connect it to motion.adaptive-feed.
Either way should work.

Chris M

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

More
20 Apr 2017 19:10 - 20 Apr 2017 19:13 #91717 by kpj10
Ok. I'm trying to do as suggested on the URL Chris suggested. Will report ASAP.

Can you please put more light on this:
"Of course the other way is to create a python HAL component and connect it to motion.adaptive-feed.
Either way should work."


Thank you.
Last edit: 20 Apr 2017 19:13 by kpj10.

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

More
20 Apr 2017 23:22 - 20 Apr 2017 23:23 #91733 by cmorley
Well they are close to the same thing.
The first method uses the python HAL module to change an unconnected HAL pin directly.
This would work well if the pin you want to change is always the same, and has no signal connected.
It also would be good for using in a script called by an Mcode - something only called once in a while.
It would also get screwed up if you accidentally connected a signal to the pin you wish to set.

A HAL component uses the same HAL module but makes a full component with HAL pins that are connected like any other component.
This allow you to easily change connections add logic etc in the HAL file rather then reprogramming the component.

The choice for me probably would come from what is driving the change. If a bunch of python code is driving the required change but is not easily put in a self contained component I would use the first technique.

Without knowing more it's hard to say.

Chris M
Last edit: 20 Apr 2017 23:23 by cmorley.

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

More
21 Apr 2017 04:12 #91744 by kpj10
Dear Chris,

I'm planning to implement a PID controller to set the feed rate. This is how I will work:
1. Take the value of current, most probably using Arduino, and then process it to generate best data within Arduino.
2. Using serial communication transfer the data (amps current value) to the python script from the Arduino.
3. The python script will be adopting PID algorithm to predict the best feed rates to maintain spark gap.

The process needs to be as fast as possible. Now, what would be the best way to do above mentioned process?

I would also like to embed a slider on Axis to also control feed rates, will make it easier for the operator to handle things in a better way.

Thus, there will be two ways the value of feed will be provided.
1. Based on PID algorithm
or when things get ugly
2. Slider on the Axis

Thank You.

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

More
21 Apr 2017 05:59 #91747 by cmorley
ok thats good info.
i would expect the response to current changes must be very fast.

The possible problem with python and serial is they are not realtime so updates can be delayed unpredictably.
i would try to get the current value into realtime as soon as possible.
Then write a realtime component (with comp) that processes the data.
linuxcnc comes with a PID component so maybe you can piece together your logic with existing HAL components.

With relying on non realtime data the computer horsepower becomes much more important.
there must be enough time after all the realtime computing for GUI and userspace components.
and even then the user space programs have no guarantee for response.

What other I/O is available? parallel ports?
Hopefully some others will think of some other ideas...

Chris M

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

More
21 Apr 2017 06:03 #91749 by cmorley
could your Arduino send a digital signal (faster, slower or forward backward) and connect that to a parallel port?
Parallel ports are realtime.

Chris M

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

More
21 Apr 2017 08:19 #91757 by kpj10
At present i'm only using one input and connected it to halpin motion.hold-feed on pin15.

On Arduino I can use the GPIO for sending digital signal, and let Arduino so the PID control algorithm.

There are four other pins: pin10 to pin13 of parallel port not yet used.

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

More
24 Apr 2017 18:26 #91996 by kpj10
Dear Chris,

I'm thinking to monitor two input pins of the parallel port using the ClassicLadder. One to increase the speed the other one to decrease the speed. Is there a way I can connect the ClassicLadder to hal pin motion.adaptive-feed and provide value to it, and still keep a slider, connected on hal pin motion.adaptive-feed, in my axis window to control feed rates from the GUI.

Thank you.

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

Time to create page: 0.191 seconds
Powered by Kunena Forum