Page 1 of 1

Simple C Program to Z Work Offset

Posted: Sun Oct 07, 2018 7:38 pm
by AlexD85
Hello,
Sorry for possible doubling the post of other user, but I need to clear things a little.
I bought a simple touch plate from Aliexpress for my 3 Axis router with Kflop control.
touch probe.jpg
After reading some information about using DoPCFloat(PC_COMM_SET_X,0.0) I have more questions than answers.
The touch probe is connected via optocoupler board to Pin 6 of JP7. I need a C program that will work as follows:

1. I connect the sensor to an instrument
2. Press the button
3. Z axis starts moving down
4. When instruments touches the sensor it sets G54 Z work offset as 20mm (sensor's height)
5. Z axis moves up for 5-10mm

Most of hobby machines' users don't need a hassle with Tool Lenght Tables etc., just a simple routine like this. Thanks for an upcoming answer.

regards, Alex

Re: Simple C Program to Z Work Offset

Posted: Sun Oct 07, 2018 7:52 pm
by TomKerekes
Hi Alex,

You might look at tthe ProbeZ.c example on how to move Z and stop when the probe triggers:

Code: Select all

#include "KMotionDef.h"

main()
{
    Jog(2,-100);                       // move Z down slowly
    while (!ReadBit(1040)) ;           // wait for switch to go high
    Jog(2,0);                          // Stop
}
The SetFixtureZ.c example shows how to set the current Fixture Offset based on current Position which doesn't involve any Tool Offsets or Tables. You can include some probe offset if you wish.

Code: Select all

#include "KMotionDef.h"

#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"

#define Zaxis 2

main()
{
    int FixtureIndex;
    double NewOriginOffset,OriginOffsetZ;
    double DROx, DROy, DROz, DROa, DROb, DROc;

    GetFixtureIndex(&FixtureIndex);

    GetOriginOffset(&OriginOffsetZ, FixtureIndex, Zaxis);

    GetDROs(&DROx, &DROy, &DROz, &DROa, &DROb, &DROc);
    
    // Adjust Origin Offset to make DRO zero
    NewOriginOffset = OriginOffsetZ + DROz;

    SetUserDataDouble(TMP,NewOriginOffset);
    SetVars(5201+FixtureIndex*20+Zaxis, 1, TMP);

    DoPC(PC_COMM_UPDATE_FIXTURE);
}
HTH

Re: Simple C Program to Z Work Offset

Posted: Sun Oct 07, 2018 8:39 pm
by AlexD85
Hello, Tom
Thank you for your answer. I've attached resulting program, but can't figure out how to include probe offset (20mm) in it.

regards, Alex

Re: Simple C Program to Z Work Offset

Posted: Sun Oct 07, 2018 8:57 pm
by TomKerekes
Hi Alex,

Subtract 20.0 from NewOriginOffset.

Note a call to Jog requires only 2 parameters and needs a semicolon.

A MoveRelAtVel (axis, distance, velocity); would probably be more appropriate.