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

More
19 Dec 2021 23:16 - 19 Dec 2021 23:54 #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: 19 Dec 2021 23:54 by Michael.

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

More
21 Feb 2024 10:31 #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:3 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
Attachments:

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

More
21 Feb 2024 13:17 #293907 by tommylight
From your hal file
loadrt scale names=scale.x,scale.xjog
addf scale.x
addf scale.xjog
should probably be
loadrt scale names=scale.x,scale.xjog
addf scale.x   servo-thread
addf scale.xjog  servo-thread
The following user(s) said Thank You: Amin Laakel Sofet

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

Time to create page: 0.099 seconds
Powered by Kunena Forum