Hi Michael-Yurov,
Do you want to run this from a GCode program or a User Button?
How about trying it this way?
See the code below. Assign it to M Code M100. Configure it with option Exec/Wait/Sync. It will not change the Machine Coordinates but after it finishes the tool should be at a physical height of 5mm. So then use G92 to set the Program Coordinates to Z of 5mm. So code in GCode:
M100
G92 Z5
#include "KMotionDef.h"
#define TO_CNTS 960.0
#define BLOCK_HEIGHT 1.535
#define FINAL_HEIGHT 5.0
main()
{
Jog(2,-2000); // start moving
while (ReadBit(15)) ; // wait for switch (input #15) to change
// sample the counts where we at the touch block height and
// since we know what that height is compute where to move
// in counts so we will be at the desired final height
Move(2,ch2->Dest + (FINAL_HEIGHT-BLOCK_HEIGHT)*TO_CNTS);
while (!CheckDone(2)) ; // wait till finished
}
Regards