Controlling a Futaba RC servo with pwmgen type=0

More
12 Sep 2013 04:53 - 12 Sep 2013 09:54 #38678 by cnccircuits
Hi everyone.

This is my first post here on the forum, and i am quite novice in EMC2.

so heres my situation:
i am building a "pick and place" machine to help me install small SMD components on to circuit boards. i have my X, Y and Z axis in my_mill.hal configuration setup so i can translate them using an XBox joypad controller. but i would also like to incorporate a Futaba rc servo or two to also be controlled via the joypad.

during my research on Google i have come to the conclusion that this is entirely doable, but my vaguest of questions is: how?? lol

seriously though, looking at other people's .HAL configurations i can see a few commands that i understand and some that i do not. furthermore even if i try to replicate their setup i would not know how to link the joypad to the PWM output to a particular servo.

the example I have been using is: Rc Servo Test by Kirk Wallace)

using the example; how would i specify that i do not want to open an external window with a slider bar? rather i would like to take a value from something (say the joypad) and feed it into an input for the PWM thread?

are there sites or a good list of basic operations using HAL that might help me to understand the syntax involved in variable assignment? mainly im a little confused about what is holding or returns the value of the joystick axis in a hal script? and what do I assigning to in order to change the pwm?
also im wondering about the flow in a hall script (if calling it a script is even correct. .). is the file my_mill.hal iterated over only once during initialization of pyvcp? does it just configure and then launch threads? how important is the ordering of commands? I only ask because I asigned the joystick on the last line and nothing prior had an issue configuring for it.

also i would like to apologize for the vague nature of this question, i am new to .HAL configs (and even most cnc stuff in general) and dont want to do what i usually do and over analyze the situation.
in fact, i was very skeptical about configuring my joypad until i got into it a little, then it wasn't so intimidating.

Thank you all very much for your insight!

also i will try to thoroughly document what ive done and share it in the HAL Examples section.
Last edit: 12 Sep 2013 09:54 by cnccircuits.

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

More
12 Sep 2013 17:57 #38691 by BigJohnT
This line in Kirk's example is the one that "connects" the slider to the pwm.

net PWMcmd servopyvcp.anaout-f pwmgen.0.value #float

I highly recommend reading this

linuxcnc.org/docs/html/hal/basic_hal.html

JT

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

More
12 Sep 2013 19:39 #38697 by andypugh

i would also like to incorporate a Futaba rc servo or two to also be controlled via the joypad..


A slight problem here is that the RC servo interface is a pulse of 1 to 2ms every 20mS. With a typical base-thread period of 25uS the pulses can be 1.0mS, 1.025mS, 1.05mS etc long, so you won't get great resolution, only 40 possible positions and fewer if your base thread is slower.

If that is acceptable, then changing
net PWMcmd servopyvcp.anaout-f pwmgen.0.value

to
net PWMcmd input.0.abs-x-position pwmgen.0.value

Should link the servo command to the X-joystick on the pendant.

However, note that the slider has a -90 to 90 scale.
The pwm scale is set to 1000, which means that the pwm duty cycle (input * scale + offset) is set to 0.06 to 0.24 (which also matches the duty cycle limits set in the HAL file)
You will have an output of -1 to +1 from the joypad, so will need:
setp pwmgen.0.scale 11.1 to have the same output swing.

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

Time to create page: 0.697 seconds
Powered by Kunena Forum