585,708 active members*
3,893 visitors online*
Register for free
Login
Page 1 of 2 12
Results 1 to 20 of 32
  1. #1
    Join Date
    Feb 2008
    Posts
    216

    Mach3/Kflop - Homing 3 axis machine

    I’m building a 3 axis wood CNC which will have:
    1 home switch per axis
    2 limit switches X++, X—per axis
    2 E-stop Over travel Switches per axis
    I’m currently working on the first axis, the X-Axis.
    The limit switches are working correctly in Mach3, I’m now working on the Home switch for the first X axis.
    I got the Machscreen software and changed the oem –Code for the Zero X button for 1022 as the Kmotion instruction say to. I then updated the changed screen in Mach3 and changed the Home Plug-in C-code file to the following file in mach3. When I click on the Zero X button on the main page in Mach it doesn’t do anything. When I hold down the Home switch and then click the Zero button I get a message that the home switch is already activated. (the Home switch does light up when activated as an Input in Mach and Kmotion.)
    Am I missing something here? I haven’t done any C++ in years. I used snipes posted code as my starting point. http://www.cnczone.com/forums/dynomo..._-_homing.html Does anyone have a C-Code file that works that I could use as a template to alter to make it work? I’m having no luck and have hit a wall.
    Thanks
    -Dan

    Code:
     
    
    #include "KMotionDef.h"
    
    //Plugin calls for Mach3 Home (actually Purge) Commands
    
    main()
    {
    	int flags = persist.UserData[5];  		// Mach3 flags bit0=X, bit1=Y, Bit2=Z, etc...
    
    	printf("Mach3 Home Call, flags = %d\n",flags); 
    	
    	//XXXXXXXXXXXXXXXXXXXXXX  START OF X-AXIS Home Switch  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    	
    	if (flags==1)                                                // Why is this not flags==0 if bit0=x?
    	{
    		int SaveXLimits;  					// Place to save limit switch settings
    		DisableAxis(0);  					// Disable x axis
    			
    	// The following taken striaght from Channel 0 configuration in Kmotion...Is this what is needed?
    		
    	ch0->InputMode=NO_INPUT_MODE;
    	ch0->OutputMode=STEP_DIR_MODE;
    	ch0->Vel=4000;
    	ch0->Accel=5000;
    	ch0->Jerk=200000;
    	ch0->P=1;
    	ch0->I=0;
    	ch0->D=0;
    	ch0->FFAccel=0;
    	ch0->FFVel=0;
    	ch0->MaxI=200;
    	ch0->MaxErr=1e+006;
    	ch0->MaxOutput=200;
    	ch0->DeadBandGain=1;
    	ch0->DeadBandRange=0;
    	ch0->InputChan0=0;
    	ch0->InputChan1=0;
    	ch0->OutputChan0=4;
    	ch0->OutputChan1=1;
    	ch0->MasterAxis=-1;
    	ch0->LimitSwitchOptions=0x1011001f;
    	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.1;
    	ch0->MaxFollowingError=1000000000;
    	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=1;
    	ch0->iir[2].B1=0;
    	ch0->iir[2].B2=0;
    	ch0->iir[2].A1=0;
    	ch0->iir[2].A2=0;
    	
    	// END OF COPY & PASTE
    						 
    	SaveXLimits = ch0->LimitSwitchOptions;	        // save how the limit is set
    	ch0->LimitSwitchOptions = 0;			        // disable the limit
    	EnableAxis(0);						// enable x axes and begin servoing where we are 
    									// jog x-axis until it sees the limit
        Jog(0,-100);							// jog slowly positive
        while (!ReadBit(19)) ; 		 			// loop until IO bit goes high
        Jog(0,0);							// stop
        while (!CheckDone(0)) ; 				        // loop until motion completes 
        DisableAxis(0);							// disable the axis
        Zero(0);								// Zero the position 
        EnableAxis(0);							// re-enable the ServoTick
        Move(0,-1000.0);						// move some amount inside the limits
        while (!CheckDone(0)) ; 				        // loop until motion completes 
        ch0->LimitSwitchOptions = SaveXLimits;              // restore limit settings
    
    	}
    	
    		//YYYYYYYYYYYYYYYYYYYYYY  START OF Y-AXIS Home Switch  YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
    		if (flags==2)
    		{							// Why is this not flags==1 if bit1=y?
    		int SaveYLimits;  					// Place to save limit switch settings
    		DisableAxis(1);  					// Disable y axis
    	
    		// The following taken striaght from Channel 1 configuration in Kmotion...Is this what is needed?	
    		
    		ch1->InputMode=NO_INPUT_MODE;
    		ch1->OutputMode=STEP_DIR_MODE;
    		ch1->Vel=40000;
    		ch1->Accel=400000;
    		ch1->Jerk=4e+006;
    		ch1->P=0;
    		ch1->I=0.01;
    		ch1->D=0;
    		ch1->FFAccel=0;
    		ch1->FFVel=0;
    		ch1->MaxI=200;
    		ch1->MaxErr=1e+006;
    		ch1->MaxOutput=200;
    		ch1->DeadBandGain=1;
    		ch1->DeadBandRange=0;
    		ch1->InputChan0=1;
    		ch1->InputChan1=0;
    		ch1->OutputChan0=5;
    		ch1->OutputChan1=0;
    		ch1->MasterAxis=-1;
    		ch1->LimitSwitchOptions=0x0;
    		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.1;
    		ch1->MaxFollowingError=1000000000;
    		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;
    	
    		// END OF COPY & PASTE
    						 
    		SaveYLimits = ch1->LimitSwitchOptions;	        // Save how the limit is set
    		ch1->LimitSwitchOptions = 0;			        // Disable the limit
    		EnableAxis(1);						// Enable y axes and begin servoing where we are 
    										// Jog y-axis until it sees the limit
    		Jog(1,100);							// Jog slowly positive
    		while (!ReadBit(10)) ; 		 			// loop until IO bit goes high
    		Jog(1,0);							// Stop
    		while (!CheckDone(1)) ; 				// Loop until motion completes 
    		DisableAxis(1);						// Disable the axis
    		Zero(1);							// Zero the position 
    		EnableAxis(1);						// Re-enable the ServoTick
    		Move(1,-1000.0);						// Move some amount inside the limits
    		while (!CheckDone(1)) ; 				// Loop until motion completes 
    		ch1->LimitSwitchOptions = SaveYLimits;          // restore limit settings
    		} 
    
    			//ZZZZZZZZZZZZZZZZZZZZZZ  START OF Z-AXIS Home Switch  ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
    			if (flags==4)						// Why is this not flags==2 if bit2=y?
    			{	   
    			int SaveZLimits;  						// Place to save limit switch settings
    	
    			DisableAxis(2);  						// Disable Z axis
    	
    			// The following taken striaght from Channel 2 configuration in Kmotion...Is this what is needed?	
    		
    			ch2->InputMode=NO_INPUT_MODE;
    			ch2->OutputMode=STEP_DIR_MODE;
    			ch2->Vel=40000;
    			ch2->Accel=400000;
    			ch2->Jerk=4e+006;
    			ch2->P=0;
    			ch2->I=0.01;
    			ch2->D=0;
    			ch2->FFAccel=0;
    			ch2->FFVel=0;
    			ch2->MaxI=200;
    			ch2->MaxErr=1e+006;
    			ch2->MaxOutput=200;
    			ch2->DeadBandGain=1;
    			ch2->DeadBandRange=0;
    			ch2->InputChan0=2;
    			ch2->InputChan1=0;
    			ch2->OutputChan0=6;
    			ch2->OutputChan1=0;
    			ch2->MasterAxis=-1;
    			ch2->LimitSwitchOptions=0x0;
    			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.1;
    			ch2->MaxFollowingError=1000000000;
    			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;
    			
    			// END OF COPY & PASTE
    									 
    			SaveZLimits = ch2->LimitSwitchOptions;          	// Save how the limit is set
    			ch2->LimitSwitchOptions = 0;			        // Disable the limit
    			EnableAxis(2);					        // Enable Z axes and begin servoing where we are 
    											// jog z-axis until it sees the limit
    			Jog(2,100);							// jog slowly positive
    			while (!ReadBit(10)) ; 		 			// loop until IO bit goes high
    			Jog(2,0);							// stop
    			while (!CheckDone(2)) ; 				// loop until motion completes 
    			DisableAxis(2);						// disable the axis
    			Zero(2);							// Zero the position 
    			EnableAxis(2);						// re-enable the ServoTick
    			Move(2,-1000.0);						// move some amount inside the limits
    			while (!CheckDone(2)) ; 			        // loop until motion completes 
    			ch2->LimitSwitchOptions = SaveZLimits;          // restore limit settings
    				 
    			}
    
    printf("Done\n"); 
    
    }

  2. #2
    Join Date
    Feb 2010
    Posts
    371
    I just got a KFlop so I can't answer many of your questions, but I code for a living so I can at least help out on three related questions:

    if (flags==4)// Why is this not flags==2 if bit2=y?

    Remeber we are talking binary here. For a number that is 8 bits long, (00000000), bit0 (the rightmost position) will give you either a 1 or a zero. Bit1, the second from the right, is the two's position, so it contributes either zero to two, and similarily the third bit is the four's position. The value of each bit takes on this form:
    2^7, 2^6, 2^5, 2^4, 2^3, 2^2, 2^1, 2^0

    Incidentally, the source code would fail if X and Y were both set as flags would then equal 5, although I suspect in practice that would not happen. Just something to keep in mind when working with bit flags.

    If you want to check to see if an individual bit is set, I would normally code.
    if (flags&0x04){....} // here you are 'AND'ing the flags value with 4 to isolate the value of the bit2

    Eric

  3. #3
    Join Date
    Mar 2003
    Posts
    35538
    2 limit switches X++, X—per axis
    2 E-stop Over travel Switches per axis
    Can't actually help, but what is the purpose of the "E Stop Over Travel" switches?
    Limit switches are over travel switches.
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  4. #4
    Join Date
    Feb 2008
    Posts
    216
    Quote Originally Posted by AiR_GuNNeR View Post
    I just got a KFlop so I can't answer many of your questions, but I code for a living so I can at least help out on three related questions:

    if (flags==4)// Why is this not flags==2 if bit2=y?

    Remeber we are talking binary here. For a number that is 8 bits long, (00000000), bit0 (the rightmost position) will give you either a 1 or a zero. Bit1, the second from the right, is the two's position, so it contributes either zero to two, and similarily the third bit is the four's position. The value of each bit takes on this form:
    2^7, 2^6, 2^5, 2^4, 2^3, 2^2, 2^1, 2^0

    Incidentally, the source code would fail if X and Y were both set as flags would then equal 5, although I suspect in practice that would not happen. Just something to keep in mind when working with bit flags.

    If you want to check to see if an individual bit is set, I would normally code.
    if (flags&0x04){....} // here you are 'AND'ing the flags value with 4 to isolate the value of the bit2

    Eric
    Thanks AirGunner, i wasn't thinking in terms of Binary. There is a reason i went with Mechanical engineering instead of Software or Electrical!

  5. #5
    Join Date
    May 2006
    Posts
    4045
    Hi Slimneil,

    When using Mach3 with KFLOP Homing is handled by KFLOP. So there is no need to configure the Home input within Mach3. In fact if you do so I don't think Mach3 requests our Plugin to do the Homing. Watch the KMotion Console Screen for printouts to see if the Home Program is ever being called.

    Normally RESET will call an Initialization C Program to configure all the KFLOP Axis Parameters so there is no need to set them in the Home Program also, but it shouldn't hurt anything to do so.

    I think in Mach3 to home you need to push the "Ref" or "Ref all home" button to home the axis. The "Zero" button is something else. It just sets a Work offset to make the current position and the DROs read zero.

    I see in your Home Program you are checking bit 19 for X and bit 10 for Y and Z. That might be a bug.

    HTH
    Regards
    TK
    http://dynomotion.com

  6. #6
    Join Date
    Feb 2008
    Posts
    216

    Still not working with simplified approach....

    Thanks for the feedback but nothing is working.

    I've abandoned Mach3 for now in hope of getting KmotionCNC to be able to run the Home program for itself and and it won't work.

    This is what i have done, hopefully some one can point out my error.....

    In Kmotion, I went to Tool Setup-->User Buttons-->for Button name HOME I change it to Execute Prog. Thread 1, VAR 0, C File is called Simplehome.c


    I have no idea what Thread 1-7 are or what VAR is, there is no description that I could find in this section of the manual. There looks to be 1-7 G-code programs that could be run on the main page. I tried setting it to different threads and then clicking the different programs with no change.

    The C Program I am using is called Simplehome.c

    Code:
     
    
    #include "KMotionDef.h"
    
    main()
    {
    	Jog(0,-50);               // start moving
    	while (!ReadBit(19)) ;  // wait for switch (input #19) to change
    	Jog(0,0);		       // stop
    }
    I have the X Limit switch correctly working on Pin 10 , I/O Bit 19 on JP4. It turns the Digital I/O on/off in Kmotion when flicked so I know it is working.
    I then move the machine in the positive X direction in Kmotion CNC and then hit the Home button and it does nothing! It won't even travel backwards towards the hoem switch. What am I doing wrong? This seems dead simple.

    I’m not running a program in Kmotion CNC or have the Y or Z axis set up yet, just the X+ and X- limits and X home switch.

  7. #7
    Join Date
    May 2006
    Posts
    4045
    Hi Slimneil,

    It looks like everything you are doing is correct. But it is simpler to debug C code using KMotion.exe C Programs Screen. Then only after it is working ok assign it to a button in KMotionCNC. In KMotion.exe you can also look at the Axis Screen to see if the axis is enabled and if the Destination ever changes.

    The only thing I can think of is that you have never told us whether your Home Input is on or off while in the Home Switch. Your program is written to stop as soon as IO bit 19 turns on. If it is already on then it will never move at all.

    This line:

    while (!ReadBit(19)) ; // wait for switch (input #19) to change

    can be interpreted as: "while NOT bit #19 loop doing nothing". To wait while high remove the "!"

    Regarding your question on Threads: KFLOP has a concept of Threads which are basically places where programs can be loaded and run (nothing related to GCode files). KFLOP has 7 User Threads and so can have up to 7 User C Programs running at the same time. The main thing to understand is that if you wish to have two threads running at the same time then assign them to run in different Threads. Usually the main Initialization Program is assigned to run in Thread #1 and may run forever. So you might want to used Thread #2 for your Home Program. See here for more info.

    Regarding your Question on Var: When M/S Codes Programs run some associated parameters are downloaded to a Persist.UserData Variable in KFLOP as a way to pass data to the Program. For example an S command will set the desired Speed in RPM into the Variable. In your case it is not relevant.

    HTH
    Regards
    TK
    http://dynomotion.com

  8. #8
    Join Date
    Feb 2008
    Posts
    216
    Thanks Tom,

    We figured out that the Home switch needed to be set to "normally off" until activated right as you were posting the question (It was set to "normally on" before that point". So I now can successfully home the X-Axis with the Simplehome.c code. I'll have to try my luck with a different C-Code which has the built in Zero function. Is all i need to do is add a command "Zero(0)" to the code to do this? Or do i need to disable the axis, then zero command, then enable axis again to make it work?

    The next obstacle is going to be E-Stops.

    How should i set them up in Kmotion? As an Input or Output?
    The Limits are Outputs, the Home Switch is an input.
    I'm thinking it should be configured the same way as the Limits?

    Thanks again for all your help!

  9. #9
    Join Date
    May 2006
    Posts
    4045
    Hi Slimneil,

    You should be able to use:

    while (!CheckDone(0)) ; // wait till we are stopped
    Zero(0); // Set current position to 0

    Because the Jog(0,0); only initiates the deceleration to a stop, we should wait until we actually come to a stop before Zeroing the position

    I don't understand how Limits could be outputs. Normally they are inputs to KFLOP to tell KFLOP to stop the axis.

    EStop is usually best just hard wired to kill all motor power to your system. But you may also want to have an additional enable coming from KFLOP so KFLOP can keep all power off until it is ready to initialize the system. Additionally you might have a signal going to KFLOP to signal EStop has been pushed.

    HTH
    Regards
    TK
    http://dynomotion.com

  10. #10
    Join Date
    Feb 2008
    Posts
    216

    Homing Update

    Hi Tom,

    I miss typed before about the limits being outputs. All of the limits and homing switches are inputs. The Limits are always set to high until triggered low. We thought this would be the safe approach if a switch were to stop working or ground. The homing is low until triggered high.

    Thanks for the help, we managed to get it to work using the checkdone(0) command in post 9. It would contact the limit switch. The zero and then move away from the limit, then zero again. (The first zero was so that we knew that is was moving away) It was moving so fast it was hard to tell.
    Now that we have this basic homing functionality working, we want to try and get the Encoder Index to make homing even more accurate. We wired the encoder Index Z to Pin 8 on the Kflop. It sends out a 5V pulse and is detectable by the Kflop I/O screen when driven slow enough.
    I tried to use the same homing routine that worked for the initial limit switch, but I can’t get it to continue to move backwards until the encoder index pulses back to the Kflop.

    Code:
    #include "KMotionDef.h"
    //simplehomeron7.c
    main()
    {
    	Jog(0,-5000);          		// start moving towards home
    	while (!ReadBit(19)) ; 		// wait for switch (input #19) to change, input 19 is X Home
    	Jog(0,0);		   	// stop
    	while (!Checkdone(0));		// loop until motion complete
    
    //Continue to move until Incoder Index is reached
    	Jog(0,-1000);          		// start moving
    	while (!ReadBit(8)) ; 		// wait for switch (input #8) to change, input 8 is Encoder Z input
    	Jog(0,0);		      	// stop
    	while (!Checkdone(0));		//loop until motion complete
    	Zero(0);
    	
    //Move off of limit switch
    	Move(0,1000.0);
    	while (!Checkdone(0));		//loop until motion complete
    	Zero(0);

    The above code is what we are using and it still acts like the normal homing routine where it stops and then moves forward 1000 counts.
    Could it be that there isn’t enough time to slow down before it starts the second Jog command? Is there a way to insert a pause to time delay between functions? TO make it more apparent when something starts and stops? I tried googling it and the C programing stuff I tried didn’t do anything.

  11. #11
    Join Date
    May 2006
    Posts
    4045
    Hi Slimneil,

    Your code looks correct to me if the index pulses high. Is the check on the Digital IO Screen normally unchecked and pulses checked when at the index mark?

    You can easily add big delays for debugging by inserting:

    Delay_sec(10.0); // delay for 10 seconds

    Another possibility is noise. You may not see it on the Digital IO Screen because it only samples about every 1 sec for the screen. But the program will watch the signal continuously and stop on the first noise pulse.

    To isolate between a hardware or software problem disconnect the input signal and ground the pin. The axis should then move forever looking for the index.

    BTW you meant to say IO 8 not Pin 8 I presume.

    HTH
    Regards
    TK
    http://dynomotion.com

  12. #12
    Join Date
    Feb 2008
    Posts
    216

    New C program, still can't get Mach3 to home properly

    Since the last post we have built the machine and have all 3 axis running and homing properly in KmotionCNC when i hit the button i have assigned for homing.

    I have tried to make this Homing program work in Mach3. But i can not get Mach3 to send the request to Kmotion.

    Correct me if i am wrong:
    1-I have tested the homing program in Kmotion and it works every time, maybe i have the wrong call out part at the start of the C Code.
    2- I have assigned this homing C code in the Mach3 > COnfig > Config Plugin> Dynomotion > Home User, with Thread 3, Variable Flags 5.
    3- The standard button configurations in Mach3 should home properly. (By clicking on the Ref All Home button it should send the command to Kmotion)?
    When i hit the button in mach3, it doesn't do anything when i look at the Kmotion Console, it doesn't change anything at all.

    I want to Home Z first, then Y , then X.

    It's written like:
    Move backwards until the proximity switch is fired, then keep moving slowly until the Index pulse is detected, then move forward off of the index pulse a very small amount. I have a proximity switch and Encoder index pulse for each axis and i know they are all working, again i think its in the start of the code becuase Kmotion doesn't even get the request to start the homing c program.

    Thanks for the help.

    C Program also attached.
    Code:
    #include "KMotionDef.h"
    
    //Plugin calls for Mach3 Home (actually Purge) Commands
    #define X 0
    #define Y 1
    #define Z 2
    
    main()
    {
    	int flags = persist.UserData[5];  		// Mach3 flags bit0=X, bit1=Y, Bit2=Z, etc...
    
    	printf("Mach3 Home Call, flags = %d\n",flags); 
    	
    	
    	
    	if (flags & 4)                           // Why is this not flags==0 if bit0=x?
    	{
    		
    	//////////////////////////HOMING z
    	Jog(Z,5000)   ;      // start moving
    	while(!ReadBit(10)) ; // wait for switch (input IO#  10) (Z Home Proximity switch) to change
    	Jog(Z,0);		      // stop
    	while (!CheckDone(0)) ; // loop until motion completes
    	Zero(Z);				//Zero Z DRO
        
    	Delay_sec(2.0);    
            Jog(Z,50);          // start moving
    	while (!ReadBit(28)) ; // wait for encoder home Z signal (input IO# 28) (Y encoder Home switch) to change
    	Jog(Z,0);		      // stop
    
    	Delay_sec(2.0);		//Delay_sec(2.0);
    	Zero(Z);  		//Zero Y Coordinates
    	Move(Z,-10); 		// Moves Encoder off of encoder home signal to save relay from buzzing.
    
    	Delay_sec(2.0);		//Delay_sec(2.0);
    	Zero(Z);  	
    	}
    						
    		if (flags & 2)
    		{
    		//////////////////////////HOMING Y
    		Jog(Y,-3000)   ;      // start moving
    		while(!ReadBit(9)) ; 		// wait for switch (input IO#  09) (Y Home Proximity switch) to change
    		Jog(Y,0);		      // stop
    		while (!CheckDone(0)) ; 		// loop until motion completes
    		Zero(Y);				//Zero Y DRO
        
    		Delay_sec(2.0);    
        
    		Jog(Y,-14);          // start moving
    		while (!ReadBit(27)) ; // wait for encoder home Y signal (input IO# 27) (Y encoder Home switch) to change
    		Jog(Y,0);		      // stop
    		Delay_sec(2.0);		//Delay_sec(2.0);
    		Zero(Y);  			//Zero Y Coordinates
    		Move(Y,10); 		// Moves Encoder off of encoder home signal to save relay from buzzing.
    		Delay_sec(2.0);		//Delay_sec(2.0);
    		Zero(Y);  	
    		}
    
                            if (flags & 1)
    			{	
    			Jog(X,-1250);          // start moving
    	
    			while (!ReadBit(8)) ; // wait for switch (input #  08) (X Home switch) to change
    			Jog(X,0);		      // stop
    	
    			while (!CheckDone(0)) ; // loop until motion completes
    			Zero(X);				//Zero X DRO
    			Delay_sec(2.0);    
        
    			Jog(X,-10);          // start moving
    			while (!ReadBit(26)) ; // wait for encoder home Z signal (input #  09) (X encoder Home switch) to change
    			Jog(X,0);		      // stop
    			Delay_sec(2.0);	
    			Move(X,5);	// Moves Encoder off of encoder home signal to save relay from buzzing.
    			Delay_sec(2.0);
    			Zero(X);  
    			}
    
    //printf("Homing Done\n"); 
    
    }
    Attached Files Attached Files

  13. #13
    Join Date
    May 2006
    Posts
    4045
    Hi Slimneil,

    I think your assumptions are correct.

    Mach3 has a quirk if Homing Inputs are enabled in Mach3 | Config | Ports and Pins | Input Signals | X Home, Y Home, Z Home, A Home, B Home, C Home then Mach 3 will NOT call the Plugin to do Homing. Please make sure these Inputs are NOT enabled. KFLOP performs the Homing operation not Mach3 so Mach3 doesn't need to know anything about which inputs are used.

    I think the standard Mach3 REF ALL HOME button has code to do the axis order you describe. If not you can change the button code for REF ALL HOME.

    Regarding why "flags" is tested for 1, 2 and 4 is because "flags" is intended to be a binary number where each bit represents an axis so that any or all axes can be commanded to home at one time.

    1 = bit0 = 2^0
    2 = bit1 = 2^1
    4 = bit2 = 2^2
    8 = bit3 = 2^3

    That would allow a value like 7 (1+2+4) to home x,y,z. But Mach3 never seems to home more than one axis at a time.

    HTH
    Regards
    TK
    http://dynomotion.com

  14. #14
    Join Date
    Mar 2013
    Posts
    33

    Re: Mach3/Kflop - Homing 3 axis machine

    Hi All,

    I too am having no success getting Mach3 to home my axes.

    I have a simple 3 axis gantry. The X-axis has an X-- and an X++ limit switch. The Y-axis has only a Y++ limit switch, and the Z-axis has only a Z++ limit switch. I am using the X--, Y++, and Z++ limit switches as home switches. BTW, all switches are inductive proximity sensors and are active low. They have KFlop bit addresses as follows: X--, X++, Y++, Z++ are assigned bits 0,1,2,3 respectively. They work just fine in KMotion, and Mach3 will stop and wait for a RESET whenever I hit one, just as designed. However, clicking the REF ALL HOME button on the Program Run Screen in Mach3 does absolutely nothing. I am checking in the Console Screen, but see nothing when I click the REF ALL HOME button in Mach3. If I open the C program (that I have assigned to the HOME function in Mach3) in the C Program window within KMotion and then press the Save, Compile, Download, and Run button I see the following:

    Mach3 Home Call, flags = 0
    Done


    Which leads me to believe that the code is working, and the plugin is not being passed any arguments (flags). I am not sure how to debug any further. The code that I have assigned to the HOME function in the Mach3 Plugin Config window (Thread 3, Variable Flags 5) is as follows:

    #include "KMotionDef.h"

    //Plugin calls for Mach3 Home (actually Purge) Commands

    main()
    {
    int SaveXLimits,SaveYLimits,SaveZLimits; //place to save limit switch settings
    int flags = persist.UserData[5]; // Mach3 flags bit0=X, bit1=Y, Bit2=Z, etc...

    printf("Mach3 Home Call, flags = %d\n",flags);


    if (flags==1)
    {
    // do X homing here

    DisableAxis(0); // Disable X Axis

    ch0->InputMode=NO_INPUT_MODE;
    ch0->OutputMode=STEP_DIR_MODE;
    ch0->Vel=40000;
    ch0->Accel=400000;
    ch0->Jerk=4e+006;
    ch0->P=0;
    ch0->I=0.01;
    ch0->D=0;
    ch0->FFAccel=0;
    ch0->FFVel=0;
    ch0->MaxI=200;
    ch0->MaxErr=1e+006;
    ch0->MaxOutput=200;
    ch0->DeadBandGain=1;
    ch0->DeadBandRange=0;
    ch0->InputChan0=0;
    ch0->InputChan1=0;
    ch0->OutputChan0=0;
    ch0->OutputChan1=0;
    ch0->MasterAxis=-1;
    ch0->LimitSwitchOptions=0x12f;
    ch0->LimitSwitchNegBit=0;
    ch0->LimitSwitchPosBit=1;
    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=1000000000;
    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.92076;
    ch0->iir[2].A2=-0.923833;

    SaveXLimits = ch0->LimitSwitchOptions; // Save X-axis limit configs
    ch0->LimitSwitchOptions = 0; // Disable X-axis limits
    EnableAxis(0); // Enable X-axis and begin servoing where we are



    // Home X left - jog until it sees the limit

    Jog(0,-100); // jog slowly negative (left)
    while (ReadBit(0));// loop until IO bit goes low
    Jog(0,0); // stop
    while (!CheckDone(0)); // loop until motion completes
    DisableAxis(0); // disable the axis
    Zero(0); // Zero the position
    EnableAxis(0); // re-enable the ServoTick
    Move(0,1000.0); // move some amount inside the limits
    while (!CheckDone(0)); // loop until motion completes
    ch0->LimitSwitchOptions = SaveXLimits; // restore limit settings

    }




    if (flags==2)
    {
    // do Y homing here

    DisableAxis(1); // Disable Y Axis

    ch1->InputMode=NO_INPUT_MODE;
    ch1->OutputMode=STEP_DIR_MODE;
    ch1->Vel=40000;
    ch1->Accel=400000;
    ch1->Jerk=4e+006;
    ch1->P=0;
    ch1->I=0.01;
    ch1->D=0;
    ch1->FFAccel=0;
    ch1->FFVel=0;
    ch1->MaxI=200;
    ch1->MaxErr=1e+006;
    ch1->MaxOutput=200;
    ch1->DeadBandGain=1;
    ch1->DeadBandRange=0;
    ch1->InputChan0=1;
    ch1->InputChan1=0;
    ch1->OutputChan0=1;
    ch1->OutputChan1=0;
    ch1->MasterAxis=-1;
    ch1->LimitSwitchOptions=0x12a;
    ch1->LimitSwitchNegBit=0;
    ch1->LimitSwitchPosBit=2;
    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=1000000000;
    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;

    SaveYLimits = ch1->LimitSwitchOptions; // Save Y-axis limit configs
    ch1->LimitSwitchOptions = 0; // Disable Y-axis limits
    EnableAxis(1); // Enable Y-axis and begin servoing where we are


    // Home Y backward - jog until it sees the limit

    Jog(1,100); // jog slowly positive (backward)
    while (ReadBit(2)); // loop until IO bit goes low
    Jog(1,0); // stop
    while (!CheckDone(1)) ; // loop until motion completes
    DisableAxis(1); // disable the axis
    Zero(1); // Zero the position
    EnableAxis(1); // re-enable the ServoTick
    Move(1,-1000.0); // move some amount inside the limits
    while (!CheckDone(1)) ; // loop until motion completes
    ch1->LimitSwitchOptions = SaveYLimits; // restore limit settings

    }




    if (flags==4)
    {
    // do Z homing here

    DisableAxis(2); // Disable Z Axis

    ch2->InputMode=NO_INPUT_MODE;
    ch2->OutputMode=STEP_DIR_MODE;
    ch2->Vel=40000;
    ch2->Accel=400000;
    ch2->Jerk=4e+006;
    ch2->P=0;
    ch2->I=0.01;
    ch2->D=0;
    ch2->FFAccel=0;
    ch2->FFVel=0;
    ch2->MaxI=200;
    ch2->MaxErr=1e+006;
    ch2->MaxOutput=200;
    ch2->DeadBandGain=1;
    ch2->DeadBandRange=0;
    ch2->InputChan0=2;
    ch2->InputChan1=0;
    ch2->OutputChan0=2;
    ch2->OutputChan1=0;
    ch2->MasterAxis=-1;
    ch2->LimitSwitchOptions=0x12a;
    ch2->LimitSwitchNegBit=0;
    ch2->LimitSwitchPosBit=3;
    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=1000000000;
    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;

    SaveZLimits = ch2->LimitSwitchOptions; // Save Z-axis limit configs
    ch2->LimitSwitchOptions = 0; // Disable Z-axis limits
    EnableAxis(2); // Enable Z-axis and begin servoing where we are


    // Home Z up - jog until it sees the limit

    Jog(2,100); // jog slowly positive
    while (ReadBit(3)) ; // loop until IO bit goes low
    Jog(2,0); // stop
    while (!CheckDone(2)) ; // loop until motion completes
    DisableAxis(2); // disable the axis
    Zero(2); // Zero the position
    EnableAxis(2); // re-enable the ServoTick
    Move(2,-1000.0); // move some amount inside the limits
    while (!CheckDone(2)) ; // loop until motion completes
    ch2->LimitSwitchOptions = SaveZLimits; // restore limit settings

    }


    printf("Done\n");
    }

    This code is a modification of one of Tom's templates and I think I have it correct, based upon the research I have been doing here in this forum. (Thank goodness for the lot of you!!) I would appreciate any clarity as to how I can rectify this situation.

    Cheers,
    Jeff

  15. #15
    Join Date
    Mar 2013
    Posts
    33

    Re: Mach3/Kflop - Homing 3 axis machine

    ... Mach3 has a quirk if Homing Inputs are enabled in Mach3 | Config | Ports and Pins | Input Signals | X Home, Y Home, Z Home, A Home, B Home, C Home then Mach 3 will NOT call the Plugin to do Homing. Please make sure these Inputs are NOT enabled. KFLOP performs the Homing operation not Mach3 so Mach3 doesn't need to know anything about which inputs are used.
    Well, I am embarrassed. I just saw the post previous to my last one and, lo and behold, there was my solution (quoted above). I disabled the home inputs in Mach3 and REF ALL HOME worked. After tweaking the C Code to achieve a good hunt speed and to move .1000 off the home position I am quite satisfied.

    You know, I really don't mind being a newbie at this, but I'd like not to make myself look like one quite so often.

    Thanks for the info,
    Jeff

  16. #16
    Join Date
    Mar 2013
    Posts
    33

    Re: Mach3/Kflop - Homing 3 axis machine

    I am now totally confused. Last night (my last post, just previous to this one) I had everything working. Tonight, I can no longer REF ALL HOME. When I click that button, absolutely nothing happens. I can jog everything just fine, I can run the spindle, I just can't home anything.

    Last night I was even running the Roadrunner GCode program, albeit with a marker inserted and not a cutting tool. As I am using the Mach3 DEMO program, I was unable to run the whole program as I suppose it is too large for the demo mode. I ran across a bunch of demo GCode programs that are supposed to be small enough to run in demo mode. I loaded one that creates a scorpion. During the toolpath generation Mach3 hung. I had to use windows task manager to quit the program. After that I just shut the machine down and went to bed. Today I cannot home anymore. I have gone over everything that I can think of and used KMotion's Console Window to see what is being passed by Mach3. Only the spindle messages show up. Nothing for homing.

    I am at a complete loss here. I don't know what to do next. I am not going to buy Mach3 until I am CERTAIN that it will work. I am totally dismayed by how difficult it is to get all of this working. I sense that it really ISN'T that complex. I just need to better understand how this is supposed to work. Then I might be able to figure this out on my own, or at least without having to run to the forum quite so often. I really do appreciate all the help, it is just a slower way of learning. I guess I need to be more patient.

    I am at a complete standstill. If anyone can help me get going again, I would appreciate it very much. I am running out of time to get this machine operational.

    See post #14 (my last post) for technical details. Cheers.

    Thank you,
    Jeff

  17. #17
    Join Date
    Jun 2013
    Posts
    1041

    Re: Mach3/Kflop - Homing 3 axis machine

    My 2cents. Ditch mach3 and go with k-motion cnc. I know it doesn't have all the bells and whistles but it does a great job running code. Have you given it a try?

    Ben

  18. #18
    Join Date
    May 2006
    Posts
    4045

    Re: Mach3/Kflop - Homing 3 axis machine

    Hi Jeff,

    Are the Home Inputs Disabled?

    Is the Home Program configured in the Dynomotion Configuration?

    If you post your Mach3 XML file we can look at it.

    Regards
    TK
    http://dynomotion.com

  19. #19
    Join Date
    Mar 2013
    Posts
    33

    Re: Mach3/Kflop - Homing 3 axis machine

    Hi Tom and Ben,

    Yes, the homing inputs are diabled. I tried the homing program, minus the flags from Mach3, in KMotionCNC and it worked perfectly. This made no sense so I started poking around in Mach3 some more. When I looked into the Operator|Restore Settings feature it seemed to apply, as I had experienced a crash. Long story short; I found a previous configuration the worked. I checked that XML file against the one I had been using and could not find a difference (though that is a LOT of repetitive info to stare at). After working in IT for 15 years I learned that things occur for which an explanation will never be found, particularly where software is concerned. Hence the reason I am a hardware guy! So, it is back to working again and I have made three copies of that XML file including one stored off the machine. A little paranoia at this point is probably called for.

    I do think that I will use both KMotionCNC and Mach3 eventually, Ben. I like the fact that I can do so much with Tom's product, so long as I have the imagination and programming skills. For now though, I want to use Mach3 as it seems (at this time) to have more users and therefore likely more information for newbies like me. Once I'm more experienced, I really want to see what kind of trouble I can get into with the KFLOP. With the kind of support you get from Tom, I feel confident that I will be able to do a lot more with it once my skills improve a notch or two.

    You two have been quite helpful. Thank you both. I am sure this is not the last time you'll see a post from me. Tomorrow, perhaps? Or, even this evening ...

    Cheers!
    Jeff

  20. #20
    Join Date
    Feb 2008
    Posts
    216

    Re: Mach3/Kflop - Homing 3 axis machine

    I too was trying to get both Mach3 and KmotionCNC to work. I've found that Mach3 seems to be less consistent with results not being repeatable. We've moved over to KmotionCNC's latest version and it seems to be much better then the version we were using 2 years ago when we started out.

Page 1 of 2 12

Similar Threads

  1. Replies: 13
    Last Post: 06-25-2014, 02:21 PM
  2. Axis stop moving - KFlop - SnapAmp - Mach3
    By PapstDFrisco in forum Dynomotion/Kflop/Kanalog
    Replies: 11
    Last Post: 04-11-2014, 09:56 PM
  3. Mach3/Kflop - Homing
    By Snipes44 in forum Dynomotion/Kflop/Kanalog
    Replies: 5
    Last Post: 10-18-2012, 06:06 AM
  4. Mach3 vs Kflop
    By MarunovV in forum Dynomotion/Kflop/Kanalog
    Replies: 13
    Last Post: 07-25-2012, 08:54 PM
  5. RW20:How to move axis without homing the machine
    By adolfoe in forum Milltronics
    Replies: 2
    Last Post: 01-05-2012, 04:57 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •