Hi Clayton,
That would depending on how you want to "Zero" the coordinate system (change Fixture Offset, change G92 offset, or change tool table).
For Fixture Offset you might combine
ProbeZ.c
and
SetFixtureZ.c
with a final Move up.
Regards
I am trying to to find a simple C program to use for auto tool zeroing. I have seen a couple versions of what I need but can no longer seem to find them.
I would like the program to start when I press a button on the Kmotion screen and then slowly lower, find zero, and ideally set the 0 itself before it raises so I can attach the dust shoe.
Thank-you!!
Clayton
Similar Threads:
- Need Help!- Three axis touch plate setup
- Newbie- Z axis touch plate
- Need Help!- Z axis touch off plate connection
- Z axis touch plate
- Need help with Z axis touch off plate
Last edited by -Sliver-; 10-01-2016 at 01:07 AM.
Clayton
http://sliverpaddleboards.com
Hi Clayton,
That would depending on how you want to "Zero" the coordinate system (change Fixture Offset, change G92 offset, or change tool table).
For Fixture Offset you might combine
ProbeZ.c
and
SetFixtureZ.c
with a final Move up.
Regards
Regards
TK http://dynomotion.com
Tom
Thank-you! I was unable to find ProbeZ.c but I have tried to adapt another answer you gave someone else on a similar question. I would like to lower to the touch plate and set DRO (G92) to the touch plate thickness.
Here is what I believe I have to do:
Wiring Plan:
Pin 12 on the KStep JP33 header to the aluminum touch plate. (JP33 pin 12 is Opto IN 3, which maps to IO 171 Input, In my .c file, I have PROBEBIT set to 171)
Ground connection from JP33 to endmill.
Kmotion Set-up:
* Open KMotionCNC, click Tool Setup, choose the User Buttons tab
* For one of the available buttons, do the following
- Name the button (Zero Z-Axis)
- Choose Execute Prog
- Pick a thread (I choose thread 7)
- For VAR, enter 0
- For C File, enter the path to your TouchPlateZero.c file I am creating below.
Program: (TouchPlateZero.c)
#include "KMotionDef.h"
main()
{
Jog(0,-100); // jog slowly negative
while (!ReadBit(171)) ; // loop until IO bit goes high
Jog(0,0); // stop
while (!CheckDone(0)) ; // loop until motion completes
//*******************************I need a command here to set the Z (G92) to the height of the touch plate (0.25)
Move(0,100); // move safe height for installing the dust shoe
while (!CheckDone(0)) ; // loop until motion completes
}
Last edited by -Sliver-; 10-02-2016 at 02:48 AM.
Clayton
http://sliverpaddleboards.com
I have been given this modified version of Jeremy Browns Triple Edge finder program that now only preforms the Z- direction. This is exactly what I need and I have this up and running on my machine but have a couple questions:
Question 1) The program is raising the Z-axis instead of lowering it. I have tried changing #define PROBESPEED 500.0f to -500.0f but it doesn't change the direction of travel. Should I be adding a minus to #define DOWNSPEED (PROBESPEED * -1.0f) // #116 to DOWNSPEED -(PROBESPEED * -1.0f) // #116
Question 2) The program is currently travelling 10x too fast and I am not sure what PROBESPEED 500.0f means. Do I just change this variable to a smaller number like 50.0f or 5.0f to slow it down. I don't understand what the "f" at the end means?
Here is the program:
#include "KMotionDef.h"
#include "PC-DSP.h"
int DoPC(int cmd);
int DoPCFloat(int cmd, float f);
int DoPCInt(int cmd, int i);
int MsgBox(char *s, int Flags);
int SetVars(int poff, int varoff, int n);
int GetVars(int varoff, int n, int poff);
int GetAxisOffset(double *AxisOffset, int Axis);
int GetOriginOffset(double *OriginOffset, int FixtureIndex, int Axis);
int GetMiscSettings();
int GetMachine();
int GetDROs(double *DROx, double *DROy, double *DROz, double *DROa, double *DROb, double *DROc);
void MoveNorth(double distance);
void MoveSouth(double distance);
void MoveWest(double distance);
void MoveEast(double distance);
void MoveUp(double distance);
void MoveDown(double distance);
void MoveXToDest(double destination);
void MoveYToDest(double destination);
void ProbeDown();
void ProbeNorth();
void ProbeSouth();
void ProbeWest();
void ProbeEast();
// Globals
double *pD = (double *)persist.UserData;
float xRes, yRes, zRes;
#define PROBEBIT 171 // #110
#define PROBESPEED 500.0f // #111
#define XAXIS 1 // #112
#define YAXIS 2 // #113
#define ZAXIS 0 // #114
#define UPSPEED 2000.0f // #115
#define DOWNSPEED (PROBESPEED * -1.0f) // #116
#define WESTSPEED -1000.0f // #117
#define EASTSPEED 1000.0f // #118
#define NORTHSPEED 1000.0f // #119
#define SOUTHSPEED -1000.0f // #120
#define PLATETHICKNESS 0.621f // #121
#define SAFEZ 3.0f // #122
#define PLATEDEPTH 3.0f // #123
#define PLATEWIDTH 3.0f // #124
#define BUFFERDISTANCE 0.1f // #125
#define PROBEDEPTH 0.6f // #126
#define RIGHTCORNEROFFSET 0.5f // #127
#define MAXIMUMTOOLDIAMETER 0.5f // #128
#define LEFTCORNEROFFSET 0.75f // #129
main()
{
printf("\n\nStarting main\n");
pD[10] = PROBEBIT;
pD[11] = PROBESPEED;
pD[12] = XAXIS;
pD[13] = YAXIS;
pD[14] = ZAXIS;
pD[15] = UPSPEED;
pD[16] = DOWNSPEED;
pD[17] = WESTSPEED;
pD[18] = EASTSPEED;
pD[19] = NORTHSPEED;
pD[20] = SOUTHSPEED;
pD[21] = PLATETHICKNESS;
pD[22] = SAFEZ;
pD[23] = PLATEDEPTH;
pD[24] = PLATEWIDTH;
pD[25] = BUFFERDISTANCE;
pD[26] = PROBEDEPTH;
pD[27] = RIGHTCORNEROFFSET;
pD[28] = MAXIMUMTOOLDIAMETER;
pD[29] = LEFTCORNEROFFSET;
printf("Setting vars\n");
SetVars(110, 20, 10);
double nTouch, sTouch, wTouch, eTouch;
double nHole, sHole, wHole, eHole;
double approxXAxisHoleZero, approxYAxisHoleZero;
double toolWidth, toolDepth;
printf("Getting Axis Resolution\n");
DoPCInt(PC_COMM_GETAXISRES, 50);
xRes = *(float *)&persist.UserData[50];
yRes = *(float *)&persist.UserData[51];
zRes = *(float *)&persist.UserData[52];
printf("Axis Resolutions Found:\n\tx: %f\n\ty: %f\n\tz: %f\n", xRes, yRes, zRes);
// Find Z Height
ProbeDown();
printf("Setting Z DRO to plate thickness: %f\n", PLATETHICKNESS);
//Zero(ZAXIS);
DoPCFloat(PC_COMM_SET_Z, PLATETHICKNESS);
//MoveUp(15)
MoveUp(SAFEZ);
printf("Done\n");
}
void MoveNorth(double distance)
{
printf("Moving North by %f\n", distance);
MoveRel(YAXIS, distance * yRes);
while (!CheckDone(YAXIS));
}
void MoveSouth(double distance)
{
printf("Moving South by %f\n", distance);
MoveRel(YAXIS, -1 * distance * yRes);
while (!CheckDone(YAXIS));
}
void MoveWest(double distance)
{
printf("Moving West by %f\n", distance);
MoveRel(XAXIS, -1 * distance * xRes);
while (!CheckDone(XAXIS));
}
void MoveEast(double distance)
{
printf("Moving East by %f\n", distance);
MoveRel(XAXIS, distance * xRes);
while (!CheckDone(XAXIS));
}
void MoveUp(double distance)
{
printf("Moving Up by %f\n", distance);
MoveRel(ZAXIS, distance * zRes);
while (!CheckDone(ZAXIS));
}
void MoveDown(double distance)
{
printf("Moving Down by %f\n", distance);
MoveRel(ZAXIS, -1 * distance * zRes);
while (!CheckDone(ZAXIS));
}
void MoveXToDest(double destination)
{
printf("Moving XAXIS to %f\n", destination);
Move(XAXIS, destination);
while (!CheckDone(XAXIS));
}
void MoveYToDest(double destination)
{
printf("Moving YAXIS to %f\n", destination);
Move(YAXIS, destination);
while (!CheckDone(YAXIS));
}
void ProbeDown()
{
printf("Jogging Down at speed:%f\n", DOWNSPEED);
Jog(ZAXIS, DOWNSPEED);
printf("Waiting for probe to read high\n");
while (!ReadBit(PROBEBIT));
printf("Stopping\n");
Jog(ZAXIS, 0);
printf("Waiting for Z motion to stop\n");
while (!CheckDone(ZAXIS));
}
void ProbeSouth()
{
printf("Jogging South at speed:%f\n", SOUTHSPEED);
Jog(YAXIS, SOUTHSPEED);
printf("Waiting for probe to read high\n");
while (!ReadBit(PROBEBIT));
printf("Stopping\n");
Jog(YAXIS, 0);
printf("Waiting for Y motion to stop\n");
while (!CheckDone(YAXIS));
}
void ProbeNorth()
{
printf("Jogging North at speed:%f\n", NORTHSPEED);
Jog(YAXIS, NORTHSPEED);
printf("Waiting for probe to read high\n");
while (!ReadBit(PROBEBIT));
printf("Stopping\n");
Jog(YAXIS, 0);
printf("Waiting for Y motion to stop\n");
while (!CheckDone(YAXIS));
}
void ProbeWest()
{
printf("Jogging West at speed:%f\n", WESTSPEED);
Jog(XAXIS, WESTSPEED);
printf("Waiting for probe to read high\n");
while (!ReadBit(PROBEBIT));
printf("Stopping\n");
Jog(XAXIS, 0);
printf("Waiting for X motion to stop\n");
while (!CheckDone(XAXIS));
}
void ProbeEast()
{
printf("Jogging East at speed:%f\n", EASTSPEED);
Jog(XAXIS, EASTSPEED);
printf("Waiting for probe to read high\n");
while (!ReadBit(PROBEBIT));
printf("Stopping\n");
Jog(XAXIS, 0);
printf("Waiting for X motion to stop\n");
while (!CheckDone(XAXIS));
}
int GetDROs(double *DROx, double *DROy, double *DROz, double *DROa, double *DROb, double *DROc)
{
int TMP = 60;
if (DoPCInt(PC_COMM_GET_DROS,TMP)) return 1; // Var index and Cmd
*DROx=pD[TMP];
*DROy=pD[TMP+1];
*DROz=pD[TMP+2];
*DROa=pD[TMP+3];
*DROb=pD[TMP+4];
*DROc=pD[TMP+5];
}
int GetMachine(double *Machinex, double *Machiney, double *Machinez, double *Machinea, double *Machineb, double *Machinec)
{
int TMP = 66;
if (DoPCInt(PC_COMM_GET_MACHINE_COORDS,TMP)) return 1; // Var index and Cmd
*Machinex=pD[TMP];
*Machiney=pD[TMP+1];
*Machinez=pD[TMP+2];
*Machinea=pD[TMP+3];
*Machineb=pD[TMP+4];
*Machinec=pD[TMP+5];
}
int GetMiscSettings(int *Units, int *TWORD, int *HWORD, int *DWORD)
{
int TMP = 72;
if (DoPCInt(PC_COMM_GET_MISC_SETTINGS,TMP)) return 1;
*Units = persist.UserData[TMP];
*TWORD = persist.UserData[TMP+1];
*HWORD = persist.UserData[TMP+2];
*DWORD = persist.UserData[TMP+3];
}
int GetOriginOffset(double *OriginOffset, int FixtureIndex, int Axis)
{
int TMP = 77;
if (GetVars(5200+FixtureIndex*20+Axis+1,1,TMP)) return 1; // Download to persist TMP
*OriginOffset=pD[TMP];
return 0;
}
int GetAxisOffset(double *AxisOffset, int Axis)
{
int TMP = 78;
if (GetVars(5200+Axis+11,1,TMP)) return 1; // Download to persist TMP
*AxisOffset=pD[TMP];
return 0;
}
int SetVars(int varoff, int n, int poff)
{
persist.UserData[PC_COMM_PERSIST+2] = n; // number of elements
persist.UserData[PC_COMM_PERSIST+3] = poff; // persist offset (doubles)
return DoPCInt(PC_COMM_SET_VARS,varoff); // Var index and Cmd
}
int GetVars(int varoff, int n, int poff)
{
persist.UserData[PC_COMM_PERSIST+2] = n; // number of elements
persist.UserData[PC_COMM_PERSIST+3] = poff; // persist offset (doubles)
return DoPCInt(PC_COMM_GET_VARS,varoff); // Var index and Cmd
}
#define GATH_OFF 0 // define the offset into the Gather buffer where strings are passed
// Trigger a message box on the PC to be displayed
// defines for MS Windows message box styles and Operator
// response IDs are defined in the KMotionDef.h file
int MsgBox(char *s, int Flags)
{
char *p=(char *)gather_buffer+GATH_OFF*sizeof(int);
int i;
do // copy to gather buffer w offset 0
{
*p++ = *s++;
}while (s[-1]);
persist.UserData[PC_COMM_PERSIST+2] = Flags; // set options
DoPCInt(PC_COMM_MSG,GATH_OFF);
return persist.UserData[PC_COMM_PERSIST+3];
}
// put the MDI string (Manual Data Input - GCode) in the
// gather buffer and tell the App where it is
int MDI(char *s)
{
char *p=(char *)gather_buffer+GATH_OFF*sizeof(int);
int i;
do // copy to gather buffer w offset 0
{
*p++ = *s++;
}while (s[-1]);
// issue the command an wait till it is complete
// (or an error - such as busy)
return DoPCInt(PC_COMM_MDI,GATH_OFF);
}
// Put a Float as a parameter and pass the command to the App
int DoPCFloat(int cmd, float f)
{
int result;
persist.UserData[PC_COMM_PERSIST+1] = *(int*)&f;
return DoPC(cmd);
}
// Put an integer as a parameter and pass the command to the App
int DoPCInt(int cmd, int i)
{
int result;
persist.UserData[PC_COMM_PERSIST+1] = i;
return DoPC(cmd);
}
// Pass a command to the PC and wait for it to handshake
// that it was received by either clearing the command
// or changing it to a negative error code
int DoPC(int cmd)
{
int result;
persist.UserData[PC_COMM_PERSIST]=cmd;
do
{
WaitNextTimeSlice();
}while (result=persist.UserData[PC_COMM_PERSIST]>0);
// printf("Result = %d\n",result);
return result;
}
Here is the original program on Youtube:
Clayton
http://sliverpaddleboards.com
Hi Clayton,
PROBESPEED should change the direction and speed of probing. Are you sure you really changed it? Did you change the file you specified to use?
The 'f" tells the compiler it is a 32bit floating point number of type float. In some cases it matters to to the compiler if the number is a float, double, or integer. In this case it doesn't but it is good practice to always be clear. For example 1/3 = 0 (integer division) 1.0f/3.0f = 0.3333333 (32 bit floats) and 1.0/3.0 = 0.33333333333333333 (64 bit doubles)
It seems odd you would need to reverse your z direction. If you raise your spindle does the value on the KMotion Axis Screen become more positive?
Regards
Regards
TK http://dynomotion.com
Tom
Thank-you for your help!
I will double check tonight. It is possible that I made a duplicate file by mistake the way I transferred the file to the PC (I usually use a Mac) That would also explain why I was unable to change the direction so I really hope this is the problem.
Yes. When I raise the bit up the DRO number is more positive. 1 inch above the stock shows as 1.00 and 2 inches above the stock shows as 2.00.
Clayton
Clayton
http://sliverpaddleboards.com
Hi Clayton,
I wasn't referring to the DRO number. Rather the KMotion Axis ScreenYes. When I raise the bit up the DRO number is more positive. 1 inch above the stock shows as 1.00 and 2 inches above the stock shows as 2.00.
Regards
Regards
TK http://dynomotion.com
Tom
Thank-you!!
The problem was I was using a limit switch to test my program. The switch was NC so the program started with UPSPEED. This explains why I was unable to edit the DOWNSPEED speed or the direction. Now that I have the program working I will wire properly tomorrow.
I am planning on using KSTEP input 175 with a 12v input. Does this sound ok?
Clayton
Clayton
http://sliverpaddleboards.com
Hi Clayton,
That sounds ok. The diagram below shows how the circuit should be completed activate the Opto Input. As you stated before you will need a 12V or 24V supply with it's GND connected to the endmill. This should be isolated from KFLOP +5V GND. I would normally keep the Limit Switch wiring and Home Switch wiring (the other inputs to KStep JP33) isolated from Earth GND (the endmill). But it will probably work ok.
HTH
Regards
Regards
TK http://dynomotion.com
Tom
Thank-you so much!! The machine has been working flawlessly with your products (Kflop/Kstep/Kmotion) for over a year and I was worried about screwing this up. Your customer support is awesome!
Clayton
Clayton
http://sliverpaddleboards.com