linking and unlinking a pin based on motion-enabled

More
12 Feb 2024 15:07 #293151 by linuxfan
Hi all, 

I have a net lines:

net ATC-pos-cmd  joint.3.motor-pos-cmd => cia402.3.pos-cmd
net ATC-pos-fb      joint3.motor-pos-fb <= cia402.3.pos-fb

net ATC-pos-posthome limit3.0.out => joint3.posthome-cmd

I would like limit3.0.in to be connected to ATC-pos-fb only when controller is disabled - when motion.motion-enabled pin is set to false.
When motion.motion-enabled is true, I would like to disconnect limit3.0.in from ATC-pos-fb, as once controller is enabled, I want to feed my own position into it.
Before controller is enabled and before drives are enabled, I want it to be connected to ATC-pos-fb, as I am using absolute encoders, so no homing is required. But obviously if current position read from encoder is for example 5000, and limit3.0.in is zero or some other position, motor will jump abruptly first time when machine is enabled.

So i'd like to achieve something like this:

If (motion.motion-enabled == false)then
     linksp ATC-pos-fb limit3.0.in
else
    unlinkp limit3.0.in
end

Thanks



 

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

More
12 Feb 2024 16:29 #293153 by PCW
Seems like this would be best done with a "mux2" component

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

More
12 Feb 2024 17:39 - 12 Feb 2024 17:40 #293156 by linuxfan
Thanks for a quick reply. I was suspecting that mux2 would be a way to do this. However I am totally new to linuxcnc.
Would you mind sharing exact code with mux2, that would work for my case?

Thanks
Last edit: 12 Feb 2024 17:40 by linuxfan.

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

More
12 Feb 2024 18:42 #293159 by PCW
This is just an example that sets the limit3 source to
ATC-pos-fb when motion is not enabled and 0
when motion is enabled

loadrt mux2
addf mux2.0 servo-thread

net ATC-pos-fb mux2.in0
setp mux2.0.in1 0
net limit3source mux2.0.out  limit3.0.in
net motion-enabled motion.motion-enabled mux2.0.sel
 

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

More
13 Feb 2024 10:01 #293212 by linuxfan
I tried your approach, and while it works fine for connecting ATC-pos-fb to limit3.0.in, it doesn't achieve my goal regarding disconnecting pin limit3.0.in, as instead of disconnecting it, it connects it to value zero - so pin is again not available for free input value assignment.

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

More
13 Feb 2024 12:04 #293216 by Aciera
replace:
setp mux2.0.in1 0

with:
net alt_input  <your hal signal here>  mux2.0.in1

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

More
13 Feb 2024 12:37 - 13 Feb 2024 13:05 #293217 by linuxfan
You mean like that:
net alt_input limit3.0.in mux2.0.in1 ?
This doesn't work as limit3.0.in is already connected to mux2.0.out 


For what I want to accomplish, it seems that mux won't work, as switching net of signal limit3.0.in from ATC-pos-fb to something else doesn't work for me. Once it has to be connected, and once it has to be disconnected from any other signal. 

To explain what I want to achieve(maybe there is some other, better way of doing it):
When controller is disabled, I want limit3.0.in to get value from ATC-pos-fb, so when controller is back to enable, servo wont jump anywhere, as current commanded position is same as current feedback position. As soon as controller is enabled, previous value has to be retained, but pin limit3.0.in now has to become disconnected from limit3.0.in, so it is available for accepting new values, that would be passed from ngc with MDI setp command.
 
Last edit: 13 Feb 2024 13:05 by linuxfan.

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

More
13 Feb 2024 14:55 - 13 Feb 2024 14:58 #293229 by PCW
What about:

loadrt mux2
addf mux2.0 servo-thread

net ATC-pos-fb mux2.in0
net limit3source mux2.0.out  limit3.0.in mux2.0.in1
net motion-enabled motion.motion-enabled mux2.0.sel

Simpler still would be a sample/hold component
There is a sample_hold component but it uses S32 rather than float.
It would not be a big deal to re-write a float version of it though.
Last edit: 13 Feb 2024 14:58 by PCW.

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

More
13 Feb 2024 15:35 #293231 by tommylight
Forum member Spumco did something about S32 to Float and it worked, more here
forum.linuxcnc.org/10-advanced-configura...ndle?start=10#293042

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

More
13 Feb 2024 16:09 #293233 by PCW
The mux2 example with feedback above does work
as a floating point  sample/hold (just tried)
The following user(s) said Thank You: tommylight

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

Time to create page: 0.077 seconds
Powered by Kunena Forum