Timed exit while loop. Best way?

More
04 Jun 2013 07:06 #35242 by BigJohnT

BigJohn, Not sure where on your site the harding.clp file is? I downloaded the EMC2 CHNC Config Files and that file is not in there. Maybe I am looking in the wrong place?


Here is the link

gnipsel.com/linuxcnc/examples/cl-turret.zip

JT

Please Log in or Create an account to join the conversation.

More
04 Jun 2013 07:07 #35243 by BigJohnT

Please Log in or Create an account to join the conversation.

More
04 Jun 2013 07:10 #35244 by BigJohnT
You connect your inputs to the weighted sum component and feed the number to classicladder.

JT

Please Log in or Create an account to join the conversation.

More
04 Jun 2013 07:21 #35245 by DaOne
John, I was referring to the hardinge.clp file as it is not in your "EMC2 CHNC Config Files" that you down load from your website.


This weighted sum component sounds a bit over my head. LinuxCNC has been a steep learning curve for me coming from Windows and Mach 3. My last lathe was a stepper driven machine. I am wondering if I wouldn't be better off with my original way? Maybe you could help me understand weighted sum components with some sort of example?

Please Log in or Create an account to join the conversation.

More
04 Jun 2013 16:41 #35249 by ArcEye
Hi

I you want to use C (that is what I am most comfortable with too) look at the Orac Toolchanger I wrote.

wiki.linuxcnc.org/cgi-bin/wiki.pl?Contri...oolchanger_component

That uses a greyscale encoder truth table and has delays built in to allow mechanical movements, both by linkage to the timedelay component and an internal timer.

The big thing about realtime components is how quickly they are polled, so the program needs to do a bit and then return.
while() loops are a very bad idea full stop and I never use them.

The alternative is to use a state change, switch loop, where a progress level is set and each time the component is polled it goes to that level, does or checks something and returns.
When the required value is reached or whatever, the progress level is changed to move to the next task.

Regards an internal timer can be as simple as
case 1: // programmed delay to allow relays time to change over
                 if(sleeptime < times)  
                    {
                    sleeptime++;
                    break;
                    }
                run = true;
                progress_level = 2;
                break;

The component just increments a timer and returns until the required value is reached and then moves to the next level, to do the next part of the toolchange.

Might give you some ideas

regards

Please Log in or Create an account to join the conversation.

More
04 Jun 2013 19:14 #35253 by BigJohnT

John, I was referring to the hardinge.clp file as it is not in your "EMC2 CHNC Config Files" that you down load from your website.


This weighted sum component sounds a bit over my head. LinuxCNC has been a steep learning curve for me coming from Windows and Mach 3. My last lathe was a stepper driven machine. I am wondering if I wouldn't be better off with my original way? Maybe you could help me understand weighted sum components with some sort of example?


I've updated the zip file for my hardinge config and can't figure out how the clp file was not included.

I created a weighted sum example for you and it is here . It's probably the terms that scare you but it is a rather simple component. And that being said HAL is very simple like building something with small components one part at a time. Run the example configuration and look at the HAL in the postgui.hal file to see how simple it is to connect once you know how. The man page link is very terse...

JT

Please Log in or Create an account to join the conversation.

More
04 Jun 2013 22:06 #35257 by andypugh

I would like to have a timed exit in a while loop for my hal tool changer component. I am waiting for an input in a loop and if I don't get it in a few seconds I want it to alarm out with a message. I am wondering the best way to achieve this. Probably a stupid question but I am still a newbie to LinuxCNC.


Just to clarify: Is this a realtime component or a userspace one?

In a userspace component you can look at www.linuxcnc.org/docs/html/man/man3/rtapi_get_time.3rtapi.html
Initialise a variable from this function on entry, then keep checking the difference between the variable and the function return value and exit the loop when it exceeds the limit.

In a realtime component you can't have a wait loop, you will stop the whole machine. Instead you keep a counter and add "fperiod" to it every time through.
git.linuxcnc.org/gitweb?p=linuxcnc.git;a...s/heads/master#l1085
(Line 1085 onwards) is an example of a wait-loop in a realtime module. It uses a state-machine so that it can always run to completion, and some of the states run a timer so that they can exit if they don't see the right result in time. For example case 0x11 starting in line 1234.

Please Log in or Create an account to join the conversation.

More
04 Jun 2013 23:07 #35262 by DaOne

Hi

I you want to use C (that is what I am most comfortable with too) look at the Orac Toolchanger I wrote.

wiki.linuxcnc.org/cgi-bin/wiki.pl?Contri...oolchanger_component

That uses a greyscale encoder truth table and has delays built in to allow mechanical movements, both by linkage to the timedelay component and an internal timer.

The big thing about realtime components is how quickly they are polled, so the program needs to do a bit and then return.
while() loops are a very bad idea full stop and I never use them.

The alternative is to use a state change, switch loop, where a progress level is set and each time the component is polled it goes to that level, does or checks something and returns.
When the required value is reached or whatever, the progress level is changed to move to the next task.

Regards an internal timer can be as simple as
case 1: // programmed delay to allow relays time to change over
                 if(sleeptime < times)  
                    {
                    sleeptime++;
                    break;
                    }
                run = true;
                progress_level = 2;
                break;

The component just increments a timer and returns until the required value is reached and then moves to the next level, to do the next part of the toolchange.

Might give you some ideas

regards


ArcEye, I am building my code based on the Orac Toolchanger you wrote. I am just changing some things to make it work with my setup. The biggest issue I had with the Orac Toolchanger code is from my amateur eyes, contains loops that will go on to infinity if it never gets the right signal. The other issue I have with the timer in the Orac file is installing this: sudo comp --install timedelay2.comp The file is nowhere to be found so it says.

Please Log in or Create an account to join the conversation.

More
04 Jun 2013 23:09 #35263 by DaOne

John, I was referring to the hardinge.clp file as it is not in your "EMC2 CHNC Config Files" that you down load from your website.


This weighted sum component sounds a bit over my head. LinuxCNC has been a steep learning curve for me coming from Windows and Mach 3. My last lathe was a stepper driven machine. I am wondering if I wouldn't be better off with my original way? Maybe you could help me understand weighted sum components with some sort of example?


I've updated the zip file for my hardinge config and can't figure out how the clp file was not included.

I created a weighted sum example for you and it is here . It's probably the terms that scare you but it is a rather simple component. And that being said HAL is very simple like building something with small components one part at a time. Run the example configuration and look at the HAL in the postgui.hal file to see how simple it is to connect once you know how. The man page link is very terse...

JT


Thanks John, I will give that a look. I appreciate all your help.

Please Log in or Create an account to join the conversation.

More
04 Jun 2013 23:16 #35264 by DaOne

I would like to have a timed exit in a while loop for my hal tool changer component. I am waiting for an input in a loop and if I don't get it in a few seconds I want it to alarm out with a message. I am wondering the best way to achieve this. Probably a stupid question but I am still a newbie to LinuxCNC.


Just to clarify: Is this a realtime component or a userspace one?

In a userspace component you can look at www.linuxcnc.org/docs/html/man/man3/rtapi_get_time.3rtapi.html
Initialise a variable from this function on entry, then keep checking the difference between the variable and the function return value and exit the loop when it exceeds the limit.

In a realtime component you can't have a wait loop, you will stop the whole machine. Instead you keep a counter and add "fperiod" to it every time through.
git.linuxcnc.org/gitweb?p=linuxcnc.git;a...s/heads/master#l1085
(Line 1085 onwards) is an example of a wait-loop in a realtime module. It uses a state-machine so that it can always run to completion, and some of the states run a timer so that they can exit if they don't see the right result in time. For example case 0x11 starting in line 1234.


Andy, its basically the Orac Toolchanger ArcEye wrote just modified to work with my machine. I think this would be considered real time but I am not sure? As far as stopping the whole machine that was kinda the point. What I am trying to do is make it wait for a turret clamped signal. This would be a loop until it gets the signal. The problem with that is what if it never gets the turret clamped signal? I want it to error out and alert the user the turret has an issue and stop the machine not bring the system to a halt (infinity loop). Thank you guys for the help. Not sure I could do this with out it.

Please Log in or Create an account to join the conversation.

Time to create page: 0.403 seconds
Powered by Kunena Forum