Kflop thread/C program question


Results 1 to 13 of 13

Thread: Kflop thread/C program question

  1. #1
    Member
    Join Date
    May 2013
    Location
    Canada
    Posts
    16
    Downloads
    0
    Uploads
    0

    Default Kflop thread/C program question

    I have a scenario where my INIT program is in thread 1 and a "servo alarm/emergency stop" program is in thread 2. How would i go about running the program in thread 2 after my INIT program is ran in thread 1? For example, is there a way to call and run a C program at the end of my INIT file?


    I have attached my INIT file (thread 1) and the ESTOP thread 2 program. The latest approach we have been trying is through a global persist variable but It just wont seem to work. There must be a simpler solution.

    Any help would be appreciated,

    Thanks.

    -Curtis

    ps. here is a video of what the kflop is powering: https://photos.app.goo.gl/ac2uA86gZTNDMDj73

    Similar Threads:
    Attached Files Attached Files


  2. #2
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Hi Curtis,

    There isn't a simple way to have one Program load and execute another Program into another Thread as it isn't normally necessary.

    Combine the two loops into a single loop at the end of your INIT program.

    Regards

    Regards
    TK http://dynomotion.com


  3. #3
    Member
    Join Date
    May 2013
    Location
    Canada
    Posts
    16
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    After some further research, I found this:

    // M U L T I - T H R E A D S U P P O R T

    // user threads are numbered 1 .. n

    void StartThread(int thread); // starts a downloaded program at it's entry point
    void PauseThread(int thread); // stops a thread from executing
    int ResumeThread(int thread); // resumes a tread after a pause
    void ThreadDone(void); // call to terminate current thread
    extern int CurrentThread; // current thread that is/was executing 0 = Pri 1-7 = User Threads
    So I would presume that I could use void StartThread(int thread) in thread1 to call thread2.

    Does this sound right? or is there a better way?



  4. #4
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Hi Curtis,

    StartThread() will allow you to start a Program in another Thread but the Program must be first somehow loaded into that Thread.

    Its better to use the method I described in my previous post.

    Besides running two User Threads would slow down the response and consume more DSP resources unnecessarily.

    Regards

    Regards
    TK http://dynomotion.com


  5. #5
    Member
    Join Date
    May 2013
    Location
    Canada
    Posts
    16
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Thank you for your explanation,

    so my plan would have been to have an ESTOP program and a soft limits program load into threads 2 and 3 on powerup. They would be started from my INIT in thread1. But I hear what your saying and your approach sounds more logical. I suppose I was trying to make minimal changes to my INIT file and I found it easier to debug with separate C programs. Is it the common approach for people to incorporate soft limits, E-stop etc.. into their INIT file?



  6. #6
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Hi Curtis,

    Yes it is common to service everything that need continous service in one loop. You can still debug as separate Threads if you wish but after they are working merge into the INIT Program Thread.

    HTH
    Regards

    Regards
    TK http://dynomotion.com


  7. #7
    Registered
    Join Date
    Dec 2015
    Posts
    9
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Hello. I also have a thread question. The Kflop controller supports 7 threads, that is, simultaneous start of 7 independent programs with equal priorities downloaded from C files, if it is necessary to use more than 7 programs, then some are deleted and others are written in their place? All possible variants of the CNC operation should be provided by only 7 programs, or you can write several programs in one thread and connect the necessary ones depending on the situation.
    Completed, what is the purpose of the Var parameter in the Tool Setup Screen / User button?Kflop thread/C program question-333-jpg



  8. #8
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Hi Lotreck,

    I also have a thread question. The Kflop controller supports 7 threads, that is, simultaneous start of 7 independent programs with equal priorities downloaded from C files, if it is necessary to use more than 7 programs, then some are deleted and others are written in their place? All possible variants of the CNC operation should be provided by only 7 programs, or you can write several programs in one thread and connect the necessary ones depending on the situation.
    You can download and execute any number of different C Programs. The 7 Thread limitation (+ 1 System Thread) limits you to having 7 User programs running at the same time.



    See also: KMotion/KFlop Multi-tasking

    Note that each running User Thread reduces the cpu time available for the KFLOP System Thread so it is best to have a minimum number of Threads active. If a number of things need to be continuously serviced it is usually possible to service them all in a single loop in a single Thread. See also:
    KFLOP C Programs - Dynomotion

    what is the purpose of the Var parameter in the Tool Setup Screen / User button?
    Some Actions need to pass one or more parameters. The Var Setting determines which KFLOP persist.UserData Variables the parameters will be consecutively placed into before Executing the C Program. For Example M6 Tool Change Action passes the Tool Slot and Tool ID values into persist.UserData[Var] and persist.UserData[Var+1].

    MCodes can pass PQR parameters. See:
    MCodes with Parameters

    If no parameter is associated with the particular Action then the Action Index is placed into the Variable specified by Var. This can sometimes be useful to have a Single C Program handle multiple Actions where the C Program can use the Action Index to determine which Action was invoked.

    HTH
    Regards

    Regards
    TK http://dynomotion.com


  9. #9
    Registered
    Join Date
    Dec 2015
    Posts
    9
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    [QUOTEAlthough C Programs can be Flashed to KFLOP memory so they will be present in KFLOP Memory on Power up this is not normally recommended and not usually required. KFLOP normally powers up with no C Programs in Memory. Programs can be compiled, downloaded, and executed dynamically in Threads by Applications at run time. They do not need to be pre-loaded (or Flashed) into KFLOP Memory.][/QUOTE]
    I correctly understood that it is not necessary to load each C-program into flash user memory, just specify the thread and click "Save, Compile, Download, Run" button?



  10. #10
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Hi Lotreck,

    I correctly understood that it is not necessary to load each C-program into flash user memory, just specify the thread and click "Save, Compile, Download, Run" button?
    Well I'm not sure exactly what you mean. To run a Program it does not need to be Flashed into KFLOP's Flash memory. It can just be loaded and executed by the PC.

    Normally that Button and KMotion.exe is not used at all in your final application. KMotion.exe is only used while developing and testing. Instead a Button or MCode or other Action in KMotionCNC will automatically load and execute the necessary C Program when it is needed.

    HTH
    Regards

    Regards
    TK http://dynomotion.com


  11. #11
    Registered
    Join Date
    Dec 2015
    Posts
    9
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Is it necessary to load the axis configuration program into flash memory?

    After installing the program Kmotion, to each thread is already connected some program, how to remove these not necessary programs, so that they do not strain the controller? Is it enough to just delete them from the file C: \ KMotion433\KMothionData\Threads or do we need some more manipulations?



  12. #12
    Member TomKerekes's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    4043
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Hi Lotreck,

    Is it necessary to load the axis configuration program into flash memory?
    It seems I wasn't clear in my last post. No. Programs do not need to be Flashed. Assign it to a User Button in KMotionCNC so it will be downloaded and executed when the button is pushed.

    After installing the program Kmotion, to each thread is already connected some program, how to remove these not necessary programs, so that they do not strain the controller?
    Firstly the programs in the KMotion.exe Program Edit Windows are not necessarily in KFLOP. The edit windows on the PC and the memory in KFLOP are two different things.

    Secondly there is no need to remove programs from KFLOP. If they are not executing then the do not do anything or use any cpu resources. Whenever a new program is downloaded it will overwrite any previous program.

    HTH
    Regards

    Regards
    TK http://dynomotion.com


  13. #13
    Registered
    Join Date
    Dec 2015
    Posts
    9
    Downloads
    0
    Uploads
    0

    Default Re: Kflop thread/C program question

    Thank you very much for your answers.



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

Kflop thread/C program question

Kflop thread/C program question