LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-11-2009, 05:00 AM   #1
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Rep: Reputation: 15
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?

Plz help its urgent ..
 
Old 01-11-2009, 06:23 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 178Reputation: 178
Quote:
Plz help its urgent ..
Here ya go. If it's really that urgent, this is the quickest way.
 
Old 01-11-2009, 07:05 AM   #3
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Original Poster
Rep: Reputation: 15
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).

Thx..
 
Old 01-11-2009, 07:14 AM   #4
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
comment removed

Last edited by ErV; 01-11-2009 at 07:15 AM.
 
Old 01-11-2009, 09:48 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
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.

jlinkels
 
Old 01-11-2009, 10:27 AM   #6
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Original Poster
Rep: Reputation: 15
Hey..
Thank you so much for the same..

I was thinking of using Taylor series...
But the problem is the frequency of work that i need..(around 5 KHz) from RTLinux.

Is there a way in which I could find out how much time this computation would take?

If this is not possible then its better choice to go ahead with the table format.

thx a lot once again
 
Old 01-11-2009, 11:16 AM   #7
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
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.


jlinkels

Last edited by jlinkels; 01-11-2009 at 12:07 PM.
 
Old 01-11-2009, 01:53 PM   #8
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
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.

jlinkels

Last edited by jlinkels; 01-11-2009 at 02:10 PM.
 
Old 01-14-2009, 07:13 PM   #9
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Original Poster
Rep: Reputation: 15
Hie All

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.

IF ANYONE DOES KNOW ABOUT IT...PLEASE DO THE SAME

THX A LOT

~navderm

Last edited by navderm; 01-14-2009 at 08:01 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux boot cd with cciss support and USB 2.0 support zerobane Linux - Software 0 03-21-2006 10:03 PM
How to make mencoder support mp3 AVD_ZM Linux - Software 5 02-22-2005 01:52 PM
USB Support, UHCI (Intel PIIX4, VIA, ...) Support qingjuan Linux - General 0 03-30-2002 11:46 AM
Help desk / technical support / Customer support Software BaerRS Linux - General 1 12-20-2001 07:16 PM
Recompiling RH 7.1 to disable DMA support - chipset doesn't support properly arby73 Linux - Newbie 0 06-13-2001 10:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration