'clicking' checkbox on pyvcp from gcode

More
17 Jan 2014 17:32 #42910 by eslavko
Hello...

I have run out of input pins so I share spindle rpm sensor and probe input.
At hardware when I attach probe the spindle rpm is just broken. It's works ok.
Now In pyvcp I had the checkbox to tell when probe is attached. So when I attach probe I need to make click to inform that probe is in.
Now the quiestion? How I can simulate click in pyvcp checkbox from G code?
Ie if I attach probe and run hole center for example I want to program do the click before exec G38 and after that to unclick the box.
I can't just tied input to encoder-A and probe as I get probe tripped in non probe move...
(wan't to keep manual acess too)

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

More
17 Jan 2014 18:36 #42912 by ArcEye
Hi

You may need to look at it another way, a checkbox is not too useful an indicator as it just has an OUT pin
Even if you added an IN pin, how would you tell which took priority to set the state?

If you had a LED and a switch for the user input, you could put the switch though a logic component and set the other pin via GCode
(halcmd setp and2.0.in1 1 for instance) , with the output to the LED

Then for instance the Gcode value setting would have to be the same as the user (for and2) , to light the LED.

I assume you have other stuff linked to the signal that would now go to the LED, that deselects probe and re-connects spindle

Just an idea

regards

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

More
17 Jan 2014 19:54 #42913 by eslavko
There is chunks from config.

parport pin is connected to encoderA permanently.
But it's connected to motion.probe.input trought AND gate.
So if enable-probe check is clicked then motion.probe.input gets the
pin value, and same is showed in pyvcp led too.

It works nice.
Of course I can just make other led for enable-probe and change that net
with setp. But then I can't manualy switch the option. So I like to keep
signal as checkbox, but need to find a way to change it's state within
G-code program if it's possible at all.



pyvcp code...
<hbox>
    <boxanchor anchor="w"/>
    <checkbutton>
        <halpin>"enable-probe"</halpin>
        <font>("Helvetica",12)</font>
        <text>"ENABLE PROBE"</text>
    </checkbutton>
    <led>
        <halpin>"probe-pin"</halpin>
        <size>"28"</size>
        <on_color>"green"</on_color>
        <off_color>"red4"</off_color>
    </led>
</hbox>

pyvcp postgui.hal
net enable-probe        <= pyvcp.enable-probe
net myprobe             => pyvcp.probe-pin

HAL
net spindle-phase-a => and2.0.in0 <=    parport.0.pin-15-in #rpm or probe
net spindle-phase-a => encoder.0.phase-A
net enable-probe    => and2.0.in1
net myprobe         <= and2.0.out =>    motion.probe-input

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

More
17 Jan 2014 22:34 #42922 by andypugh

I have run out of input pins so I share spindle rpm sensor and probe input


You only care about the spindle speed when the spindle is on. So forget the checkbox, do it all automatically with the spindle.is-on signal

loadrt and2 count=2
loadrt not count=1
net probe-index parport.0.pin-99-in and2.0.in0 and2.1.in0
net spindle-on motion.spindle-on and2.0.in1 not.0.in
net spindle-not-on not.0.out and2.1.in1

net spindle-index and2.0.out encoder.0.index
net probe-pin and2.1.out motion.probe-in

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

More
17 Jan 2014 23:37 - 18 Jan 2014 01:16 #42925 by ArcEye
Hi

If you want to use the checkbox, then you could change the way it works

The below code, substituted in pyvcp_widgets.py, will create an extra IN pin called pyvcp.{whateveryounamedcheckbox}.changepin

It toggles the state of the checkbox, when set TRUE.
(it will not toggle again until pin goes FALSE to prevent a race condition)

Activating will either check or uncheck the checkbox, depending upon its current state, user click on the checkbox will revert the state.
class pyvcp_checkbutton(Checkbutton):

    """ (control) a check button 
        halpin is 1 when button checked, 0 otherwise 
        <checkbutton>
            [ <halpin>"my-checkbutton"</halpin> ]
            [ <text>"Name of Button"</text>]  text set in widget
            [ <initval>1</initval> ]  sets intial value to 1, all values >=0.5 are assumed to be 1
        </checkbutton>
    """
    n=0
    def __init__(self,master,pycomp,halpin=None,initval=0,**kw):
        self.v = BooleanVar(master)
        Checkbutton.__init__(self,master,variable=self.v,onvalue=1, offvalue=0,**kw)
        if halpin == None:
            halpin = "checkbutton."+str(pyvcp_checkbutton.n)
	self.halpin=halpin
	pycomp.newpin(halpin, HAL_BIT, HAL_OUT)
	changepin = halpin + ".changepin"
	self.changepin=changepin
	pycomp.newpin(changepin, HAL_BIT, HAL_IN)
        pycomp[self.changepin] = 0

	pyvcp_checkbutton.n += 1
		
        if initval >= 0.5:
            self.value=1
        else:
            self.value=0
        self.v.set(self.value)
        self.reset = 0
		
    def update(self,pycomp):
        # prevent race condition if connected to permanently on pin
	if pycomp[self.changepin] and not(self.reset):
    	    self.v.set(not(self.v.get()))
	    self.reset = 1
            pycomp[self.changepin] = 0 # try to reset, but may not work
	if not(pycomp[self.changepin]) and(self.reset):
    	    self.reset = 0 
            pycomp[self.changepin] = 0   # make sure is reset now
	pycomp[self.halpin]=self.v.get()

As with all parsel-tongue, be very careful of indentation if you cut and paste this

You can amend to suit.
For instance: if you will only ever want to uncheck the box, just change the conditional test in update()
so that it only toggles the value in self.v if that value is true.

regards

EDIT added another reset of IN pin to ensure it is done, whatever the result of the conditional test
Last edit: 18 Jan 2014 01:16 by ArcEye.

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

More
18 Jan 2014 00:43 #42929 by eslavko

I have run out of input pins so I share spindle rpm sensor and probe input


You only care about the spindle speed when the spindle is on. So forget the checkbox, do it all automatically with the spindle.is-on signal

loadrt and2 count=2
loadrt not count=1
net probe-index parport.0.pin-99-in and2.0.in0 and2.1.in0
net spindle-on motion.spindle-on and2.0.in1 not.0.in
net spindle-not-on not.0.out and2.1.in1

net spindle-index and2.0.out encoder.0.index
net probe-pin and2.1.out motion.probe-in


Hmm...
Automatic switchower seems nice, but I see the folowing problem:
at the end of program I have mostly like these:

M5 #spindle off
G0 Z100
G0 X0 Y0

So when program hit M5 the spindle is switched off (got signal that doesn't run)
but spindle still turns due to inertia. and when hit G0 Z100 will throw probe triggered during nonprobe move.
But I like that idea...
Probably I need to insert some monostable to be triggered with spindle pulses.
will check that...

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

More
18 Jan 2014 17:43 #42963 by eslavko
Hello...

There is tested automatic switch for probe.
It's quite complex but I think I managed all event's properly.

it have two input pins:
spindle-phase-a is spindle encoder signal (I gave only phase A but quadrature should work too)
spindle-on is actualy motion.spindle-on - the signal for spindle on

and two output pins:
myprobe is filtered probe signal connected to motion.probe-input
probe-dissable when probe isn't monitored (I use this to greyout led in pyvcp)


What/how it works?

When spindle is started (spindle-on goes high) the probe-dissable is set, and myprobe keep unactive.
And this state is held until spindle-on goes false AND at least one second pass from last spindle-phase-a AND index signal is false.
Why?
Just for reason to not trigger 'probe tripped during nonprobe event' error.
As when program ends I turnoff the spindle and start jogging (or put that in code already) machine to 0.0 the spindle itself can still rotate as have high inertia. And when spindle stop it may be with phase A left in true or false. So if it's in true (aka probe hit something) the signal is not pass as it's triger error. But when I switch probe in the signal goes to false (probe not touching) and this reenable probe.

and there is program itself...
#loadrt or2 count=4  #already done elsewhere in HAL (gate 0 and 1 used)
loadrt and2 count=2
loadrt edge count=1
loadrt flipflop count=1
loadrt not count=2

addf or2.2      servo-thread
addf or2.3      servo-thread
addf and2.0     servo-thread
addf and2.1     servo-thread
addf edge.0     servo-thread
addf flipflop.0 servo-thread
addf not.0      servo-thread
addf not.1      servo-thread

setp edge.0.out-width-ns 1000000000         #spindle rpm timeout
setp edge.0.in-edge     false               #rising edge
setp flipflop.0.data    false

net spindle-phase-a     => and2.0.in0
net probe-disable       <= and2.0.in1       <= not.0.out
net probe-enable        <= not.0.in         <= flipflop.0.out
net edge-in             <= edge.0.in        <= and2.0.out
net edge-out            <= or2.2.in0        <= edge.0.out
net spindle-on          => or2.2.in1
net ff-rst              <= flipflop.0.reset <= or2.2.out
net spindle-on          => flipflop.0.clk
net ff-set              <= flipflop.0.set   <= not.1.out
net spindle-on          => or2.3.in0
net spindle-phase-a     => or2.3.in1
net inv-in              <= not.1.in         <= or2.3.out
net probe-enable        => and2.1.in0       
net spindle-phase-a     => and2.1.in1
net myprobe             <= and2.1.out       => motion.probe-input

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

More
04 Feb 2014 22:32 - 04 Feb 2014 23:13 #43542 by tomws

Hi

If you want to use the checkbox, then you could change the way it works

The below code, substituted in pyvcp_widgets.py, will create an extra IN pin called pyvcp.{whateveryounamedcheckbox}.changepin

It toggles the state of the checkbox, when set TRUE.
(it will not toggle again until pin goes FALSE to prevent a race condition)

Activating will either check or uncheck the checkbox, depending upon its current state, user click on the checkbox will revert the state.
...code snipped...

As with all parsel-tongue, be very careful of indentation if you cut and paste this

You can amend to suit.
For instance: if you will only ever want to uncheck the box, just change the conditional test in update()
so that it only toggles the value in self.v if that value is true.

regards

EDIT added another reset of IN pin to ensure it is done, whatever the result of the conditional test


Thank you for providing this! This is just what I was looking for. I need a checkbox that I can reset after a particular operation so that the user always has to click it, if needed, before starting the operation again. I like it!

One newbie question, however. I see in the lib directory that there is a pyvcp_widgets.py file and a pyvcp_widgets.pyc file. If this change is made to the .py file, is there some kind of compile step required to make the .pyc file before it can be used? Update: Ignore this question, I found the answer in your other posts.

Another question, however, is if, instead of 'changepin', I could simply have a 'statepin' where you can actually set the state to 0 or 1? I would think this would be straightforward, but I'm confused by the role of the 'reset' attribute... Perhaps it's to address the fact that this is toggling, rather than setting the value?


Tom
Last edit: 04 Feb 2014 23:13 by tomws. Reason: removed question answered elsewhere.

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

More
04 Feb 2014 23:02 #43546 by ArcEye
Hi

One newbie question, however. I see in the lib directory that there is a pyvcp_widgets.py file and a pyvcp_widgets.pyc file. If this change is made to the .py file, is there some kind of compile step required to make the .pyc file before it can be used?


No, just delete the old .pyc file, edit the .py file and the next time you run a new .pyc will be generated

regards

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

More
17 Jul 2017 15:50 #95909 by MadGuest
Hi, all. I use linuxcnc 2.7.0, and when I add checkbutton to my pyvcp panel, pyvcp.my-checkbutton.changepin is created, but it is always in "False" state. I tried to toggle it with MDI command like #<_hal[pyvcp.my-checkbutton.changepin]> = 1 and got an error message: "Internal error: could not assign #<_hal[pyvcp.my-checkbutton.changepin]>. Please, could someone help me to fix this issue?

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

Time to create page: 0.142 seconds
Powered by Kunena Forum