user button to send X and Y axis to position 0.000

Moderators: TomKerekes, dynomotion

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

user button to send X and Y axis to position 0.000

Post by turbothis » Tue Aug 27, 2019 7:49 pm

i had one of these on my mill a while back but can not find it
is there a code that would enter something like "G00x0.0Y0.0" into the MDi bar?

maybe?

Code: Select all

#include "KMotionDef.h"

main()
{
	Move0=0.0;
	Move1=0.0;
}

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: user button to send X and Y axis to position 0.000

Post by TomKerekes » Tue Aug 27, 2019 7:56 pm

Hi turbothis,

Don't confuse Console Script Commands with C Functions. Try the code below. Note this will move to Machine Coordinates 0,0 which may be different than GCode Coordinate 0,0 if there are GCode Offsets.

Code: Select all

#include "KMotionDef.h"

main()
{
	Move(0, 0.0);
	Move(1, 0.0);
}
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: user button to send X and Y axis to position 0.000

Post by turbothis » Tue Aug 27, 2019 8:02 pm

you know better than anyone i get everything confused!
is there a list of C functions?
i dont do any fancy offsets
thanks!

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: user button to send X and Y axis to position 0.000

Post by TomKerekes » Tue Aug 27, 2019 8:04 pm

C Functions are defined in \DSP_KFLOP\KMotionDef.h
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: user button to send X and Y axis to position 0.000

Post by turbothis » Tue Aug 27, 2019 8:10 pm

it works but stops short by about .002" ish
if i MDI X 0 then it gets to .0001"

Code: Select all

#include "KMotionDef.h"

 main()
{

	ch0->InputMode=ENCODER_MODE;
	ch0->OutputMode=DAC_SERVO_MODE;
	ch0->Vel=130000;
	ch0->Accel=1.5e+006;
	ch0->Jerk=3e+007;
	ch0->P=4;
	ch0->I=0.0;
	ch0->D=550;
	ch0->FFAccel=0;
	ch0->FFVel=0;
	ch0->MaxI=100;
	ch0->MaxErr=2000;
	ch0->MaxOutput=2000;
	ch0->DeadBandGain=1;
	ch0->DeadBandRange=0;
	ch0->InputChan0=0;
	ch0->InputChan1=0;
	ch0->OutputChan0=7;
	ch0->OutputChan1=0;
	ch0->MasterAxis=-1;
	ch0->LimitSwitchOptions=0x0;
	ch0->SoftLimitPos=1e+009;
	ch0->SoftLimitNeg=-1e+009;
	ch0->InputGain0=1;
	ch0->InputGain1=1;
	ch0->InputOffset0=0;
	ch0->InputOffset1=0;
	ch0->OutputGain=-1;
	ch0->OutputOffset=0;
	ch0->SlaveGain=1;
	ch0->BacklashMode=BACKLASH_OFF;
	ch0->BacklashAmount=0;
	ch0->BacklashRate=0;
	ch0->invDistPerCycle=1;
	ch0->Lead=0;
	ch0->MaxFollowingError=8000;
	ch0->StepperAmplitude=20;

	ch0->iir[0].B0=1;
	ch0->iir[0].B1=0;
	ch0->iir[0].B2=0;
	ch0->iir[0].A1=0;
	ch0->iir[0].A2=0;

	ch0->iir[1].B0=1;
	ch0->iir[1].B1=0;
	ch0->iir[1].B2=0;
	ch0->iir[1].A1=0;
	ch0->iir[1].A2=0;

	ch0->iir[2].B0=0.000769;
	ch0->iir[2].B1=0.001538;
	ch0->iir[2].B2=0.000769;
	ch0->iir[2].A1=1.92081;
	ch0->iir[2].A2=-0.923885;
	EnableAxis(0);


	ch1->InputMode=ENCODER_MODE;
	ch1->OutputMode=DAC_SERVO_MODE;
	ch1->Vel=120000;
	ch1->Accel=2e+006;
	ch1->Jerk=3e+007;
	ch1->P=7;
	ch1->I=0.0;
	ch1->D=1000;
	ch1->FFAccel=0;
	ch1->FFVel=0;
	ch1->MaxI=100;
	ch1->MaxErr=2000;
	ch1->MaxOutput=2000;
	ch1->DeadBandGain=1;
	ch1->DeadBandRange=0;
	ch1->InputChan0=1;
	ch1->InputChan1=0;
	ch1->OutputChan0=6;
	ch1->OutputChan1=0;
	ch1->MasterAxis=-1;
	ch1->LimitSwitchOptions=0x0;
	ch1->SoftLimitPos=1e+009;
	ch1->SoftLimitNeg=-1e+009;
	ch1->InputGain0=1;
	ch1->InputGain1=1;
	ch1->InputOffset0=0;
	ch1->InputOffset1=0;
	ch1->OutputGain=-1;
	ch1->OutputOffset=0;
	ch1->SlaveGain=1;
	ch1->BacklashMode=BACKLASH_OFF;
	ch1->BacklashAmount=0;
	ch1->BacklashRate=0;
	ch1->invDistPerCycle=1;
	ch1->Lead=0;
	ch1->MaxFollowingError=8000;
	ch1->StepperAmplitude=20;

	ch1->iir[0].B0=1;
	ch1->iir[0].B1=0;
	ch1->iir[0].B2=0;
	ch1->iir[0].A1=0;
	ch1->iir[0].A2=0;

	ch1->iir[1].B0=1;
	ch1->iir[1].B1=0;
	ch1->iir[1].B2=0;
	ch1->iir[1].A1=0;
	ch1->iir[1].A2=0;

	ch1->iir[2].B0=0.000769;
	ch1->iir[2].B1=0.001538;
	ch1->iir[2].B2=0.000769;
	ch1->iir[2].A1=1.92081;
	ch1->iir[2].A2=-0.923885;
	EnableAxis(1);


	ch2->InputMode=ENCODER_MODE;
	ch2->OutputMode=DAC_SERVO_MODE;
	ch2->Vel=120000;
	ch2->Accel=1.8e+006;
	ch2->Jerk=3e+007;
	ch2->P=3;
	ch2->I=0.001;
	ch2->D=120;
	ch2->FFAccel=0;
	ch2->FFVel=0;
	ch2->MaxI=100;
	ch2->MaxErr=2000;
	ch2->MaxOutput=2000;
	ch2->DeadBandGain=1;
	ch2->DeadBandRange=0;
	ch2->InputChan0=2;
	ch2->InputChan1=0;
	ch2->OutputChan0=5;
	ch2->OutputChan1=0;
	ch2->MasterAxis=-1;
	ch2->LimitSwitchOptions=0x0;
	ch2->SoftLimitPos=1e+009;
	ch2->SoftLimitNeg=-1e+009;
	ch2->InputGain0=1;
	ch2->InputGain1=1;
	ch2->InputOffset0=0;
	ch2->InputOffset1=0;
	ch2->OutputGain=-1;
	ch2->OutputOffset=0;
	ch2->SlaveGain=1;
	ch2->BacklashMode=BACKLASH_OFF;
	ch2->BacklashAmount=0;
	ch2->BacklashRate=0;
	ch2->invDistPerCycle=1;
	ch2->Lead=0;
	ch2->MaxFollowingError=8000;
	ch2->StepperAmplitude=20;

	ch2->iir[0].B0=1;
	ch2->iir[0].B1=0;
	ch2->iir[0].B2=0;
	ch2->iir[0].A1=0;
	ch2->iir[0].A2=0;

	ch2->iir[1].B0=1;
	ch2->iir[1].B1=0;
	ch2->iir[1].B2=0;
	ch2->iir[1].A1=0;
	ch2->iir[1].A2=0;

	ch2->iir[2].B0=0.000769;
	ch2->iir[2].B1=0.001538;
	ch2->iir[2].B2=0.000769;
	ch2->iir[2].A1=1.92081;
	ch2->iir[2].A2=-0.923885;
	EnableAxis(2);
	
	
	

	DefineCoordSystem(0,1,2,-1);

    

}


User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: user button to send X and Y axis to position 0.000

Post by TomKerekes » Tue Aug 27, 2019 8:24 pm

Hi turbothis,

I wouldn't expect there to be any difference. Check the KMotion.exe Axis Screen to see what is the Destination for Axis 0 is and what is the actual Position.

Are your GCode DRO's displaying Actual Position (blue) or commanded Destinations (green)? I assume Actual Positions.

Your Servos don't have any I Gain on Axes 0 and 1. I gain is what helps a servo drive errors to zero. Without I gain if the error is not big enough to cause the motor to move it will sit there forever with some error. With I gain the Integrator will keep ramping up pushing harder and harder until the motor eventually moves.
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: user button to send X and Y axis to position 0.000

Post by turbothis » Tue Aug 27, 2019 9:44 pm

ok i added in some I
ch0->I=0.05;
ch1->I=0.1;
got it real stable and does go to zero with G0X0Y0 in the MDI

they are blue
on the C program though, i move to X-2.0 and Y-2.0 (or any position) and use the C program and still get .002 on both axis
the axis screen does say dest 0 / position 0 too

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: user button to send X and Y axis to position 0.000

Post by turbothis » Wed Aug 28, 2019 1:07 am

my dad had this for the last version of the go to zero user button but i cant figure it out

Code: Select all

// This is the header file for Matt specific Programs
// Matt.h   	Rev A	JEY	July 31, 2013
//MattRevB.h	Rev B	JEY	October 10, 2013

#define HALTBIT 	 27
#define RESTARTBIT	 28
#define ZEROALLBIT	 29

#define KFLOP_LED46	 46

#define ESTOP 		 136
#define CYCLESTARTBIT	 137
#define FLOOD_CTL_BIT  	 138
#define FEEDHOLD_BIT	 140

#define CW_BIT  	 144
#define CCW_BIT 	 145
#define FLOOD_BIT  	 153

// These are user.data bytes to identify which button pushed (and which routine to xeq)
// "LOC" identifies the LOCation in persist.User.Data

#define M5STOP_LOC	 80
#define	INIT_LOC	 81
#define ENABLE_LOC	 82
#define ZERO_LOC	 83
#define SPEED500_LOC	 84
#define FLOOD_LOC	 85
#define FEEDHOLD_LOC	 86
		 
#define WATCHDOG   	 89

// SPINDLE_FACTOR converts RPM to voltage, SPINDLE_DAC is which DAC is in use

#define SPINDLE_FACTOR  (-0.5386)
#define SPINDLE_DAC  	0

Code: Select all

// Program to handle all the one shot KMotion functions
// oneshot.c  	Rev A	JEY	July 31, 2013
//		Rev B	JEY	October 10, 2013

#include "KMotionDef.h"
#include "C:\Users\SHIZ\Desktop\mattheader.c"

int main()
{
 //debug();
	//test for each button or Mcode...call routine for found condition
	
if ( persist.UserData[M5STOP_LOC] ) 	M5stop();
if ( persist.UserData[FEEDHOLD_LOC] ) 	Feedhold();
if ( persist.UserData[FLOOD_LOC] )	    Flood(); 
if ( persist.UserData[SPEED500_LOC] ) 	Speed500();
if ( persist.UserData[ZERO_LOC] )	    ZeroMatt();
	
return 0;
}

/*----------------------------------------------------------------------------*/

	// debug - prints UserData to console
	
debug()
{
int x;
for (x=80;x<=90;x++) {
	printf("n%i=%i\n",x,persist.UserData[x]);
	}
return 0;
}

/*----------------------------------------------------------------------------*/

	// M5 command -> clear spindle direction and set speed to Zero
	
M5stop()
{
	
persist.UserData[M5STOP_LOC]=0; 				// Clear Switch
	
ClearBit(CCW_BIT);
ClearBit(CW_BIT);
	
DAC(SPINDLE_DAC,0);		
}

/*----------------------------------------------------------------------------*/

	// Handle FeedHold/Resume

Feedhold()
{

persist.UserData[FEEDHOLD_LOC]=0; 				// Clear Switch

if (CS0_StoppingState == 0){
		StopCoordinatedMotion();}
else {
		ResumeCoordinatedMotion();}


}

/*----------------------------------------------------------------------------*/

	// Program to toggle bit that controls flood relay

Flood()
{
int x;
	
persist.UserData[FLOOD_LOC]=0; 				// Clear Switch
	
if (ReadBit(FLOOD_BIT)) 				// Check setting of flood bit
	ClearBit(FLOOD_BIT);				// Turn off if it was on
else 
	SetBit(FLOOD_BIT);				// Turn on if it was off
	printf("Flood toggled in oneshot\n");		
for (x=1;x<2500;x++) { 					// Debounce by 500 breaks
	WaitNextTimeSlice();				// Wait
	persist.UserData[FLOOD_LOC]=0; 			// Clear Switch
	}
}

/*----------------------------------------------------------------------------*/

	//  Program to set CW direction and spindle speed to 500 RPM
  
Speed500()
{
int x;
	
persist.UserData[SPEED500_LOC]=0; 				// Clear Switch

SetBit(CW_BIT);									// Clockwise bit set

x=500*SPINDLE_FACTOR;							// Compute DAC setting

DAC(SPINDLE_DAC,x);								// Set spindel speed
}

/*----------------------------------------------------------------------------*/

	// Zero the three axes by using a G-Code command 

int DoPC(int cmd);
int DoPCInt(int cmd, int i);
#define GATH_OFF 0  // define the offset into the Gather buffer where strings are passed


ZeroMatt()
{
		persist.UserData[ZERO_LOC]=0; 				// Clear Switch

		MDI("G00 X0 Y0");  					// move to x=zero, y=zero
}

/*----------------------------------------------------------------------------*/

// 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 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);
	
return result;
}

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: user button to send X and Y axis to position 0.000

Post by turbothis » Wed Aug 28, 2019 1:47 am

https://dynomotion.com/Help/KMotionCNC/ ... rKFLOP.htm

this says i can Execute a MDI line of GCode with a C code
pretty much all i want to do here

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: user button to send X and Y axis to position 0.000

Post by TomKerekes » Wed Aug 28, 2019 2:04 am

Hi turbothis,

You can do that also. Both approaches should work.

Code: Select all

#include "KMotionDef.h"

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


main()
{
	MDI("G0 X0 Y0");  // move to zero
}
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply