SPINDLE INDICATOR (3 STate)

More
27 Sep 2015 12:47 - 27 Sep 2015 15:22 #63049 by Askjerry
I have become pretty good at making pyVCP panels now... and I want to create one for a University machine. The machine has a spindle that can go CW or CCW... and looking at the machine signals I can see there are...

spindle-ccw = 0 of the spindle is OFF or in CW mode, 1 if running in CCW mode.
spindle-cw = 0 of the spindle is OFF or in CCW mode, 1 if running in CW mode.

So I want to make an indicator to show one of three graphic images...

0 = spindle-stop.png
1 = spindle-forward.png
2 = spindle-reverse.png

The actual pyVCP part is easy...
<image name="spindle-stop" file="./IMAGES/spindle-stop.png"/>
<image name="spindle-forward" file="./IMAGES/spindle-forward.png"/>
<image name="spindle-reverse" file="./IMAGES/spindle-reverse.png"/>
<image_bit halpin="SPINDLE-STAT" images="spindle-stop spindle-forward spindle-reverse"/>


If I were writing a program in BASIC or some other language... I would do something like this...

S = (spindle-reverse*2) + spindle-forward

And we should never see S=3 unless something really bizarre occurs.

So... what do I set up in the HAL file to evaluate something like this and assign it to something like... SPINDLE-STAT for example?

Once I know that part... I should be able to design something nice.

Thanks,
Jerry
Last edit: 27 Sep 2015 15:22 by Askjerry.

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

More
27 Sep 2015 13:55 #63051 by Askjerry
Well... after doing some reading... I finally figured out how to do it.

You need to use WEIGHTED SUM
# -----------------------------------------------------------------------------------------------
# Build the SPINDLE-STAT signal for driving the PYVCP panel display.
# We need two inputs to make 00, 01, 10, or 11. (In theory, we will never get 11.)

loadrt weighted_sum wsum_sizes=2
addf process_wsums servo-thread

# connect the inputs to the wsum component
net bit-1 wsum.0.bit.0.in <= halui.spindle.runs-forward
net bit-2 wsum.0.bit.1.in <= halui.spindle.runs-backward

# connect the output to a new signal called spindle-stat
net spindle-stat <= wsum.0.sum
# -----------------------------------------------------------------------------------------------

This gets the signal spindle-stat into the system with an output of 0,1,2 depending on the status of the spindle.

From here I should be able to assign it pretty easy.
Jerry

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

More
27 Sep 2015 15:31 - 27 Sep 2015 15:54 #63052 by Askjerry
Not quite so easy...

The image uses a u32 input, but the output from the Weighted Sum is a s32 output. This means it must be converted... and you need to load another function into the mix.
Here is the final solution...
# -----------------------------------------------------------------------------------------------
# Build the SPINDLE-STAT signal for driving the PYVCP panel display.
# We need two inputs to make 00, 01, 10, or 11. (In theory, we will never get 11.)

loadrt weighted_sum wsum_sizes=2
addf process_wsums servo-thread

# connect the inputs to the wsum component
net bit-1 wsum.0.bit.0.in 	<= halui.spindle.runs-forward
net bit-2 wsum.0.bit.1.in 	<= halui.spindle.runs-backward
net spindle-stat 		<= wsum.0.sum

loadrt conv_s32_u32
addf conv-s32-u32.0 servo-thread

net spindle-stat		=> conv-s32-u32.0.in
net panel-spindle-status	<= conv-s32-u32.0.out 
net panel-spindle-status	=> pyvcp.spindle-stat
# -----------------------------------------------------------------------------------------------

Here I thought it would be an easy line or two. :unsure: But hey... it works! :laugh:

Jerry
Last edit: 27 Sep 2015 15:54 by Askjerry. Reason: Add information and update

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

More
28 Sep 2015 04:22 #63092 by andypugh
As an alternative you could have written a simple user component. It would at least hide the complexity from HAL.

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

More
28 Sep 2015 04:23 #63093 by andypugh
I just thought of another way to do it. You could use a mux_generic set to u32 output which has two inputs, one for each spindle direction.
The following user(s) said Thank You: Askjerry

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

More
28 Sep 2015 04:38 - 28 Sep 2015 04:46 #63094 by Askjerry
MUX GENERIC huh... I'll look that up and tinker with it.

Found it --> linuxcnc.org/docs/html/man/man9/mux_generic.9.html

I appreciate the help... I've been learning this on my own... try-fail-try again.

All I could think of was that if it had "A" and wanted "B"... that we needed to convert "A" to "B"... so that was what I searched on...

I'm helping a University in Norway (Telemark University College)... they will try the new pyVCP out tomorrow. If all goes well... then I'll research this and update the files for the next version... and post the modifications here for future researchers.

Thanks again!
Jerry
Last edit: 28 Sep 2015 04:46 by Askjerry.

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

More
28 Sep 2015 04:54 - 28 Sep 2015 04:55 #63095 by andypugh
(Untested)
loadrt mux_generic config = "uu4"
setp mux-gen.00.in-u32-00 0
setp mux-gen.00.in-u32-01 1
setp mux-gen.00.in-u32-02 2
setp mux-gen.00.in-u32-03 0
net fwd motion.spindle-fwd mux-gen.00.sel-bit-000
net fwd motion.spindle-rev mux-gen.00.sel-bit-001

net output mux-gen.00.out-u32 => pyvcp....
Last edit: 28 Sep 2015 04:55 by andypugh.

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

More
28 Sep 2015 05:07 - 28 Sep 2015 05:11 #63097 by Askjerry
I'll have to experiment... the players in this panel are as follows...

INPUTS
<= halui.spindle.runs-forward
<= halui.spindle.runs-backward

OUTPUT
=> pyvcp.spindle-stat

The actual pyvcp widget is...
<image_u32 halpin='spindle-stat' images='spindle-stop spindle-forward spindle-reverse'/>

And the images are...








It looks really good... I'll have to digest your data and give it a try!
I'll attach the whole machine... in case anyone else wants to play with it.

File Attachment:

File Name: BoxfordCNC_MAX.zip
File Size:529 KB
Attachments:
Last edit: 28 Sep 2015 05:11 by Askjerry.

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

More
28 Sep 2015 05:11 #63098 by andypugh
I have never got round to figuring out the difference between the motion and halui spindle direction pins. But given a choice I always prefer motion (realtime) to halui (userspace) pins.

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

More
28 Sep 2015 05:13 #63099 by Askjerry
I was trying the motion... but it looked like they were control pins and the halui was an output (result) pin... but hey... still learning.

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

Time to create page: 0.151 seconds
Powered by Kunena Forum