Add spinboxes to GUI to input values

More
16 Nov 2020 17:10 #189523 by Jocman
Hi all.
I'm trying to more customize my GUI.
In particular, I'd like to add 3 spinboxes to input 3 values (X, Y, F), then 2 buttons to use these values, in this way
- 1st button: by pressing it, go to the input coordinates XY at speed F
- 2 nd button: by pressing it, add the values (X and Y) to the current position, then go there at the speed F

I started by modifyig custompanel.mxl, creating the 3 spinboxes and the 2 buttons:
<hbox>	
	<vbox>
	
		<relief>RAISED</relief>
		<bd>3</bd>	
		<label text="Valore X"/>
		<spinbox>
			<halpin>"pos_X1"</halpin>
			<min_>0</min_>
			<max_>600</max_>
			<initval>0</initval>
			<resolution>0.1</resolution>
			<format>"2.3f"</format>
			<font>("Arial",20)</font>
		
		</spinbox>

		<label text="Valore Y"/>
		<spinbox>
			<halpin>"pos_Y1"</halpin>
			<width>3</width>
			<min_>0</min_>
			<max_>650</max_>
			<initval>0</initval>
			<resolution>0.01</resolution>
			<format>"2.3f"</format>
			<font>("Arial",20)</font>
		
		</spinbox>

		<label text="Velocità"/>
		<spinbox>
			<halpin>"velocita_1" </halpin>
			<width>3</width>
			<min_>0</min_>
			<max_>1500</max_>
			<initval>1000</initval>
			<resolution>1</resolution>
			<format>"2.3f"</format>
			<font>("Arial",20)</font>
		
		</spinbox>
	</vbox>



	<vbox>
		<button>
			<halpin>"Posizione01"</halpin>
			<text>"Vai alle coord. indicate"</text>
			<font>('fixed',15)</font>
		</button>
		<button>
			<halpin>"Posizione02"</halpin>
			<text>"Aggiungi alle coord. attuali"</text>
			<font>('fixed',15)</font>
		</button>
		
	</vbox>
</hbox>

Then, custom_postgui.hal
net Posizione01 halui.mdi-command-16 <= pyvcp.Posizione01

net Posizione02 halui.mdi-command-17 <= pyvcp.Posizione02

Then my file INI:
#16
MDI_COMMAND = o150 call

#17
MDI_COMMAND = o160 call

Finally, created the macro file:
<pre>
o150sub

#1000 = #<_hal[pyvcp.pos_X1]> 
#1001 = #<_hal[pyvcp.pos_Y1]>
#1002 = #<_hal[pyvcp.velocita_1]>

G0 X[#1000] Y[#1001] F[#1002]

o150 endsub
</pre>

But the thing doesn't work...
After inputting the 3 values and hitting button 1 (go to the coordinates), I get an error message:
Named Parameter #<_hal[pyvcp.pos_X1]> not defined

After a couple of useless tries, I decided to try some test, by modifying the macro.

- 1st try:
G0 X10 Y[#1001] F[#1002]

This time I got the error message
Named Parameter #<_hal[pyvcp.pos_Y1]> not defined

- 2nd try:
G0 X10 Y10 F[#1002]

No error messages, but nothing happens....

By chance, I tried this:
G1 X10 Y10 F[#1002]

The carriage moved to the specified position, at specified speed.

At this point I can't understand.....
The syntax is the same, but why the F parameter is accepted (defined) but X and Y don't?

Why G0 doesn't work but G1?

Andrea

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

More
16 Nov 2020 18:38 #189528 by tommylight
G0 does not use feed rate, it moves at the max allowed by the ini settings.
The following user(s) said Thank You: Jocman

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

More
16 Nov 2020 20:32 #189543 by Jocman
Thanks.
This explain the behaviour between G0 and G1 (my ignorance).
But why the error messages?

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

More
16 Nov 2020 21:15 #189549 by tommylight
There are no defined positions where it is looking for them.
Most probably since #1000 etc means nothing to LinuxCNC if they are not real values somewhere OR there is no hal file connecting the hal pins from or to the Pyvcp panel .

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

More
16 Nov 2020 23:12 #189557 by MaHa
Had a look at your problem, and modified a bit, just able to o<150> call from a program. It followed the input of the scale. When input numbers in scale make shure to hit enter, otherwise the numbers are just there, but not loged.
For test, the file were panel.xml and 150.ngc. Changed capital letters for halpin to lowercase and underline removed.
Entry in ini PYVCP = panel.xml
So you have a working base to finish...

o<150> sub
G1 X#<_hal[pyvcp.posx1]> Y#<_hal[pyvcp.posy1]> F#<_hal[pyvcp.velocita1]>
o<150> endsub
M2

<pyvcp>
	<hbox>	
		<vbox>
	
			<relief>RAISED</relief>
			<bd>3</bd>	
			<label text="Valore X"/>
			<spinbox>
				<halpin>"posx1"</halpin>
				<min_>0</min_>
				<max_>600</max_>
				<initval>0</initval>
				<resolution>0.1</resolution>
				<format>"2.3f"</format>
				<font>("Arial",20)</font>
		
			</spinbox>

			<label text="Valore Y"/>
			<spinbox>
				<halpin>"posy1"</halpin>
				<width>3</width>
				<min_>0</min_>
				<max_>650</max_>
				<initval>0</initval>
				<resolution>0.01</resolution>
				<format>"2.3f"</format>
				<font>("Arial",20)</font>
		
			</spinbox>

			<label text="Velocità"/>
			<spinbox>
				<halpin>"velocita1" </halpin>
				<width>3</width>
				<min_>0</min_>
				<max_>1500</max_>
				<initval>1000</initval>
				<resolution>1</resolution>
				<format>"2.3f"</format>
				<font>("Arial",20)</font>
		
			</spinbox>
		</vbox>



		<vbox>
			<button>
				<halpin>"posizione01"</halpin>
				<text>"Vai alle coord. indicate"</text>
				<font>('fixed',15)</font>
			</button>
			<button>
				<halpin>"posizione02"</halpin>
				<text>"Aggiungi alle coord. attuali"</text>
				<font>('fixed',15)</font>
			</button>
		
		</vbox>
	</hbox>
</pyvcp>
Attachments:
The following user(s) said Thank You: Jocman

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

More
17 Nov 2020 08:12 - 17 Nov 2020 08:17 #189578 by Jocman
About hitting Enter (not the one in the numeric keyboard), I know about this issue, and check it evrytime (without "enter" the values are not "decimal" - it miss the decimal values)

I'll try your suggestion as soon as I back home from workplace.

BTW, to create this feature, I followed the same step used couple of months ago to create a zero procedure for the 3 axis using an aluminium square.
Even in this case, I used 2 spinboxes to enter 2 values (material thickness and bit diameter) and a button to launch a macro.

The structure of the files (INI, HAL, XLM) are similar to the one used for this topic, but in that case the procedure works fine, with no error and no need to delete underlines.

<vbox>
	
		<relief>RAISED</relief>
		<bd>3</bd>
		<label text="Spessore Materiale"/>
		<spinbox>
			<halpin>"spess_materiale" </halpin>
			<min_>0</min_>
			<max_>90</max_>
			<initval>0</initval>
			<resolution>0.1</resolution>
			<format>"2.3f"</format>
			<font>("Arial",20)</font>
		
		</spinbox>

		<label text="Diametro Punta"/>
		<spinbox>
			<halpin>"diam_punta" </halpin>
			<width>3</width>
			<min_>0</min_>
			<max_>8</max_>
			<initval>0</initval>
			<resolution>0.01</resolution>
			<format>"2.3f"</format>
			<font>("Arial",20)</font>
		
		</spinbox>

                 <button>
		      		<halpin>"o107"</halpin>
		     		<text>"X-Y-Z"</text>
		     		<font>('fixed',20)</font>
		</button>

	</vbox>

And similar for the hal file:
net X_Y_Z_touch halui.mdi-command-05 <= pyvcp.o107

And ini file:
#05 X-Y-Z-Touch
MDI_COMMAND = o107 call

Attached is the related macro file, with the same variables.

All this works without any problem, and I just copy/pasted the code and changed the reference.
That's why my puzzlement about the error messages
Attachments:
Last edit: 17 Nov 2020 08:17 by Jocman.

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

More
18 Nov 2020 08:33 #189650 by Jocman
Well, after studying the MaHa suggestions, I decided to make a step-by-step check.
And the first thing I did was relative to the Maha's suggestion about the use of all lowercase letters and no underscores.
After fixing all the lines in the various files, the thing worked perfectly.
The only thing that leaves me a little bit confused is that reading the forum in the past, I read the advice, when operating in HAL environment, to use always lowercase letters and avoid to use "Windows style" characters, like the space, and use the underscore instead of space.
If my mistake about the lowercase is plain, the use of underscore seemed to me recommended. Could it due different versions of LinuxCNC?


Beside the fixed problem, I would ask (keeping the spinboxes problem) how (if possible) can I set the length of the spinbox. currently all my spinboxes are about 10 cm wide, but 2 cm will be more than enough to input a value.
I found a topic in the forum about the same issue, but no solution.
Analyzing some XML files found in several topics, I've seen the use of parameter <width> for spinboxes, and the attached image showing a short spinbox. But in my XLM the parameter gets no effect.
Same even about some buttons, thy are very wide (too wide...) Eventually, the side custom panel steals a lot of space to the axis preview window....

Is there really no way to manage the widget dimensions?

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

More
18 Nov 2020 17:15 #189696 by MaHa
If you set all font to "Arial",10 , its getting slim. And if enclosed within 1 Vbox it doesn't use much space. If length of text is adjusted, the button getting less wide

Attachments:
The following user(s) said Thank You: Jocman

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

More
19 Nov 2020 07:40 #189761 by Jocman
This afternoon I'll try some combination "box/font" and let you know.

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

More
19 Nov 2020 17:42 #189796 by Jocman
Well, it seems the only way to deal with the widget dimensions is playing with the font dimension and the text line length (so as Maha sayd)

Played a little bit with both features, and got a nice results, and doubled the AXIS preview

Thanks very much to all, guys.

Andrea
Attachments:

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

Time to create page: 0.116 seconds
Powered by Kunena Forum