Hi Mark,
You might try this:
Code:
#include "KMotionDef.h"
// Vary the backlash linearly between 3 points (NegEnd, Middle, PosEnd)
#define XAXIS 0
#define XRes 10000.0 // counts/inch
#define XNegEndDest ( 0.0 * XRes) // counts
#define XPosEndDest (20.0 * XRes) // counts
#define XNegEndBacklash (0.001 * XRes) // backlash counts at negative end of travel
#define XMiddleBacklash (0.005 * XRes) // backlash counts middle
#define XPosEndBacklash (0.002 * XRes) // backlash counts counts at positive end of travel
#define XMiddleDest ((XNegEndDest + XPosEndDest)*0.5) // counts
#define XNegSlope ((XMiddleBacklash - XNegEndBacklash) / (XMiddleDest - XNegEndDest))
#define XPosSlope ((XPosEndBacklash - XMiddleBacklash) / (XPosEndDest - XMiddleDest))
void ServiceBacklashX();
double Interpolate(double x0, double x, double y0, double Slope);
void main()
{
for (;;)
{
ServiceBacklashX();
}
}
void ServiceBacklashX(void)
{
if (chan[XAXIS].Dest < XMiddleDest) // check which section we are in
chan[XAXIS].BacklashAmount =
Interpolate(XNegEndDest, chan[XAXIS].Dest, XNegEndBacklash, XNegSlope);
else
chan[XAXIS].BacklashAmount =
Interpolate(XMiddleDest, chan[XAXIS].Dest, XMiddleBacklash, XPosSlope);
}
// linear interpolation along line defined by point and slope
double Interpolate(double x0, double x, double y0, double Slope)
{
double y = (x - x0) * Slope + y0;
if (y < 0.0) // limit to positive
y = 0.0;
return y;
}