sebba is right and he is describing exactly a homing procedure. So I thought, why not make 2 homings for each axis?
And that's what I did.
This was an interesting exercise, I got to use structs, #events and learn more about macro programming.
Enough said, here is the code. Right now it works only with X, Y and Z, but it can easily be expanded to include A,B and C axes.
You need at least 2 input pins, one for all the proximity sensors and one for all the precision switches. Fast and slow feedrates, up and down the sensors, are individually set for each axis.
Let me know what you think.
- Code: Select all
Config_ Config = new Config_{
//X Axis
X = new AxisConfig{ AxisName = "X",
//Inputs
ProximityPin = new Setting{ Value = 1, ScreenField = 5},
ProximityPort = new Setting{ Value = 2, ScreenField = 245},
MicroPin = new Setting{ Value = 1, ScreenField = 5},
MicroPort = new Setting{ Value = 2, ScreenField = 245},
//Feedrates
FastHomingUp = new Setting{ Value = 1000, ScreenField = 6},
FastHomingDown = new Setting{ Value = 250, ScreenField = 15},
SlowHomingUp = new Setting{ Value = 50, ScreenField = 6},
SlowHomingDown = new Setting{ Value = 10, ScreenField = 15},
//Buttons
HomingButton = 107
},
//Y Axis
Y = new AxisConfig{ AxisName = "Y",
//Inputs
ProximityPin = new Setting{ Value = 2, ScreenField = 20},
ProximityPort = new Setting{ Value = 2, ScreenField = 250},
MicroPin = new Setting{ Value = 2, ScreenField = 20},
MicroPort = new Setting{ Value = 2, ScreenField = 250},
//Feedrates
FastHomingUp = new Setting{ Value = 1000, ScreenField = 21},
FastHomingDown = new Setting{ Value = 250, ScreenField = 30},
SlowHomingUp = new Setting{ Value = 50, ScreenField = 21},
SlowHomingDown = new Setting{ Value = 10, ScreenField = 30},
//Buttons
HomingButton = 108
},
//Z Axis
Z = new AxisConfig{ AxisName = "Z",
//Inputs
ProximityPin = new Setting{ Value = 3, ScreenField = 35},
ProximityPort = new Setting{ Value = 2, ScreenField = 255},
MicroPin = new Setting{ Value = 3, ScreenField = 35},
MicroPort = new Setting{ Value = 2, ScreenField = 255},
//Feedrates
FastHomingUp = new Setting{ Value = 500, ScreenField = 36},
FastHomingDown = new Setting{ Value = 250, ScreenField = 45},
SlowHomingUp = new Setting{ Value = 50, ScreenField = 36},
SlowHomingDown = new Setting{ Value = 10, ScreenField = 45},
//Buttons
HomingButton = 109
}
};
exec.AddStatusmessage( "!!!Double Homing Started!!!" );
DoubleHoming(Config.Z);
DoubleHoming(Config.X);
DoubleHoming(Config.Y);
exec.AddStatusmessage( "!!!Double Homing Finished!!!" );
#Events
int ApplysettingsButton = 168;
struct Setting {
public double Value;
public int ScreenField;
}
struct AxisConfig {
public string AxisName;
//Proximity Input
public Setting ProximityPin;
public Setting ProximityPort;
//Micro Input
public Setting MicroPin;
public Setting MicroPort;
//Feedrates
public Setting FastHomingUp;
public Setting FastHomingDown;
public Setting SlowHomingUp;
public Setting SlowHomingDown;
//Buttons
public int HomingButton;
}
struct Config_{
public AxisConfig X;
public AxisConfig Y;
public AxisConfig Z;
}
void DoubleHoming(AxisConfig AC)
{
//Fast homing
exec.AddStatusmessage( "- Fast Homing " + AC.AxisName + " Axis -");
//set proximity as home sensor
setFieldValue(AC.ProximityPin);
setFieldValue(AC.ProximityPort);
//set fast feedrates
setFieldValue(AC.FastHomingUp);
setFieldValue(AC.FastHomingDown);
//Applysettings
exec.Callbutton(ApplysettingsButton);
//home axis
exec.Callbutton(AC.HomingButton);
while(exec.IsMoving()){}
//Slow homing
exec.AddStatusmessage( "- Slow Homing " + AC.AxisName + " Axis -");
//set precision switch as home sensor
setFieldValue(AC.MicroPin);
setFieldValue(AC.MicroPort);
//set slow feedrates
setFieldValue(AC.SlowHomingUp);
setFieldValue(AC.SlowHomingDown);
//Applysettings
exec.Callbutton(ApplysettingsButton);
//home axis
exec.Callbutton(AC.HomingButton);
while(exec.IsMoving()){}
}
void setFieldValue(Setting s){
AS3.Setfield(s.Value, s.ScreenField);
AS3.Validatefield(s.ScreenField);
}