Need Help! 4th Axis: Using soft limits to prevent table crashes? - Page 2


Page 2 of 2 FirstFirst 12
Results 13 to 16 of 16

Thread: 4th Axis: Using soft limits to prevent table crashes?

  1. #13
    Registered
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    204
    Downloads
    0
    Uploads
    0

    Default Re: 4th Axis: Using soft limits to prevent table crashes?

    Quote Originally Posted by m_c View Post
    That V2 file should let you back out of limits, however it's still disabling things.

    What I think you're wanting to do, is activate a feedhold when you enter your no-fly zones.
    Then as Tom has said, you want some way to track/test how you ended up in the no fly zone, then only allow movement in the safest direction.

    However, I suspect that provided things stop when you hit a no-fly zone, you'd be happy enough to simply disable the no-fly zones, move to a safe point, then re-enable the no-fly zones?
    Yeah, when it breaches a no fly zone it stops instantly, there is no drift. A feedhold is all im looking for.



  2. #14
    Registered
    Join Date
    Jun 2004
    Location
    Scotland
    Posts
    288
    Downloads
    0
    Uploads
    0

    Default Re: 4th Axis: Using soft limits to prevent table crashes?

    In that case, instead of disabling all the axes, you want to use this line-
    Code:
    StopCoordinatedMotion();  //feedhold
    Then the easiest way to enable/disable things, is to have a button that simply toggles a virtual, so you should end up with something like this-
    Code:
    #include "KMotionDef.h"
    
    #define XRes 19190.2062692 //Counts/inch
    #define YRes 22854.4476 //Counts/inch
    #define ZRes 28853.846 //Counts/inch
    
    #define XMIN_Head 	40
    #define YMIN_Head	15
    #define XMAX_Head 	54
    #define YMAX_Head	34
    
    #define XMIN_Tail 	60
    #define YMIN_Tail	20
    #define XMAX_Tail 	70
    #define YMAX_Tail	34
    
    #define NoFlyEnabled 1020 // 1020 picked at random!!! Change to something unused
     
    int X1=XMIN_Head*XRes;
    int X2=XMAX_Head*XRes;
    int X3=XMIN_Tail*XRes;
    int X4=XMAX_Tail*XRes;
    
    
    int Y1=YMIN_Head*YRes;
    int Y2=YMAX_Head*YRes;
    int Y3=YMIN_Tail*YRes;
    int Y4=YMAX_Tail*YRes;
    
     
    main()
    {
    	for (;;)  // loop forever
    	{
    		if (ReadBit(NoFlyEnabled) && InLimit())  // If our no fly zones are enabled, and we're in one
    		{
    			StopCoordinatedMotion();  // activate feedhold
    		}
    	}
    }
    
    int InLimit()
    {
    	WaitNextTimeSlice();
    	
    return ((ch0->Dest >X1 && ch0->Dest <X2) && (ch1->Dest >Y1 && ch1->Dest<Y2)) || ((ch0->Dest >X3 && ch0->Dest<X4) && (ch1->Dest > Y3 && ch1->Dest<Y4));
    
    }
    You'll need to add some way to toggle the virtual bit, but all that loop should do now, is if your no fly zones are enabled, and you're within one, it will activate a feedhold.
    Once you disable the no fly zones, you'll be able to jog around with no limitations.



  3. #15
    Gold Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    2620
    Downloads
    0
    Uploads
    0

    Default Re: 4th Axis: Using soft limits to prevent table crashes?

    Hi Dan,

    I also realised that this soft limits code doesn't work when i'm doing a tool change (M6 C Program) or when homing the machine (Homing C Program). How do I keep this program active when other C programs are being initiated?
    I'm not sure how you are running the code. If you are running it in some Thread and then run some other program (Tool change or home) in the same Thread then the new program will kill and overwrite the Limits program. Normally you would add the Limits checking to a forever loop at the end of your Initialization program.

    I see that there are 2 Soft Limit files in the example C code Folder. Does the Rev 2 file include the back up approach for a simple soft limit working envelope?
    Yes the idea is to only disable if in the Limit and also moving in the direction of the limit. That is an older example there is now a better variable available called ch->DirectionOfMotion

    Here is a program that might work (untested ) It should only disable if moving inward within either of your zones. That should allow you to re-initialize and remain enabled even if you are within a zone as long as you don't move the wrong direction.

    Actually I only now realize that this assumes the machine coordinates are still correct after a re-initialization. Is this true? Also before Homing we don't know where we are or where the zones are so we can't really do any protection. How are you handling this now?

    Code:
    #include "KMotionDef.h"
    
    #define XRes 19190.2062692 //Counts/inch
    #define YRes 22854.4476 //Counts/inch
    #define ZRes 28853.846 //Counts/inch
    
    #define XMIN_Head 	40
    #define YMIN_Head	15
    #define XMAX_Head 	54
    #define YMAX_Head	34
    
    #define XMIN_Tail 	60
    #define YMIN_Tail	20
    #define XMAX_Tail 	70
    #define YMAX_Tail	34
    
    
    int X1=XMIN_Head*XRes;
    int X2=XMAX_Head*XRes;
    int X3=XMIN_Tail*XRes;
    int X4=XMAX_Tail*XRes;
    
    
    int Y1=YMIN_Head*YRes;
    int Y2=YMAX_Head*YRes;
    int Y3=YMIN_Tail*YRes;
    int Y4=YMAX_Tail*YRes;
    
    void HandleZone(double minx, double maxx, double miny, double maxy);
    BOOL CheckInRange(double x, double min, double max, int *dir);
    
    main()
    {
        for (;;)  // loop forever
        {
            WaitNextTimeSlice();
            HandleZone(X1,X2,Y1,Y2);  // disable if moving in a bad direction in Head Zone
            HandleZone(X3,X4,Y3,Y4);  // disable if moving in a bad direction in Tail Zone
        }
    }
    
    // Disable all if we are within a Zone and either x or y are moving in a bad direction 
    void HandleZone(double minx, double maxx, double miny, double maxy)
    {
        int dirx, diry;
        if (CheckInRange(ch0->Dest, minx, maxx, &dirx) &&
            CheckInRange(ch1->Dest, miny, maxy, &diry) &&
            (ch0->DirectionOfMotion == dirx || ch1->DirectionOfMotion == diry))
        {
            DisableAxis(0);
            DisableAxis(1);
            DisableAxis(2);
        }
    }
    
    // check if within range and if so return direction that 
    // would move further inward from the closest edge
    // returns true if within range 
    BOOL CheckInRange(double x, double min, double max, int *dir)
    {
        if (x>min && x<max)  // within range?
        {
            if (x-min < max-x) // closer to min?
                *dir = 1;  // yes, positive would go further inward
            else
                *dir = -1; // no, negative would move further inward
    
            return TRUE;
        }
        return FALSE;
    }


    TK
    http://dynomotion.com


  4. #16
    Registered
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    204
    Downloads
    0
    Uploads
    0

    Default Re: 4th Axis: Using soft limits to prevent table crashes?

    -Each C program is ran in a separate thread. Initialization, Homing, Soft Limit, etc. I didn't get to the point of adding the soft limits code to the Initialization file. I was just testing it out of the C program area in Kmotion.

    -We damaged the Z Axis Viper drive during our initial test, so we are down to 3 axis for now. Once it gets fixed and I'm back in town I'll have another go at this little project.

    -Before homing I manually make sure the spindle isn't going to crash into anything, I didn't really think about that issue either until you said that. At this point we are just trying to learn how to program the 4th axis and make that work. Tool changes are being done manually for now, but once i get into 4th axis with automatic tool changes i'll have to tweak my post processor or Tool change C code so that it moves the spindle clear of the rotary axis zone before retrieving a tool and then brings it back to the same location before continuing with that new tool so that it doesn't crash depending on the 4th axis direction (X or Y) configuration. It shouldn't be an issue when the 4th axis runs along the Y direction but it till be when it's run along the X.

    Happy Holidays Tom



Page 2 of 2 FirstFirst 12

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
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

4th Axis: Using soft limits to prevent table crashes?
4th Axis: Using soft limits to prevent table crashes?