Hi All,
I too am having no success getting Mach3 to home my axes.
I have a simple 3 axis gantry. The X-axis has an X-- and an X++ limit switch. The Y-axis has only a Y++ limit switch, and the Z-axis has only a Z++ limit switch. I am using the X--, Y++, and Z++ limit switches as home switches. BTW, all switches are inductive proximity sensors and are active low. They have KFlop bit addresses as follows: X--, X++, Y++, Z++ are assigned bits 0,1,2,3 respectively. They work just fine in KMotion, and Mach3 will stop and wait for a RESET whenever I hit one, just as designed. However, clicking the REF ALL HOME button on the Program Run Screen in Mach3 does absolutely nothing. I am checking in the Console Screen, but see nothing when I click the REF ALL HOME button in Mach3. If I open the C program (that I have assigned to the HOME function in Mach3) in the C Program window within KMotion and then press the Save, Compile, Download, and Run button I see the following:
Mach3 Home Call, flags = 0
Done
Which leads me to believe that the code is working, and the plugin is not being passed any arguments (flags). I am not sure how to debug any further. The code that I have assigned to the HOME function in the Mach3 Plugin Config window (Thread 3, Variable Flags 5) is as follows:
#include "KMotionDef.h"
//Plugin calls for Mach3 Home (actually Purge) Commands
main()
{
int SaveXLimits,SaveYLimits,SaveZLimits; //place to save limit switch settings
int flags = persist.UserData[5]; // Mach3 flags bit0=X, bit1=Y, Bit2=Z, etc...
printf("Mach3 Home Call, flags = %d\n",flags);
if (flags==1)
{
// do X homing here
DisableAxis(0); // Disable X Axis
ch0->InputMode=NO_INPUT_MODE;
ch0->OutputMode=STEP_DIR_MODE;
ch0->Vel=40000;
ch0->Accel=400000;
ch0->Jerk=4e+006;
ch0->P=0;
ch0->I=0.01;
ch0->D=0;
ch0->FFAccel=0;
ch0->FFVel=0;
ch0->MaxI=200;
ch0->MaxErr=1e+006;
ch0->MaxOutput=200;
ch0->DeadBandGain=1;
ch0->DeadBandRange=0;
ch0->InputChan0=0;
ch0->InputChan1=0;
ch0->OutputChan0=0;
ch0->OutputChan1=0;
ch0->MasterAxis=-1;
ch0->LimitSwitchOptions=0x12f;
ch0->LimitSwitchNegBit=0;
ch0->LimitSwitchPosBit=1;
ch0->SoftLimitPos=1e+009;
ch0->SoftLimitNeg=-1e+009;
ch0->InputGain0=1;
ch0->InputGain1=1;
ch0->InputOffset0=0;
ch0->InputOffset1=0;
ch0->OutputGain=1;
ch0->OutputOffset=0;
ch0->SlaveGain=1;
ch0->BacklashMode=BACKLASH_OFF;
ch0->BacklashAmount=0;
ch0->BacklashRate=0;
ch0->invDistPerCycle=1;
ch0->Lead=0;
ch0->MaxFollowingError=1000000000;
ch0->StepperAmplitude=20;
ch0->iir[0].B0=1;
ch0->iir[0].B1=0;
ch0->iir[0].B2=0;
ch0->iir[0].A1=0;
ch0->iir[0].A2=0;
ch0->iir[1].B0=1;
ch0->iir[1].B1=0;
ch0->iir[1].B2=0;
ch0->iir[1].A1=0;
ch0->iir[1].A2=0;
ch0->iir[2].B0=0.000769;
ch0->iir[2].B1=0.001538;
ch0->iir[2].B2=0.000769;
ch0->iir[2].A1=1.92076;
ch0->iir[2].A2=-0.923833;
SaveXLimits = ch0->LimitSwitchOptions; // Save X-axis limit configs
ch0->LimitSwitchOptions = 0; // Disable X-axis limits
EnableAxis(0); // Enable X-axis and begin servoing where we are
// Home X left - jog until it sees the limit
Jog(0,-100); // jog slowly negative (left)
while (ReadBit(0));// loop until IO bit goes low
Jog(0,0); // stop
while (!CheckDone(0)); // loop until motion completes
DisableAxis(0); // disable the axis
Zero(0); // Zero the position
EnableAxis(0); // re-enable the ServoTick
Move(0,1000.0); // move some amount inside the limits
while (!CheckDone(0)); // loop until motion completes
ch0->LimitSwitchOptions = SaveXLimits; // restore limit settings
}
if (flags==2)
{
// do Y homing here
DisableAxis(1); // Disable Y Axis
ch1->InputMode=NO_INPUT_MODE;
ch1->OutputMode=STEP_DIR_MODE;
ch1->Vel=40000;
ch1->Accel=400000;
ch1->Jerk=4e+006;
ch1->P=0;
ch1->I=0.01;
ch1->D=0;
ch1->FFAccel=0;
ch1->FFVel=0;
ch1->MaxI=200;
ch1->MaxErr=1e+006;
ch1->MaxOutput=200;
ch1->DeadBandGain=1;
ch1->DeadBandRange=0;
ch1->InputChan0=1;
ch1->InputChan1=0;
ch1->OutputChan0=1;
ch1->OutputChan1=0;
ch1->MasterAxis=-1;
ch1->LimitSwitchOptions=0x12a;
ch1->LimitSwitchNegBit=0;
ch1->LimitSwitchPosBit=2;
ch1->SoftLimitPos=1e+009;
ch1->SoftLimitNeg=-1e+009;
ch1->InputGain0=1;
ch1->InputGain1=1;
ch1->InputOffset0=0;
ch1->InputOffset1=0;
ch1->OutputGain=1;
ch1->OutputOffset=0;
ch1->SlaveGain=1;
ch1->BacklashMode=BACKLASH_OFF;
ch1->BacklashAmount=0;
ch1->BacklashRate=0;
ch1->invDistPerCycle=1;
ch1->Lead=0;
ch1->MaxFollowingError=1000000000;
ch1->StepperAmplitude=20;
ch1->iir[0].B0=1;
ch1->iir[0].B1=0;
ch1->iir[0].B2=0;
ch1->iir[0].A1=0;
ch1->iir[0].A2=0;
ch1->iir[1].B0=1;
ch1->iir[1].B1=0;
ch1->iir[1].B2=0;
ch1->iir[1].A1=0;
ch1->iir[1].A2=0;
ch1->iir[2].B0=0.000769;
ch1->iir[2].B1=0.001538;
ch1->iir[2].B2=0.000769;
ch1->iir[2].A1=1.92081;
ch1->iir[2].A2=-0.923885;
SaveYLimits = ch1->LimitSwitchOptions; // Save Y-axis limit configs
ch1->LimitSwitchOptions = 0; // Disable Y-axis limits
EnableAxis(1); // Enable Y-axis and begin servoing where we are
// Home Y backward - jog until it sees the limit
Jog(1,100); // jog slowly positive (backward)
while (ReadBit(2)); // loop until IO bit goes low
Jog(1,0); // stop
while (!CheckDone(1)) ; // loop until motion completes
DisableAxis(1); // disable the axis
Zero(1); // Zero the position
EnableAxis(1); // re-enable the ServoTick
Move(1,-1000.0); // move some amount inside the limits
while (!CheckDone(1)) ; // loop until motion completes
ch1->LimitSwitchOptions = SaveYLimits; // restore limit settings
}
if (flags==4)
{
// do Z homing here
DisableAxis(2); // Disable Z Axis
ch2->InputMode=NO_INPUT_MODE;
ch2->OutputMode=STEP_DIR_MODE;
ch2->Vel=40000;
ch2->Accel=400000;
ch2->Jerk=4e+006;
ch2->P=0;
ch2->I=0.01;
ch2->D=0;
ch2->FFAccel=0;
ch2->FFVel=0;
ch2->MaxI=200;
ch2->MaxErr=1e+006;
ch2->MaxOutput=200;
ch2->DeadBandGain=1;
ch2->DeadBandRange=0;
ch2->InputChan0=2;
ch2->InputChan1=0;
ch2->OutputChan0=2;
ch2->OutputChan1=0;
ch2->MasterAxis=-1;
ch2->LimitSwitchOptions=0x12a;
ch2->LimitSwitchNegBit=0;
ch2->LimitSwitchPosBit=3;
ch2->SoftLimitPos=1e+009;
ch2->SoftLimitNeg=-1e+009;
ch2->InputGain0=1;
ch2->InputGain1=1;
ch2->InputOffset0=0;
ch2->InputOffset1=0;
ch2->OutputGain=1;
ch2->OutputOffset=0;
ch2->SlaveGain=1;
ch2->BacklashMode=BACKLASH_OFF;
ch2->BacklashAmount=0;
ch2->BacklashRate=0;
ch2->invDistPerCycle=1;
ch2->Lead=0;
ch2->MaxFollowingError=1000000000;
ch2->StepperAmplitude=20;
ch2->iir[0].B0=1;
ch2->iir[0].B1=0;
ch2->iir[0].B2=0;
ch2->iir[0].A1=0;
ch2->iir[0].A2=0;
ch2->iir[1].B0=1;
ch2->iir[1].B1=0;
ch2->iir[1].B2=0;
ch2->iir[1].A1=0;
ch2->iir[1].A2=0;
ch2->iir[2].B0=0.000769;
ch2->iir[2].B1=0.001538;
ch2->iir[2].B2=0.000769;
ch2->iir[2].A1=1.92081;
ch2->iir[2].A2=-0.923885;
SaveZLimits = ch2->LimitSwitchOptions; // Save Z-axis limit configs
ch2->LimitSwitchOptions = 0; // Disable Z-axis limits
EnableAxis(2); // Enable Z-axis and begin servoing where we are
// Home Z up - jog until it sees the limit
Jog(2,100); // jog slowly positive
while (ReadBit(3)) ; // loop until IO bit goes low
Jog(2,0); // stop
while (!CheckDone(2)) ; // loop until motion completes
DisableAxis(2); // disable the axis
Zero(2); // Zero the position
EnableAxis(2); // re-enable the ServoTick
Move(2,-1000.0); // move some amount inside the limits
while (!CheckDone(2)) ; // loop until motion completes
ch2->LimitSwitchOptions = SaveZLimits; // restore limit settings
}
printf("Done\n");
}
This code is a modification of one of Tom's templates and I think I have it correct, based upon the research I have been doing here in this forum. (Thank goodness for the lot of you!!) I would appreciate any clarity as to how I can rectify this situation.
Cheers,
Jeff