ENCODER_RATIO function implementation.

More
03 Apr 2025 06:04 #325588 by Boogie
Gents,

Continuing my learning process of LinuxCNC and Mesa cards i've managed (thank you PCW and tommylight!), to start my permanent magnet DC servomotor driven by BTS7960 H-bridges, all hooked up to Mesa 7i95T on the test bench.
forum.linuxcnc.org/configuration-tools/5...-bridges-pmdc-servos

Did some basic PID tuning and motors are not reaching following errors. Ferror is loose however - fine tuning not required at this stage.
On my learning short list now there is two topics:
1) encoder-ratio module
2) Mesa THCAD card. As I'm powering my motors and limit/home switches from old laptop power supply - its voltage sags easily when loading servos so found it good opportunity to practice THCAD and PyVCP by reading power supply voltage and present it on AXIS. 

Ad 1) While reading LinuxCNC documentation i found an interesting function ENCODER_RATIO. First thought was "hey! let's do some experiment and slave Z axis servo to X.". Let's say the final idea is to link spindle encoder with rotary/dividing head servo - i can imaging hobbing gears like that:)
Experiment conditions:
- there is three servos available X, Y, Z so three encoders, all the same ppr = 400
- X will be the master, Z will be slave
- i want Z to turn 4 times slower than X

If i understand the documentation right i did the following:
- detached joint.2.motor-pos-cmd from pid.z.command
- detached hm2_7i95.0.encoder.02.position from pid.z.feedback and joint.2.motor-pos-fb
- connected pid.z.feedback and joint.2.motor-pos-fb with encoder-ratio.0.error
- decided to use one of the switches for slave axis on/off so detached remote e-stop (will not using it now) input hm2_7i95.0.inmux.00.input-06-not and hooked it up to encoder-ratio.0.enable
- connected master axis (X) encoder signals A and B to encoder-ratio.0.master-A and encoder-ratio.0.master-B
- connected slave axis (Z) encoder signals A and B to encoder-ratio.0.slave-A and encoder-ratio.0.slave-B
- set ratio by stating ppr: encoder-ratio.0.master-ppr 400 and encoder-ratio.0.slave-ppr 100

AXIS started with no issues. Checked HAL configuration and what i can see is:
- encoder-ratio.0.master-A and B signals are successfully connected to X encoder
- encoder-ratio.0.enable is ok - turning TRUE when switch is activated by me

And i failed successfully:)
- i can see no change on pid.z.feedback as well as on pid.z.output when i move X axis - no change on encoder-ratio.0.error 

I thing i'm not getting fully what manula says about encoder_ratio. i couldn't find any HAL examples showing correct configuration.
What i found is that unfortunatelly encoder-ratio.0.master-ppr and encoder-ratio.0.slave-ppr are PARAMETERS, not PINS so no chance to make nice 'change ratio' option in PyVCP (imagine you can input different spindle/slave axis ratio and hob whatever spur gear you want!). The only option i see it close LinuxCNC, edit ppr numbers and re-start LinuxCNC to get ratio i want.

My idea was to have motorized dividing head connected and with just one switch make it move in sync with spindle @ required ratio...So it is basically ELS. Ehmmm those dreams.

Anyway, please! Could you guys look at it and poke me in good direction? I did research and tried by myself before i bother you but, as i said before, failed successfully:)
Thank you.
Attachments:
The following user(s) said Thank You: tommylight

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

More
03 Apr 2025 12:07 #325611 by andypugh
Replied by andypugh on topic ENCODER_RATIO function implementation.
I have never found a use for encoder_ratio, at least partly because it relies on software-counting of the A and B phases.

If you are using a Mesa card then encoder_ratio won't help you.

But gear hobbing is nevetheless very possible. I do it regularly. I invented the idea of electronically geared hobbing, but I probably didn't invent it first :-)

wiki.linuxcnc.org/cgi-bin/wiki.pl?Hobbing

Note that due to a problem with a certificate on the server that hosts the Wiki, https won't work. This means that to download the linked zip file you will need to copy the URL, edit out the "s" in "https" and then paste the URL back into the address bar. Sorry about this.
The following user(s) said Thank You: Boogie

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

  • scotth
  • Away
  • Elite Member
  • Elite Member
More
03 Apr 2025 14:29 #325618 by scotth
Replied by scotth on topic ENCODER_RATIO function implementation.
The first CNC hob I worked with was a Pfauter PE 150 with an Allen Bradley 7300 and the Pfauter EGB (electronic gear box). 1983

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

  • scotth
  • Away
  • Elite Member
  • Elite Member
More
03 Apr 2025 14:43 #325620 by scotth
Replied by scotth on topic ENCODER_RATIO function implementation.
The EGB would add or subtract pulses to the table for helical gears based on hob height, as well as handling hob and table speed.

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

More
04 Apr 2025 06:19 #325661 by timo
Replied by timo on topic ENCODER_RATIO function implementation.
Did this machine run the hob with a hydraulic motor for the hob spindle?

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

  • scotth
  • Away
  • Elite Member
  • Elite Member
More
04 Apr 2025 14:57 #325688 by scotth
Replied by scotth on topic ENCODER_RATIO function implementation.
VF induction with a large flywheel to smooth out any variation during the cut.

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

More
04 Apr 2025 17:31 #325698 by Boogie
Replied by Boogie on topic ENCODER_RATIO function implementation.
Wasn't expect that:/ Any practical use for ENCODER_RATIO then? I believe this is the point related to is in documentation:
"
encoder-ratio.sample

Read all input pins. Must be called at twice the maximum desired count rate."

Why can't we use encoder.0.position? Or it is just the way this component is coded? Anyway why would it be a problem? Is it because of the encoder-ratio.sample call frequency required?

ZIP download was ok. Trying to wrap my head around it.

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

More
04 Apr 2025 19:24 #325707 by andypugh
Replied by andypugh on topic ENCODER_RATIO function implementation.
Encoder_ratio is coded to count A/B phases (in software) from two encoders and to output a difference to drive a PID.
It would potentially be rather useful for a parallel port based machine, or maybe a Pi using GPIO. I expect it is fast and efficient, as it needs to do very little calculation.
But on systems where the positions are already calculated, you really can do it more simply with HAL maths functions (or the custom comp that my hobber uses)
The following user(s) said Thank You: Boogie

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

More
09 Apr 2025 09:14 #325975 by Boogie
Replied by Boogie on topic ENCODER_RATIO function implementation.
I'm trying to mix pwm servos configuration i managed to work finally with your hobbing Andy. I thought there is two options to add something to AXIS - gladeVCP and pyVCP made panels. When i saw you don't have an XML file in the folder you shared with us i thought it is made with gladeVCP. But the i saw some tutorials on yt and 'they' say that for glade-made-panels there should be panel.glade file along with panel.py (plus panel.pyc created by AXIS once is it first time started).
Here is your files and my assumptions on them:
- hobbing.py  (looks like the panel fils, defining its features, making cals on user inputs, is it a stand alone program or is attached to AXIS?)
- hobbing.ui (looks like the graphical axpect of the panel, using XML formatting - similar to XLM file in pyVCP)
- hobbing_gui.hal (connection file between panel and HAL)
- hobbing.ngc (actual NC file containing hobbing cycle, controlling all the axes involved, speciffic to your setup).

Are those files a separate "hobbing software"? I mean standalone panel using linuxcnc started in the background but not using AXIS? I can see in hybbing.py that you are importing linuxcnc, hal and other mysterious modules and see some linuxcnc.start(), linuxcnc.command() ocmmands inside. This is givimg me the impression is it not connected to AXIS gui but rather standalone "module"/interface.

I can see on wiki, you say "...the only other things needed are a Pyvcp panel with a spinbox in it for tooth count...". But, based on the tutorials i saw, why there is hobbing.ui instead of hobbing.xml?

I'll try some iterations with those files but i need to made more changes to my configuration due to the fact that all the toys i have on my test bench are 7i95t, 3 servos, 3 h-bridges and 7 microswitches, so adding my "inexperience" is giving me a headache. Will turn Z axis into A axis and Y servo will turn into a spindle with encoder so in the end i will have a system with X axis only, spindle with encoder and A-slave-axis.

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

More
09 Apr 2025 15:24 #325992 by andypugh
Replied by andypugh on topic ENCODER_RATIO function implementation.
The info on that Wiki page is possibly a bit confusing as it combines a HAL config that I used initially, with the GUI that I use with a more developed version.

The .ui file is a GladeVCP and would be loaded by a line in the INI like:
[DISPLAY]
...
EMBED_TAB_COMMAND=gladevcp -c hobbing_gui -x {XID} -H ./hobbing_gui.hal -u hobbing.py ./hobbing.ui

I also seem to have fogotten to mention the custom "hobbing" HAL component. This is installed from the attached file with the command "sudo halcompile --install hobbing.comp"

This is then loaded in the main HAL file with:
loadrt hobbing
addf hobbing.0      servo-thread

(It looks like I need to re-write that Wiki page)
Attachments:
The following user(s) said Thank You: Boogie

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

Time to create page: 0.189 seconds
Powered by Kunena Forum