Hi Epiphany,
Z Tracking is certainly possible. A better approach might have been to input the Analog Height signal into KFLOP so it could drive the Z Speed as a function of the error rather than just of/off up/down. But this approach should also work.
When moving Z independently in Height Tracking mode Z should be removed from the Coordinated Motion System with the DefineCoordSystem() function.
Another issue is that Jog commands should not be commanded continuously at a high rate. It is better to just command the Jog Speed once (and have the blended trajectory computed) until something changes.
Below is simple loop that may work for you in a way that the Z Tracking mode can be turned on and off by activating a Virtual Bit. This loop can be added to your Initialization code (and merged with any other service activities) so no extra Threads in KFLOP are required. It is also attached as a .txt file.
Code:
#include "KMotionDef.h"
// When Z Tracking Bit is set control Z Height based on two input bits
main()
{
#define Raise_Torch 20
#define Lower_Torch 21
#define Torch_Speed 1000.0 // speed to move torch - counts/sec
#define Z_TRACKING_MODE_BIT 1024 // set to begin Z height tracking
#define JoggingNone 0
#define JoggingUp 1
#define JoggingDown 2
int JogState=JoggingNone;
for(;;)
{
WaitNextTimeSlice();
if (ReadBit(Z_TRACKING_MODE_BIT))
{
if (ReadBit(Raise_Torch)) //Raise Torch ??
{
if (JogState!=JoggingUp)
{
JogState=JoggingUp;
Jog(2,Torch_Speed);
}
}
else if (ReadBit(Lower_Torch)) //Lower Torch ??
{
if (JogState!=JoggingDown)
{
JogState=JoggingDown;
Jog(2,Torch_Speed);
}
}
else //Stop Torch
{
if (JogState!=JoggingNone)
{
JogState=JoggingNone;
Jog(2,0);
}
}
}
else
{
JogState=JoggingNone;
}
}
}
Below is Code that may be assigned to an M Code to activate Z Tracking. It will remove Z from Coordinated Motion then set the virtual bit so Z Tracking will be serviced. Select Exec Prog/wait/sync
Code:
#include "KMotionDef.h"
main()
{
#define Z_TRACKING_MODE_BIT 1024 // set to begin Z height tracking
// remove Z from coordinated motion
DefineCoordSystem(0,1,-1,-1);
SetBit(Z_TRACKING_MODE_BIT);
}
Below is Code that may be assigned to an M Code to deactivate Z Tracking. It will add Z back into the Coordinated Motion System then clear the virtual bit so Z Tracking will be serviced. Select Exec Prog/wait/sync so that Z is re-synchronized to its current position before continuing with G Code.
Code:
#include "KMotionDef.h"
main()
{
#define Z_TRACKING_MODE_BIT 1024 // set to begin Z height tracking
// add Z to coordinated motion
DefineCoordSystem(0,1,2,-1);
ClearBit(Z_TRACKING_MODE_BIT);
Jog(2,0); // stop
while (!CheckDone(2)) ;
}
The code is untested so it may have bugs. Let us know if you have problems.
HTH
Regards