586,404 active members*
2,501 visitors online*
Register for free
Login
Results 1 to 17 of 17
  1. #1
    Join Date
    Mar 2015
    Posts
    20

    Working with KFlop Script

    I am working on a simple C++ program . I have connected my Kstep and Kflop to one motor only
    Here is my code

    Code:
    	KM = new CKMotionDLL(0);  // create as board 0
    	char response[MAX_LINE];
    
    
    	// Setup Axis for a simple stepper motor
    
    
    	if (KM->WriteLine( "DisableAxis0=0"))	MyError(); // Set board 0, Axis 1 to OFF while changing parameters
    	if (KM->WriteLine( "Zero0=0"))			MyError(); // Zero position board 0, Axis 1
    	if (KM->WriteLine( "StepperAmplitude0=150"))MyError(); // Set nominal Sine wave amplitude to 80/256 of Motor supply voltage
    	if (KM->WriteLine( "Vel0=2000"))			MyError(); // Set Max Velocity to 100 cycles/sec (4 full steps/sec = 1 cycle)
    	if (KM->WriteLine( "FFAccel0=100"))			MyError(); // Set Max Acceleration to 50 cycles/sec2 
    	if (KM->WriteLine( "Jerk0=10000.0"))		MyError(); // Set Max Jerk to 2000 cycles/sec3 
    	if (KM->WriteLine( "Lead0=10"))			MyError(); // Set Inductance Lead compensation to 10 * dV/dt 
    	if (KM->WriteLine( "OutputMode0=6"))		MyError(); // Set board 0, Axis 1 to MICROSTEP_MODE (see KMotionDef.h)
    	if (KM->WriteLine( "EnableAxisDest0 100"))	MyError(); // Zero position board 0, Axis 1
    	if (KM->WriteLine( "Echo Setup Complete")) MyError(); // Echo a string to console 
    	if (KM->WriteLine( "OutputChan00=8"))		MyError(); // Set board 0, Axis 1 to MICROSTEP_MODE (see KMotionDef.h)
    	
    
    
    
    
    
    
    	if (KM->WriteLine( "Move0= - 10000"))  MyError();
              if (KM->WriteLine( "Move0= 0"))  MyError();
             if (KM->WriteLine( "Move0=10000"))  MyError();


    When I execute the above code, I expect to see my actuator goes tothe -10000 postion, then goes to 0 then go tot 10000 position, but it just execute the last line and goes to the 10000 postion. How can I have it go through each line. instead of skipping to the last.

    I want to read the positions later from a text file and my my own protocol. I want to be able to send the actuator to different potions line by line.

  2. #2
    Join Date
    May 2006
    Posts
    4047

    Re: Working with KFlop Script

    Hi JimmyJackson,

    You are not waiting for the first two moves to complete so only the last has time to actually complete.

    You will need to wait until each move completes by polling KFLOP to see when the axis has completed the motion. KFLOP has a status command "CheckDone0" that will return 0 if Axis 0 is still moving, 1 if it has completed, and -1 if the Axis is disabled. You can us the WriteLineReadLine function to send the command and get the result.

    btw you should only enable an axis after it has been fully configured including the OutputChan value.

    HTH
    Regards
    TK
    http://dynomotion.com

  3. #3
    Join Date
    Mar 2015
    Posts
    20

    Re: Working with KFlop Script

    Thank you Tom .

    I added this
    Code:
    do	{
    		if (KM->WriteLineReadLine("CheckDone1",response))
    			MyError();
    	} 
    	while (response[0] != '1');
    
    
    	if (KM->WriteLine("Echo Move Complete")) MyError(); // Echo a string to console
    according to your example
    So my code is like this

    Code:
    
    if (KM->WriteLine( "Move1=10000"))  MyError();
    	
    
    	// loop until complete status = 1
    
    
    	do
    	{
    		if (KM->WriteLineReadLine("CheckDone1",response))
    			MyError();
    	} 
    	while (response[0] != '1');
    
    
    	
    if (KM->WriteLine( "Move0=10000"))  MyError();

    but it still doesn't work. Does it look right to you ?

  4. #4
    Join Date
    May 2006
    Posts
    4047

    Re: Working with KFlop Script

    Hi JimmyJackson,

    It looks correct to me. I assume you intended to then move a different Axis? What are your starting positions? What happens? You might debug it by printing things and by making moves that take many seconds and observing the Done Status and Destination Status on the KMotion.exe Axis Screen.

    Regards
    TK
    http://dynomotion.com

  5. #5
    Join Date
    Mar 2015
    Posts
    20

    Re: Working with KFlop Script

    my bad. It's one axis. and it worked.

  6. #6
    Join Date
    Mar 2015
    Posts
    20

    Re: Working with KFlop Script

    I am adding my other axises. I have trouble with axis 4 of KSTEP.
    I can't get the motor to move.


    Code:
            if (KM->WriteLine( "DisableAxis3=0"))	MyError(); // Set board 0, Axis 1 to OFF while changing parameters
    	if (KM->WriteLine( "Zero3=0"))			MyError(); // Zero position board 0, Axis 1
    	if (KM->WriteLine( "StepperAmplitude3=150"))MyError(); // Set nominal Sine wave amplitude to 80/256 of Motor supply voltage
    	if (KM->WriteLine( "Vel3=2000"))			MyError(); // Set Max Velocity to 100 cycles/sec (4 full steps/sec = 1 cycle)
    	if (KM->WriteLine( "FFAccel3=100"))			MyError(); // Set Max Acceleration to 50 cycles/sec2 
    	if (KM->WriteLine( "Jerk3=10000.0"))		MyError(); // Set Max Jerk to 2000 cycles/sec3 
    	if (KM->WriteLine( "Lead3=10"))			MyError(); // Set Inductance Lead compensation to 10 * dV/dt 
    	if (KM->WriteLine( "OutputMode3=6"))		MyError(); // Set board 0, Axis 1 to MICROSTEP_MODE (see KMotionDef.h)
    	if (KM->WriteLine( "EnableAxisDest3 0"))	MyError(); // Zero position board 0, Axis 1
    	if (KM->WriteLine( "Echo Setup Complete")) MyError(); // Echo a string to console 
    
    
    
    	if (KM->WriteLine( "Move3=10000"))  MyError();

  7. #7
    Join Date
    May 2006
    Posts
    4047

    Re: Working with KFlop Script

    Hi JimmyJackson,

    It doesn't look like you configured the Step/Dir Generator and mode to use. Try including:

    if (KM->WriteLine( "OutputChan03=11")) MyError(); // configure the Step/Dir Generator and mode to use

    Regards
    TK
    http://dynomotion.com

  8. #8
    Join Date
    Mar 2015
    Posts
    20

    Re: Working with KFlop Script

    Quote Originally Posted by TomKerekes View Post
    Hi JimmyJackson,

    It doesn't look like you configured the Step/Dir Generator and mode to use. Try including:

    if (KM->WriteLine( "OutputChan03=11")) MyError(); // configure the Step/Dir Generator and mode to use

    Regards
    Thank you Tom. I am still confused when I should use 11 and when 8 for outputChan.


    I am also trying to get my 5th motor to work, Here is my code, it doesn't work. I am using a separate stepper driver. The enable in hard wired and it works for Axis0 . but I can't get it to work for Axis 4


    if (KM->WriteLine( "DisableAxis4=0")) MyError(); // Set board 0, Axis 1 to OFF while changing parameters
    if (KM->WriteLine( "Zero4=0")) MyError(); // Zero position board 0, Axis 1
    if (KM->WriteLine( "StepperAmplitude4=150"))MyError(); // Set nominal Sine wave amplitude to 80/256 of Motor supply voltage
    if (KM->WriteLine( "Vel4=2000")) MyError(); // Set Max Velocity to 100 cycles/sec (4 full steps/sec = 1 cycle)
    if (KM->WriteLine( "FFAccel4=100")) MyError(); // Set Max Acceleration to 50 cycles/sec2
    if (KM->WriteLine( "Jerk4=10000.0")) MyError(); // Set Max Jerk to 2000 cycles/sec3
    if (KM->WriteLine( "Lead4=10")) MyError(); // Set Inductance Lead compensation to 10 * dV/dt
    if (KM->WriteLine( "OutputMode4=6")) MyError(); // Set board 0, Axis 1 to MICROSTEP_MODE (see KMotionDef.h)
    if (KM->WriteLine( "EnableAxisDest4 0")) MyError(); // Zero position board 0, Axis 1
    if (KM->WriteLine( "Echo Setup Complete")) MyError(); // Echo a string to console
    if (KM->WriteLine( "OutputChan04=8")) MyError(); // Set board 0, Axis 1 to MICROSTEP_MODE (see KMotionDef.h)









    if (KM->WriteLine( "Move4=10000")) MyError();

  9. #9
    Join Date
    May 2006
    Posts
    4047

    Re: Working with KFlop Script

    Hi JimmyJackson,

    Thank you Tom. I am still confused when I should use 11 and when 8 for outputChan.
    The OutputChan number tells the Axis what Step and Direction Generator should be driven which in turn determines which KFLOP Pins are driven. 8 drives Step and Direction Generator #0 and 11 drives Step and Direction Generator #3. The numbers are increased by 8 to select TTL mode. This is all explained here:
    Step and Direction Setup


    I am also trying to get my 5th motor to work, Here is my code, it doesn't work. I am using a separate stepper driver. The enable in hard wired and it works for Axis0 . but I can't get it to work for Axis 4
    You haven't told us how and where you have wired the driver. Which Step and Direction Generator is it wired to? What are its input requirements?

    Your comments in your program are mostly wrong regarding the Axis numbers and other things.

    You have not changed your code to tell the Axis which Output Channel to use before you enable the axis as I requested in the previous email.

    You are setting FFAccel rather than Accel.

    The Lead parameter has no effect on Step and Direction drives

    The StepperAmplitude parameter has no effect on Step and Direction drives


    HTH
    Regards
    TK
    http://dynomotion.com

  10. #10
    Join Date
    Mar 2015
    Posts
    20

    Re: Working with KFlop Script

    Thank you Tom. I am using the VC example and I didn't change the comments for different axis.
    The step and dir pins are wired to pin 1 and pin 2 of JP5 on Kflop that corresponds to the Axis4 I guess

  11. #11
    Join Date
    May 2006
    Posts
    4047

    Re: Working with KFlop Script

    Hi JimmyJackson,

    The step and dir pins are wired to pin 1 and pin 2 of JP5 on Kflop that corresponds to the Axis4 I guess
    Actually no. Those pins are connected to Step and Direction Generator #4 not Axis #4. They are not the same thing. Any Axis can be configured to use any Step and Direction Generator. If you want Axis #4 to use Step and Direction Generator #4 you still need to tell it to do so. You didn't answer my questions regarding your drive. Assuming it can accept TTL mode like KSTEP then add 8 to select that mode 4+8=12. Therefore OutputChan04=12

    Regards
    TK
    http://dynomotion.com

  12. #12
    Join Date
    Mar 2015
    Posts
    20

    Re: Working with KFlop Script

    Thank you Tom for your amazing support.

    I have another question. My axises are initialized .I am willing to have a toolpath of a rectangle. I have 4 coordinations in XY plane. Can you please hint me the best way to implement such toolpath, I tried to manually move each axis using ( Move0=4000) for example. but it doesn't blend the moves. It stops at one corner and then start the next move.

  13. #13
    Join Date
    May 2006
    Posts
    4047

    Re: Working with KFlop Script

    Hi Jimmyjackson,

    Do you realize that it is impossible to go around any corner without coming to a complete stop without introducing error and deviating from the specified path?

    What I believe you are asking for is fairly complex. This involves:

    #1 simultaneous coordinated motion of multiple axes
    #2 an arc inserted into the corners of the least amount of curvature that will not exceed a specified tolerance
    #3 The proper speed through the curve must be planned so as to not exceed any acceleration limits of any axes
    #4 accelerations and speeds before and after the curve must be appropriately planned
    #5 multiple segments must be buffered ahead of time within KFLOP so that all can occur smoothly even if Windows gets busy and momentarily freezes midway through the path.

    Fortunately we have motion libraries that will handle all this complexity for you. However it does require specifying all the necessary information for it to be able to do this for you. This involves the:

    Resolution of all the axes (so values can use units of inches)
    The max velocities of all the axes
    The max accelerations of all the axis
    The angles where moves should be rounded vs followed exactly (exact stop)
    Tolerance allowed to deviate from corners
    How much motion Time should be buffered in KFLOP

    See the SimpleCoordMotion example and let us know how much makes sense to you.

    Code:
    // SimpleCoordMotion.cpp : Defines the entry point for the console application.
    //
    
    
    #include "stdafx.h"
    #include "CoordMotion.h"
    
    // Global Variables
    
    CKMotionDLL *KM;
    CCoordMotion *CM;
    
    int count=0;  // just count the callbacks
    
    void StraightTraverseCallback(double x, double y, double z, int sequence_number)
    {
    	count++;
    }
    	
    void StraightFeedCallback(double DesiredFeedRate_in_per_sec,
    							   double x, double y, double z, int sequence_number, int ID)
    
    {
    	count++;
    }
    
    void ArcFeedCallback(bool ZeroLenAsFullCircles, double DesiredFeedRate_in_per_sec, 
    			    CANON_PLANE plane,
    				double first_end, double second_end, 
    		        double first_axis, double second_axis, int rotation,
    				double axis_end_point,
    				double first_start, double second_start, double axis_start_point, int sequence_number, int ID)
    {
    	count++;
    }
    
    
    int main(int argc, char* argv[])
    {
    	KM = new CKMotionDLL(0);  // create as board 0
    	CM = new CCoordMotion(KM);
    
    
    	MOTION_PARAMS *p=CM->GetMotionParams();
    
    	p->BreakAngle = 30;
    	p->MaxAccelX = 1;
    	p->MaxAccelY = 1;
    	p->MaxAccelZ = 1;
    	p->MaxAccelA = 1;
    	p->MaxAccelB = 1;
    	p->MaxAccelC = 1;
    	p->MaxVelX = 1;
    	p->MaxVelY = 1;
    	p->MaxVelZ = 1;
    	p->MaxVelA = 1;
    	p->MaxVelB = 1;
    	p->MaxVelC = 1;
    	p->CountsPerInchX = 100;
    	p->CountsPerInchY = 100;
    	p->CountsPerInchZ = 100;
    	p->CountsPerInchA = 100;
    	p->CountsPerInchB = 100;
    	p->CountsPerInchC = 100;
    
    	p->DegreesA = p->DegreesB = p->DegreesC = FALSE; 
    	p->ArcsToSegs = true;
    
    
    	CM->SetTPParams();  // Apply motion parameters to the Trajectory Planner
    
    	
    	CM->SetAbort();
    	CM->ClearAbort();
    
    	CM->SetStraightTraverseCallback(StraightTraverseCallback);
    	CM->SetStraightFeedCallback(StraightFeedCallback);
    	CM->SetArcFeedCallback(ArcFeedCallback);
    
    	
    	double Speed = 0.5; //inch/sec
    
    	int result = CM->ReadCurAbsPosition(&CM->current_x,&CM->current_y,&CM->current_z,
    										&CM->current_a,&CM->current_b,&CM->current_c,true);
    
    
    	CM->StraightTraverse(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000);  // jump back to zero
        
    	// set a bit, move in a circle, clear a bit
    
    	CM->DoKMotionBufCmd("SetBitBuf0");
            CM->ArcFeed(Speed,CANON_PLANE_XY,0.0000, 0.5000, 0.0000, 0.2500, DIR_CCW, 0.0000, 0.0000, 0.0000, 0.0000, 0, 0);
            CM->ArcFeed(Speed,CANON_PLANE_XY,0.0000, 0.0000, 0.0000, 0.2500, DIR_CCW, 0.0000, 0.0000, 0.0000, 0.0000, 0, 0);
    	CM->DoKMotionBufCmd("ClearBitBuf0");
    	
    	// move in an xy square (0,0) -> (0,0.5) -> (0.5,0.5) -> (0.5,0) -> (0,0)
    
    	CM->StraightFeed(Speed, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0, 0);
    	CM->StraightFeed(Speed, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0, 0);
    	CM->StraightFeed(Speed, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0);
    	CM->StraightFeed(Speed, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0);
    
    	// turn on a bit, wait 2 seconds, turn the bit off
    
    	CM->DoKMotionBufCmd("SetBitBuf0");
    	CM->Dwell(2,0);
    	CM->DoKMotionBufCmd("ClearBitBuf0");
    	CM->FlushSegments();
    	return 0;
    }

    HTH
    Regards
    TK
    http://dynomotion.com

  14. #14
    Join Date
    Mar 2015
    Posts
    20

    Re: Working with KFlop Script

    Quote Originally Posted by TomKerekes View Post
    Hi Jimmyjackson,

    Do you realize that it is impossible to go around any corner without coming to a complete stop without introducing error and deviating from the specified path?

    What I believe you are asking for is fairly complex. This involves:

    #1 simultaneous coordinated motion of multiple axes
    #2 an arc inserted into the corners of the least amount of curvature that will not exceed a specified tolerance
    #3 The proper speed through the curve must be planned so as to not exceed any acceleration limits of any axes
    #4 accelerations and speeds before and after the curve must be appropriately planned
    #5 multiple segments must be buffered ahead of time within KFLOP so that all can occur smoothly even if Windows gets busy and momentarily freezes midway through the path.

    Fortunately we have motion libraries that will handle all this complexity for you. However it does require specifying all the necessary information for it to be able to do this for you. This involves the:

    Resolution of all the axes (so values can use units of inches)
    The max velocities of all the axes
    The max accelerations of all the axis
    The angles where moves should be rounded vs followed exactly (exact stop)
    Tolerance allowed to deviate from corners
    How much motion Time should be buffered in KFLOP

    See the SimpleCoordMotion example and let us know how much makes sense to you.

    Code:
    // SimpleCoordMotion.cpp : Defines the entry point for the console application.
    //
    
    
    #include "stdafx.h"
    #include "CoordMotion.h"
    
    // Global Variables
    
    CKMotionDLL *KM;
    CCoordMotion *CM;
    
    int count=0;  // just count the callbacks
    
    void StraightTraverseCallback(double x, double y, double z, int sequence_number)
    {
        count++;
    }
        
    void StraightFeedCallback(double DesiredFeedRate_in_per_sec,
                                   double x, double y, double z, int sequence_number, int ID)
    
    {
        count++;
    }
    
    void ArcFeedCallback(bool ZeroLenAsFullCircles, double DesiredFeedRate_in_per_sec, 
                    CANON_PLANE plane,
                    double first_end, double second_end, 
                    double first_axis, double second_axis, int rotation,
                    double axis_end_point,
                    double first_start, double second_start, double axis_start_point, int sequence_number, int ID)
    {
        count++;
    }
    
    
    int main(int argc, char* argv[])
    {
        KM = new CKMotionDLL(0);  // create as board 0
        CM = new CCoordMotion(KM);
    
    
        MOTION_PARAMS *p=CM->GetMotionParams();
    
        p->BreakAngle = 30;
        p->MaxAccelX = 1;
        p->MaxAccelY = 1;
        p->MaxAccelZ = 1;
        p->MaxAccelA = 1;
        p->MaxAccelB = 1;
        p->MaxAccelC = 1;
        p->MaxVelX = 1;
        p->MaxVelY = 1;
        p->MaxVelZ = 1;
        p->MaxVelA = 1;
        p->MaxVelB = 1;
        p->MaxVelC = 1;
        p->CountsPerInchX = 100;
        p->CountsPerInchY = 100;
        p->CountsPerInchZ = 100;
        p->CountsPerInchA = 100;
        p->CountsPerInchB = 100;
        p->CountsPerInchC = 100;
    
        p->DegreesA = p->DegreesB = p->DegreesC = FALSE; 
        p->ArcsToSegs = true;
    
    
        CM->SetTPParams();  // Apply motion parameters to the Trajectory Planner
    
        
        CM->SetAbort();
        CM->ClearAbort();
    
        CM->SetStraightTraverseCallback(StraightTraverseCallback);
        CM->SetStraightFeedCallback(StraightFeedCallback);
        CM->SetArcFeedCallback(ArcFeedCallback);
    
        
        double Speed = 0.5; //inch/sec
    
        int result = CM->ReadCurAbsPosition(&CM->current_x,&CM->current_y,&CM->current_z,
                                            &CM->current_a,&CM->current_b,&CM->current_c,true);
    
    
        CM->StraightTraverse(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000);  // jump back to zero
        
        // set a bit, move in a circle, clear a bit
    
        CM->DoKMotionBufCmd("SetBitBuf0");
            CM->ArcFeed(Speed,CANON_PLANE_XY,0.0000, 0.5000, 0.0000, 0.2500, DIR_CCW, 0.0000, 0.0000, 0.0000, 0.0000, 0, 0);
            CM->ArcFeed(Speed,CANON_PLANE_XY,0.0000, 0.0000, 0.0000, 0.2500, DIR_CCW, 0.0000, 0.0000, 0.0000, 0.0000, 0, 0);
        CM->DoKMotionBufCmd("ClearBitBuf0");
        
        // move in an xy square (0,0) -> (0,0.5) -> (0.5,0.5) -> (0.5,0) -> (0,0)
    
        CM->StraightFeed(Speed, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0, 0);
        CM->StraightFeed(Speed, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0, 0);
        CM->StraightFeed(Speed, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0);
        CM->StraightFeed(Speed, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0);
    
        // turn on a bit, wait 2 seconds, turn the bit off
    
        CM->DoKMotionBufCmd("SetBitBuf0");
        CM->Dwell(2,0);
        CM->DoKMotionBufCmd("ClearBitBuf0");
        CM->FlushSegments();
        return 0;
    }

    HTH
    Regards



    Even Better. I actually tried to use your SimpleCoordMotion.cpp example but It cannot find CoordMotion.h . Can you please attach the ".h" file for me . thank you

  15. #15
    Join Date
    May 2006
    Posts
    4047

    Re: Working with KFlop Script

    The full example is in your installation. I just posted that fragment to give you an idea of the complexity.

    Regards
    TK
    http://dynomotion.com

  16. #16
    Join Date
    Mar 2015
    Posts
    20

    Re: Working with KFlop Script

    I mean CoordMotion.h is missing in my installation package. I searched all of the folders. It's not there.

  17. #17
    Join Date
    May 2006
    Posts
    4047

    Re: Working with KFlop Script

    Strange it should be at:

    C:\KMotion433k\GCodeInterpreter\CoordMotion.h

    Maybe you deleted it. Try re-installing KMotion if necessary.

    Regards
    TK
    http://dynomotion.com

Similar Threads

  1. What is the difference between wood working and metal working routers?
    By LaughingJaguar in forum Joes CNC Model 2006
    Replies: 9
    Last Post: 10-17-2016, 07:29 PM
  2. Replies: 8
    Last Post: 12-23-2014, 10:52 PM
  3. Bobcad V20.6 Script
    By Idiod in forum BobCad-Cam
    Replies: 2
    Last Post: 05-07-2013, 01:30 PM
  4. VB6,VB.net,VB script,What one???
    By hydrospin01 in forum Visual Basic
    Replies: 11
    Last Post: 05-25-2008, 02:09 AM

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
  •