Logarithm

More
09 Nov 2018 16:45 #120335 by rodw
Replied by rodw on topic Logarithm
Well thats actually quite strange. thermistor.comp use the log() function. I wonder why and even if it compiles?
github.com/LinuxCNC/linuxcnc/blob/master...omps/thermistor.comp.

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

More
09 Nov 2018 16:50 #120336 by andypugh
Replied by andypugh on topic Logarithm
The thermistor comp runs in userspace.

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

More
09 Nov 2018 17:30 #120338 by rodw
Replied by rodw on topic Logarithm

The thermistor comp runs in userspace.


Yes, I saw that but still it has no declaration in the header files for log(). The other user space components are quite liberal with standard #include files. Makes me wonder if log() should not be added to rtapi_math.h
The following user(s) said Thank You: yeepah

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

More
09 Nov 2018 17:58 - 09 Nov 2018 18:02 #120340 by yeepah
Replied by yeepah on topic Logarithm
I found a code. I will try it before post it. ASAP hope tomorow

I don't know if ther is a link but I found some people who get trouble to compile log in C with linux. They had to compiled the program with the -lm option. And it worked
like : www.unix.com/programming/63585-what-wrong-log-function-c.html
By the way, no clue what does it meens.
Last edit: 09 Nov 2018 18:02 by yeepah.

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

More
09 Nov 2018 18:06 #120341 by andypugh
Replied by andypugh on topic Logarithm
For simplicity, reliability and portability I think that "lincurve" is the best answer.
It was designed for exactly this sort of job, with inputs inside a well defined range.
We use the same approach extensively in my day job as it limits the computational overhead. And automatically limits outputs to sane values regardless of inputs.
The following user(s) said Thank You: yeepah

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

More
11 Nov 2018 17:50 #120451 by yeepah
Replied by yeepah on topic Logarithm
I will work on lincurve, but i need some result. I use the easy way...
So : if somebody need a natural logarithm function in C, here it is


double log(double x){
int i=1;
double logx = 0 ;
double ty = (x-1)/(x+1) ;
double tty=0;
do
{
logx = logx + ty / i;
tty = ty ;
ty = (ty * ((x-1)/(x+1)) * ((x-1)/(x+1)));
i = i + 2 ;
}
while(tty - ty > 0.0000005 );
logx = 2*logx;
return logx;
}

log(2) will give 0.6314

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

More
11 Nov 2018 20:39 #120457 by rodw
Replied by rodw on topic Logarithm
Its great that you have a result but if you are doing this in real time rather than in user space, I would exercise caution looping in the servo thread as you are blocking every other component that is running on the thread. Maybe make a new debug pin that publishes the number of iterations and observe it for a while to see if it is excessive. You can also see the time taken to execute by the period and fperiod variables in the component so publish one of these to a debug pin. (even better publish the largest values seen)
See linuxcnc.org/docs/html/hal/comp.html#_implicit_parameters

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

More
13 Nov 2018 18:05 #120587 by yeepah
Replied by yeepah on topic Logarithm
Be careful!!!!

The previous code is not really good. It not work with number smaller than 1
This one is better.

double Ln(double x) {
int negatif = 0;
double fois = 1;
double ajout = 0;
if(x<=0.0) return 0;
if(x<1.0) {
negatif = 1;
x = 1.0/x;
}
while(x >= 10.0) {
x /= 10.0;
ajout += 2.302585092994046;
};

while(x>=1.1) {
x = SquareRoot(x);
fois *= 2;
};
x--;
double savx = x;
double i = 2;
double xp = x*x;
double quotient = (xp/i);
double dl = x-quotient;
while (1.0E-15<quotient) {
i++;
xp *= x;
dl += (xp/i);
i++;
xp *= x;
quotient = (xp/i);
dl -= quotient;
}

dl *= fois;
dl += ajout;
if(negatif) dl = -dl;
return dl;
}


For me I give up!! That working good but using a thermistor ntc 100K to calcul temperature between 200 and 300 °C don't give me enough accuracy. Not at all.

I will try to generate a sqare signal with a micocontroleur and a thermocouple K....

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

More
13 Nov 2018 18:56 #120592 by andypugh
Replied by andypugh on topic Logarithm
lincurve should do the job..

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

More
13 Nov 2018 19:10 #120595 by yeepah
Replied by yeepah on topic Logarithm
:)
I'm a bit stubborn don't you think....
I will dig on that deeper. I to hurry. I need to understand that better
thank to puch me on that way. Don't be lazy yeeaph!!!!

I need also to see if my code will be not a break for the real time, as suggest "rodw"

big work.:blink:
big fun

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

Time to create page: 0.081 seconds
Powered by Kunena Forum