How to Control XYZ With a analog Joystick (model: r400b-m4)
19 Dec 2021 23:16 - 19 Dec 2021 23:54 #229524
by Michael
Replied by Michael on topic How to Control XYZ With a analog Joystick (model: r400b-m4)
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.
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.
- Amin Laakel Sofet
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
21 Feb 2024 10:31 #293902
by Amin Laakel Sofet
Replied by Amin Laakel Sofet on topic How to Control XYZ With a analog Joystick (model: r400b-m4)
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 :
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
This is our full .hal file :
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.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19106
- Thank you received: 6398
21 Feb 2024 13:17 #293907
by tommylight
Replied by tommylight on topic How to Control XYZ With a analog Joystick (model: r400b-m4)
From your hal fileshould probably be
loadrt scale names=scale.x,scale.xjog
addf scale.x
addf scale.xjog
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