How to Control XYZ With a analog Joystick (model: r400b-m4)

More
4 years 10 months ago #229267 by Michael
I think the analog jog is setup more for the joypad controllers as it is looking for a value of -1 to +1

Just looking at your joystick picture it appears each direction of the stick is a potentiometer. Assuming you are going to have it powered by 24v then the output range would be 0-24v and that will need to be scaled down to 0-1 using the scale component. On the X+ side just use a scale gain that brings the range down appropriately. On the Y- side use the scale gain as a negative value to scale and convert to the 0 to -1 range.

Both of those scale outputs would be feed into the halui jog pin and could use a mux2 component of you wanted to make it super tidy.

There is probably a better way to do it but this is just a thought.
The following user(s) said Thank You: Kasper-001

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

More
4 years 10 months ago #229415 by Kasper-001
thanks but i think i leave this stand for now, it´s to difficult for me find this out, so i just order a joystick with 4 switch, 

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

More
4 years 10 months ago - 4 years 10 months ago #229456 by Michael
Here is what the hal may look like for X that should scale 24v analog joystick down to -1 to 0 to +1 scale for the analog jog

loadrt scale names=scale.xminus,scale.xplus
addf scale.xminus
addf scale.xplus
#net jog-x-analog  =>  halui.axis.x.analog
net jog-x-analog  <=  scale.xminus.out
net jog-x-analog  <=  scale.xplus.out

setp scale.xminus.gain -0.0417
net x-minus-scale  =>  scale.xminus.in
net x-minus-scale  <=  hm2_7i92.0.7i76.0.0.analogin0

setp scale.xplus.gain 0.0417
net x-plus-scale  =>  scale.xplus.in
net x-plus-scale  <=  hm2_7i92.0.7i76.0.0.analogin1

You should be able to test this without the machine moving. Once you can confirm in hal show that "net jog-x-analog" moves from -1 to +1 correctly you can remove the # and that should jog the axis. I believe the jog speed will be a multiple of your jog speed setting.
Last edit: 4 years 10 months ago by Michael.

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

More
4 years 10 months ago #229476 by Kasper-001
maybe it´s me that don't understand it

the joystick has one potmeter for right and left, one for up and down, and the last one for twisting  

example for readout on pot meter: 
neutral value is 12vdc
left 0vdc
right 24vdc 

so why is the use of 2 analog inputs ? 

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

More
4 years 10 months ago - 4 years 10 months ago #229524 by Michael
I was assuming each direction of the axis had a separate pot. All I had to go off was the picture. If its one pot per axis its pretty simple change to the code above.

loadrt scale names=scale.x,scale.xjog
addf scale.x
addf scale.xjog

setp halui.axis.jog-deadband 0.05

#net jog-x-analog  =>  halui.axis.x.analog
net jog-x-analog  <=  scale.xjog.out

setp scale.xjog.gain .083
net xjog-scale <= scale.x.out
net xjog-scale => scale.xjog.out

setp scale.x.offset -12
setp scale.x.gain 1
net x-scale  =>  scale.x.in
net x-scale  <=  hm2_7i92.0.7i76.0.0.analogin0


The logic for the scale component would be:
out = in * gain + offset
First scale will split the  0 to 24v into -12v to 12v
-12 = 0v * 1 - 12   (full left)
-9 = 3v * 1 - 12   (3/4 left)
0 = 12v * 1 - 12   (no movement)
3 = 15v * 1 - 12   (1/4 right)
12 = 24v * 1 - 12   (full right)

Then you need to bring the scale into the range of -1 to +1 for the "halui.axis.x.analog" signal using the results of the first scale component
-.996 = -12 * .083   (full left)
-.747 = -9 * .083   (3/4 left)
0 = 0 * .083   (no movement)
.249 = 3 * .083   (1/4 right)
.996 = 12 * .083   (full right)

edit: You may be able to work it through a single scale component but would need to verify how it does the math with gain and offset.
Last edit: 4 years 10 months ago by Michael.

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

More
2 years 8 months ago #293902 by Amin Laakel Sofet
Hi, when using the code above we keep getting an error telling us that there are 2 arguments required after the addf command, do you know what the 2nd argument would have to look like or what it could be?
 This is our full .hal file :

File Attachment:

File Name: custom.hal
File Size:2.78 KB

This is the error we're getting

Debug file information:
Note: Using POSIX realtime
./custom.hal:94: addf requires at least 2 arguments, 1 given
2131
Stopping realtime threads
Unloading hal components
Note: Using POSIX realtime

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

Time to create page: 0.067 seconds
Powered by Kunena Forum