RTLinux does not support sine functions...How do i make it support the same

ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.

Exclusive for LQ members, get up to 45% off per month. Click here for more info.

RTLinux does not support sine functions...How do i make it support the same

I have been working on RTLinux for some time.
I wanted to generate a sine curve... but the RTLinux does not take the sin command from math.h. how do I make sin curve from RT.

I mean is there some changes in the RTLinux Makefile that can help me access it?

Seems like a cool thing but it aint...
Coz i guess I have already done that and posted something here coz I did not find the solution I was looking for...

Well been said that, I have a code which works with AD/DA converter and has the capability to use the sine function in RT. so much for GOOGLING.

The make file that I use and the make file that this converters code uses is pretty different.

I tried using it but many variables clashed and system did not work finally.

So i thought someone must've worked on the RTLinux and used this system or may be used sine fn. (as is being used by the code).

Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE

Posts: 5,195

Rep:

math.h is not available in kernel space whwre RT is running in.

To get a sine function, you could implement it yourself using a Taylor series. If you use a polynomial of degree 7 (3 terms) your error is < 0.000003.

If that is too much processor time to calculate, create a table during startup and use that one. It goes without saying that you only have to create a table from 0 to pi/2 and other angles can be found using simple arithmetic, same for cosine and tangent.

Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE

Posts: 5,195

Rep:

I don't think it is very CPU intensive.

Sin(x) = x - x^3/3! + x^5/5! - x^7/7! for a 7th degree polynome. If you calculate smart, you only have to calculate x^2, x*x^2, this *x^2 and this *x^2, which are 4 floating point multiplications, 3 divisions by a constant (3!, 5! are constants) and 3 additions. That is really not much.

Since you'd have to write the function anyway, just write it, and if it takes to much time use the function to generate the lookup-table.

Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE

Posts: 5,195

Rep:

In case you are writing this for an embedded system without math processor, you could implement this fully in integer arithmetic.

If you do that, you have to use smart scaling in order to have all terms fit into 32-bits integers, but it can be done.

You could scale like this:
for x: x -> x * 2^30
x^3/3!: x -> x * 2^10 (you'll end up with a term which is scaled 2^30)
x^5/5!: x: -> x * 2^5 (term is scaled 2^25)
x^7/7!: x: -> x * 2^3 (term is scaled 2^21)

Adding up the terms can be done as:

(x(1) - x(3) + x(5) * 2^5 - x(7) * 2^7) / 2^30

This keeps the eventual error < 10e-2.

Acuuracy might be improved if you write x^5/5! as (x^2/10) * (x^3/12) in which case you might be able to scale x to a higher power of 2 before you get an overflow.

Here is how I got out of the problem.(it wasn't by GOOGLING alone)

I took an angle and converted it to the range between 0<=theta<=180
then i used four conditions to get the theta from 0 to 90 deg. (trigonometric relations)

i. theta
ii. 2PI - theta
iii. ...
iv. ...

then i used the taylor series.

if taylor series is used in the vicinity of 180deg htere is a lot of error.
till 90 deg there is not much error (0.001 types). so the result work fine for me.

In case any one gets the problem again.
I would recommend it as its very easy and implements well.

Thanx
===============

ALSO: I AM 100% CONFIDENT THERE IS A WAY YOU CAN USE SINE FUNCTIONS VIA MAKE FILE COMMANDS..
I HAVE NOT BEEN ABLE TO FIGURE IT OUT AS YET. BUT AS SOON AS I DO I'LL POST IT HERE SO THAT PEOPLE WHO WANT IT MAY GET IT.

LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.