control axis.N.motor-pos-cmd for Z height control

More
06 Jun 2014 20:25 #47753 by jtc
Hi.

One one machine that we retrofit, we have the need to control the heigth of the Z axis. Based on the mesa THC component, I create a simpler version (height only controled by buttons).

there is the revevant parts of the code:
#*******************
#  AXIS Z
#*******************

setp   pid.z.Pgain     [AXIS_2]P
setp   pid.z.Igain     [AXIS_2]I
setp   pid.z.Dgain     [AXIS_2]D
setp   pid.z.bias      [AXIS_2]BIAS
setp   pid.z.FF0       [AXIS_2]FF0
setp   pid.z.FF1       [AXIS_2]FF1
setp   pid.z.FF2       [AXIS_2]FF2
setp   pid.z.deadband  [AXIS_2]DEADBAND
setp   pid.z.maxoutput [AXIS_2]MAX_OUTPUT

net z-index-enable  <=>  pid.z.index-enable
net z-enable       => pid.z.enable
net z-output       => pid.z.output
net z-pos-cmd      => pid.z.command
net z-vel-fb       => pid.z.feedback-deriv
net z-pos-fb       => pid.z.feedback

# ---PWM Generator signals/setup---

setp   hm2_5i25.0.7i77.0.1.analogout2-scalemax  [AXIS_2]OUTPUT_SCALE
setp   hm2_5i25.0.7i77.0.1.analogout2-minlim    [AXIS_2]OUTPUT_MIN_LIMIT
setp   hm2_5i25.0.7i77.0.1.analogout2-maxlim    [AXIS_2]OUTPUT_MAX_LIMIT

net z-output                             => hm2_5i25.0.7i77.0.1.analogout2
#net z-pos-cmd    axis.2.motor-pos-cmd
net z-enable     axis.2.amp-enable-out

# ---Encoder feedback signals/setup---

setp    hm2_5i25.0.encoder.02.counter-mode 0
setp    hm2_5i25.0.encoder.02.filter 1
setp    hm2_5i25.0.encoder.02.index-invert 0
setp    hm2_5i25.0.encoder.02.index-mask 0
setp    hm2_5i25.0.encoder.02.index-mask-invert 0
setp    hm2_5i25.0.encoder.02.scale  [AXIS_2]ENCODER_SCALE

net z-pos-fb               <=  hm2_5i25.0.encoder.02.position
net z-vel-fb               <=  hm2_5i25.0.encoder.02.velocity
net z-pos-fb           =>  axis.2.motor-pos-fb
net z-index-enable    axis.2.index-enable  <=>  hm2_5i25.0.encoder.02.index-enable
net z-pos-rawcounts        <=  hm2_5i25.0.encoder.02.rawcounts

#Nozzle height control

#enable the nhc
net LigthGreen => nhc.Enable
#Input commanded position
net ZPosCmdIn axis.2.motor-pos-cmd => nhc.ZPosCmdIn
#Input button for increase the offset
net Mud1Button => nhc.OffsetPlus
#Input button for decrease the offset
net Mud2Button => nhc.OffsetMinus
#Output commanded position + offset if exists
net z-pos-cmd  <= nhc.ZPosCmdOut 
#Output feedback position
#net ZFeedbackOut <= nhc.ZFeedbackOut 

and the comp
component nhc "Nozzle Height Control";

description 
"""
Nozzle Height Control

""";
 
author "jtc";

license "GPLv2 or greater";

option singleton yes;

// Input Pins
pin in bit Enable "Enable the THC, if not Enabled Z position is passed through";
pin in float ZPosCmdIn "Z Motor Position Command in from axis.n.motor-pos-cmd";
pin in bit OffsetPlus "increases the Offset of the nozzle";
pin in bit OffsetMinus "decrases the Offset of the nozzle";

// Output Pins
pin out float ZPosCmdOut "Z Motor Position Command Out";
pin out float ZFeedbackOut "Z Position Feedback to Axis";


// Global Variables
variable float Offset=0;

function _;

;;

#include "rtapi_math.h"

FUNCTION(_) {
	
	if(OffsetPlus && Enable){ //increases the offset
		Offset+=0.004;
	}
	if(OffsetMinus && Enable){ //decreases the offset
		Offset-=0.004;
	}
      
    if(Enable){
        ZPosCmdOut = ZPosCmdIn + Offset;
        ZFeedbackOut = ZPosCmdIn; // keep axis motor position fb from being confused
    }
    else{	// !Enable
        ZPosCmdOut = ZPosCmdIn;
        ZFeedbackOut = ZPosCmdIn; // keep axis motor position fb from being confused
    }
}


basically it bypasses the z-pos-cmd and adds a offset. it looks right, it works fine during the execution of the program, but when home and after the execution the program, me Z axis oscillate violently... so, bypass this signal is not so good idea. another disadvantage is that the DRO don't refresh the position(seeing position commanded, what is expected if we are offsetting it after the axis.2.motor-pos-cmd.


So I think the right way to do this, is is possible to implement, is to be able to control the axis.N.motor-pos-cmd, like a jog in manual mode, but in auto mode to.During the machine programs we don't play with Z coordinates, only for the beginning approach and in the end to put the nozzle in a safe height so its safe to jog like that.

This have the advantage of to control it like a regular axis, and have following error/ PID tuning and so on...


How can it be done?

João

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

More
09 Jun 2014 20:59 #47812 by andypugh

How can it be done?


Have you seen the already-existing "offset" component?
www.linuxcnc.org/docs/html/man/man9/offset.9.html

Maybe that solves some of the problems you have seen?

It is likely that you need to ramp-out the offset at a rate that the axis can follow. So, when disabled you should progressively reduce the offset value rather than set it to zero immediately.

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

Time to create page: 0.059 seconds
Powered by Kunena Forum