Lathe bed mapping - surface inequalities compensation

More
26 Apr 2019 09:58 #131937 by szary11
Hi,
We are struggling over the subject of mapping the lathe bed which is worn and unequal in some places - as an alternative to grinding whole bed.
We measure the bed in certain Z intervals and the corresponding height correction, then calculate slope between points and describe the surface as collection of linear functions. Then the offset H is converted into an offset X having taken into account the diameter of the workpiece.
We still have some issues and are hoping someone might come up with some advice.

What was accomplished so far:
1. Created and implemented realtime hal component which calculates X (tool) offset based on bed map and current Z and X position.
File lathe_bed.comp needs to be compiled first

sudo halcompile --install lathe_bed.comp

, file content below:
component lathe_bed;
license "GPL"; // GPL v2 or later
pin in float x_rel_in;  //relatywne wspolrzedne X
pin in float x_motor_in;  //maszynowe polozenie X
pin in float z_in;         //maszynowe polozenie Z
pin in touchoff-h-adjust;   //AKTUALNIE NIE DZIALA - korekta loza w momencie bazowania do materialu
pin out float x_out;
function _;
;;
#include <math.h>
#include <stdlib.h>

float z_pos_array[5] = {-750, -700, -100, -50, 0};
float h_corr_array[5] = { 0.0, 0.0, 0.0, 0.4, 0.0};
float slope_array[5] = {0.0, 0.0, 0.0, -0.008, 0.008};


float slope = 0.0;
float z_range_high = 0.0;
float h_high = 0.0;
float x_offset = 0.0;
float h_offset = 0.0;
float r;
int size = sizeof(z_pos_array)/sizeof(z_pos_array[0]);
float sqrt_val;

FUNCTION(_){

    for(int i=0; i<size; i++){
        float z_limit = z_pos_array[i];
        if(z_in <= z_limit){
            z_range_high = z_limit;
            h_high = h_corr_array[i];
            slope = slope_array[i];
            break;
        }
        else{
			slope = 0;
			h_high = 0;
        }
    }
    r = x_rel_in;
    //Circle equation : x^2 + h^2 = r^2
    //x_offset = r - x
    //x_offset = abs(r) - sqrt(pow(r,2) - pow(h_offset, 2));
    
    h_offset = (z_range_high - z_in)*slope + h_high;
    h_offset = h_offset - touchoff-h-adjust  //AKTUALNIE NIE DZIALA - na biezaco korekta H zoffsetowana ezgledem punktu bazowania do materialu

    sqrt_val = sqrt(abs((pow(r,2) - pow(h_offset, 2))*100000.0f)/100000.0f);
    x_offset = abs(r*1000.0f)/1000.0f - roundf(sqrt_val*1000.0f)/1000.0f;
    x_offset = abs(x_offset * 1000.0f) / 1000.0f;

    if(r>0){
        x_offset = -x_offset;
    }
    else{
         x_offset = x_offset;
    }
    x_out = x_motor_in + x_offset;
}

2. Component added and connected in machine HAL file (please see comments)
loadrt lathe_bed
addf lathe-bed.0 servo-thread

net x-pos-rel <= halui.axis.0.pos-relative
net x-pos-rel => lathe-bed.0.x-rel-in
net x-pos-cmd => lathe-bed.0.x-motor-in
net z-pos-cmd => lathe-bed.0.z-in 


#calc base height adjustment offset when setting X axis offset (press "END")  - CURRENTLY NOT WORKING
loadusr axisui -name axisui.0   #???
#net z-pos-cmd  => axisui.machine-z-in   # - HAL DOES NOT RECOGNIZE AXISUI PINS
#net base_height_correction axisui.touchoff-h-adjust => lathe-bed.0.touchoff-h-adjust  

net x-pos-cmd-corr <= lathe-bed.0.x-out
net x-pos-cmd-corr   =>  pid.x.command

What is missing:
1. In the moment of basing tool relative to material we touch the material, then set X offset (in GUI X -> press END -> enter workpiece diameter). Now program should also capture current Z postion to know what is the current lathe bed height difference and what initial H offset to use for further realtime calculation. For that I've modified "axis" file in /usr/bin as follows:
a) Added function that should be triggered at the moment of offsetting X axis and:
- read current machine Z position - from HAL pins?
- calculate Height offset of the bed
- return offset as Pin output which should then be inputted to realtime component
Function is triggered from within

def touch_off_system

def touch_off_system(event=None, new_axis_value = None):
        global system
        if not manual_ok(): return
        if joints_mode(): return
        offset_axis = "xyzabcuvw".index(vars.current_axis.get())
        if new_axis_value is None:
            new_axis_value, system = prompt_touchoff(
                title=_("Touch Off (system)"),
                text=_("Enter %s coordinate relative to %%s:") % vars.current_axis.get().upper(),
                default=0.0,
                tool_only=False,
                system=vars.touch_off_system.get()
                )
        else:
            system = vars.touch_off_system.get()
        if new_axis_value is None: return
        vars.touch_off_system.set(system)
        ensure_mode(linuxcnc.MODE_MDI)
        s.poll()
#FUNCTION CALL
        if offset_axis == "x":
            capture_bed_height_offset()
            
        #rest of the code was skipped...

and function code itself:
    def capture_bed_height_offset():

        z_in = comp["machine-z-in"] #pobierz z Pinu aktualny Z
        z_pos_array = [-750, -700, -100, -50, 0]
        h_corr_array = [0.0, 0.0, 0.0, 0.4, 0.0]
        slope_array = [0.0, 0.0, 0.0, -0.008, 0.008]

        for i in range(0, len(z_pos_array)):
            z_limit = z_pos_array[i]
            if z_in <= z_limit:
                z_range_high = z_limit
                h_high = h_corr_array[i]
                slope = slope_array[i]
                break
        h_offset = float((z_range_high - z_in)*slope + h_high)
        comp["touchoff-h-adjust"] = h_offset

b) added two new pins in "axix" file
- input which imports current Z machine position
- output should return height adjustment value
if hal_present == 1 :
    comp = hal.component("axisui")
    comp.newpin("jog.x", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.y", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.z", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.a", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.b", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.c", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.u", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.v", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.w", hal.HAL_BIT, hal.HAL_OUT)
    comp.newpin("jog.increment", hal.HAL_FLOAT, hal.HAL_OUT)
    comp.newpin("notifications-clear",hal.HAL_BIT,hal.HAL_IN)
    comp.newpin("notifications-clear-info",hal.HAL_BIT,hal.HAL_IN)
    comp.newpin("notifications-clear-error",hal.HAL_BIT,hal.HAL_IN)
    comp.newpin("resume-inhibit",hal.HAL_BIT,hal.HAL_IN)
    #NEWLY ADDED PINS BELOW
    comp.newpin("machine-z-in",hal.HAL_FLOAT,hal.HAL_IN)
    comp.newpin("touchoff-h-adjust",hal.HAL_FLOAT,hal.HAL_OUT)

NOW, THE ACTUAL PROBLEM:
HAL does not see AXISUI pins (axis and hal code above). Any ideas how can we solve/bypass it? We need to capture Z position while pressing "END" in GUI and offsetting X value. Maybe someone has some better ideas how to achieve desired functionality?

Many thanks in advance!

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

More
26 Apr 2019 11:40 - 26 Apr 2019 11:42 #131943 by rodw
Before you go too much further have a look at external offsets ( in the master development branch). The word external comes from the fact that its external to the trajectory planner which means you can make adjustments via an axis offset that the trajectory planner does not know about.

So I think your algorithm should calculate an offset and apply it to the axis you want to adjust. Then touchoff has no bearing on the problem as if you use this method, all axes should be square and linear.
Last edit: 26 Apr 2019 11:42 by rodw.

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

More
26 Apr 2019 12:44 - 26 Apr 2019 12:49 #131946 by szary11
Thanks for response. The issue is those axis.L.eoffset pins are not recognized in my configuration. Instead of figuring this out I'd by happy to stick to what I already did (although not perfect) at least for time being to get this working.
The second argument is I don't want a constant "flow" of Z offsetted position, I need a "snapshot" of Z position from the moment where tool is based to material.
The obstacle is - how to make HAL recognize

axisui.

pins? Guess that would be the quickest solution possible in my case
Last edit: 26 Apr 2019 12:49 by szary11.

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

More
26 Apr 2019 13:41 - 26 Apr 2019 13:42 #131952 by rodw
I get that if the tool sits lower due to wear that the actual diameter being machined changes. I see that you know how to do the maths to calculate this. So you know the offset to apply at any given point from your mapping data.

This week I threw out hundreds of hours of development I had undertaken by adopting another paradigm within the LinuxCNC community. The improvement was well worth it and encapsulated the work I had contributed as well as work from many others. Versions before V 2. 8 are quite obsolete becasue of some significant new features that have been added.

To ignore these improvements might hold you back.

You could calculate the offset continuously and sample it on a touchoff. and apply the offset. Or do your calculations as you are doing now and apply the offset you need. Either way, you are not fighting the trajectory planner becasue you will be working within the (new and improved) Linuxcnc motion control paradigm.
Last edit: 26 Apr 2019 13:42 by rodw.

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

More
26 Apr 2019 13:52 #131955 by rodw
It might not be 100% what you want but this thread shows how to adjust for a non square axis so it might give you some ideas.

forum.linuxcnc.org/10-advanced-configura...-axis-errors?start=0

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

More
26 Apr 2019 16:09 #131980 by andypugh
I think that just considering bed height is missing an important issue.

If the front and back ways are worn differently (and they typically will be) then the carriage with rotate about the Z axis, and this will give much bigger diameter variations than a simple height change would.

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

More
26 Apr 2019 16:42 #131997 by szary11
That's actually good point we didn't take into consideration, thanks! We will fine-tune our calculations at later stage, for now just need to launch the whole thing

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

Time to create page: 0.078 seconds
Powered by Kunena Forum