Page 1 of 1
find z index and set position
Posted: Tue Sep 28, 2021 1:15 am
by turbothis
easy right!?
so i murdered up this C code and see what you guys think.
1 i want to be able to eye ball my end milling cutter (pointy one) off the back/fixed face of the vise. generally Y zero for me......
2 then punch the button to fire off this code to jog negative until the Z is found
3 then set the Y axis to what distance it is off the vise face. i will measure and maintain this distance and insert when i can measure off the Z index.
Code: Select all
#include "KMotionDef.h"
main()
{
Jog(1,-100); // Y axis jog negative direction
while (!Readbit(8)); // wait for Z index (input #8) to happen
Jog(0,0); // stop
while (!CheckDone(0)); // wait till we are stopped
Dest1=-0.000; // set Y axis position to what is manually measured off vise to Z index
Pos1=-0.000; // maybe?
}
Re: find z index and set position
Posted: Tue Sep 28, 2021 5:31 pm
by TomKerekes
Its not clear to me what you are trying to do.
What type of system do you have? Encoders?
Regarding the C Program:
Axis 1 is moved but then Axis 0 is stopped?
Then the program waits for Axis 0 to be stopped which already is.
Dest1 is not a valid C Variable. To change the Axis 1 member variable Destination would be:
ch1->Dest = XXXX;
But to change the Destination you should disable the Axis and re-enable at the new Destination. Just changing the Destination would cause an infinite speed jump from the previous destination. ie:
DisableAxis(1);
EnableAxisDest(1, XXX);
Re: find z index and set position
Posted: Tue Sep 28, 2021 5:53 pm
by turbothis
ok
simple 3 axis mill
dc servos with encoders
i missed the details to make this all Y axis only
i just want a quick zero for my Y axis on the vise.
i dont have any home set up or any use of the Z index
i used to have a Y axis hand wheel on the ball screw that i had a point to line up the Y zero to the vise. this mill does not have this feature.
Code: Select all
#include "KMotionDef.h"
main()
{
Jog(1,-100); // Y axis jog negative direction
while (!ReadBit(8)); // wait for Z index (input #8) to happen
Jog(1,0); // stop
while (!CheckDone(1)); // wait till we are stopped
DisableAxis(1);
EnableAxisDest(1,-0.000); // set Y axis position to what is manually measured off vise to Z index
}
Re: find z index and set position
Posted: Tue Sep 28, 2021 6:21 pm
by turbothis
what are the chances i will see the Z pulse on the digital I/O page while slowly turning the Y axis screw by hand?
Z index wired to #8?
green and black wire

Re: find z index and set position
Posted: Thu Sep 30, 2021 3:16 pm
by TomKerekes
That Program should work although there are more accurate methods of moving exactly to where the index was detected before stopping.
what are the chances i will see the Z pulse on the digital I/O page while slowly turning the Y axis screw by hand?
Slim. The Digital IO only updates a few times per second. Whereas a C Program samples over 5000 times per second.
Kanalog JP2 passes signals to KFLOP JP5 so the input would be Bit 36 not 8.
HTH
Re: find z index and set position
Posted: Thu Sep 30, 2021 3:46 pm
by turbothis
i was concerned about over shooting
if you have a minute could you explain a more "hunting" for the index pulse?
Re: find z index and set position
Posted: Thu Sep 30, 2021 3:52 pm
by TomKerekes
You never answered my question regarding if you have encoders?
Re: find z index and set position
Posted: Thu Sep 30, 2021 4:13 pm
by turbothis
oh ya sorry
the servos do have the typical encoder
centroid brand
Re: find z index and set position
Posted: Thu Sep 30, 2021 4:35 pm
by TomKerekes
In that case instead of stopping when the index is detected with:
Jog(1,0); // stop
you might sample the current encoder position and command a move there with:
Move(1, ch1->Position);
Then after stopping delay some to let everything settle and there to be near zero error.
You will need to set both the Position and Destination to zero (or whatever value you wish) also.
So in Total:
Code: Select all
#include "KMotionDef.h"
main()
{
Jog(1,-100); // Y axis jog negative direction
while (!ReadBit(36)); // wait for Z index (input #36) to happen
Move(1, ch1->Position); // stop and move back to where index was detected
while (!CheckDone(1)); // wait till we are stopped
Delay_sec(1.0); // wait till all settled out
DisableAxis(1); // Disable Axis while shifting origin
ch1->Position = 0; // set origin
EnableAxisDest(1,0.0); // Enable and set commanded destination
}
Re: find z index and set position
Posted: Thu Sep 30, 2021 4:57 pm
by turbothis
excelent
this is what i wanted
i hope to get better at C code stuff
i only really learn this by necessity and trying
thanks for being so patient and teacher like!!!!!!!!!!!