hello
(sorry if double posted, i thinik orig dud not go thru)
I wrote a userspace .comp file to drive a pyvcp bar widget
I expected it to update every 1mS ( usleep(1000) )
But what I see is close to 1 hz š
I use a rip of linuxcmc 2.9.1Ā on debian 12
It compiles ok with the followiung cmd...
tomp@D12emc291:~/linuxcnc-barwidgets/configs/tomp$ halcompile --install
--userspace rand9.comp
gcc -I/home/tomp/linuxcnc-barwidgets/configs/tomp
-I/home/tomp/linuxcnc-barwidgets/include -I/usr/include/linuxcnc -URTAPI
-U__MODULE__ -DULAPI -OsĀ -o rand9 /tmp/tmp49hdcnk5/rand9.c
-Wl,-rpath,/home/tomp/linuxcnc-barwidgets/lib
-L/home/tomp/linuxcnc-barwidgets/lib -llinuxcnchal
halrun
loadusr rand9
loadusr halmeter
Ā Ā chooseĀ Ā rand9.0.out
note the near 1hz change rate
any idea why its so slow?
thx
TomP
component rand9;
// hd lost all superblocks, no parftial filles recovered for this comp
// had to rebuilt
// works but but updates at 1hz why??
//
// to build in rip
// halcompile --install --userspace rand9.comp
// will create file rand9 in ~/yourRipDir/bin
//
// to test after aboive
// cd; cd ripdir; . scripts/rip-environment
// halrun
// loadusr rand9
// loadusr halmeter
// select ranf9.0.out
// note the changes are ~ 1hz NOT the 1000uS of uSleep() call
//
option userspace;
// default min max , user can setp later as wanted
pin in float min=0;
pin in float max=100;
pin out float out;
license "GPL";
;;
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
// from
https://stackoverflow.com/questions/5289613/generate-random-float-between-two-floats
float RandomFloat(float a, float b) {
float random = ((float) rand()) / (float) RAND_MAX;
float diff = b - a;
float r = random * diff;
return a + r;
}
void user_mainloop(void) {
while(1) {
usleep(1000);// thats 1000uSecs = 1mS but i see chgs every 1.0 secs (
1000000uSecs) why?
srand(time(NULL));
FOR_ALL_INSTS() out = RandomFloat(min,max);
}
}
_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers