#linuxcnc-devel Logs
Dec 31 2022
#linuxcnc-devel Calendar
04:12 AM pere: hi
06:07 PM Guest7: in a hal component, what is the proper way to puase or wait ? most of the stand c library seems to have issues particularly sleep.
06:11 PM pcw---home: It a RT hal component you would typically count invocations (you cannot sleep or you will hang the thread)
06:11 PM pcw---home: In a
06:13 PM Guest7: I was considering this method, but not know the guts of the rtapi I don't know if it's barking up the wrong tree. I just want to loosely time with relatively low precision for a pause then continue #include <time.h>
06:13 PM Guest7: clock_t start, end;
06:13 PM Guest7: double cpu_time_used;
06:13 PM Guest7: start = clock();
06:13 PM Guest7: ... /* Do the work. */
06:13 PM Guest7: end = clock();
06:13 PM Guest7: cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
06:14 PM Guest7: if counting cycles is the only option, is there any good example code on how to do that and calculate seconds ?
06:38 PM cradek: you didn't explain what your goal is, so I'm guessing a bit, but: if you're designing something, it's way better to wait for an event (a sensor, for instance) than waiting a certain amount of time. it can be done easily in realtime (or nonrealtime) code, and it will be much more robust/reliable/foolproof. are you sure your design is the best you can make it?
06:43 PM Guest7: it's a mechanical limitation, the issue is that it takes X time for the mechanics to settle, before the next command, average time is 1.2 seconds, but setting for 2 seconds is a nice enough buffer it doesn't miss
06:54 PM Tom_L: Guest7, a G4 won't do it for ya?
06:55 PM Tom_L: it waits x seconds
06:59 PM Guest7: I am putting all of the code into the component, one place to look for problems. still new to C, so, meh.