Go to Post Isn't that, April showers bring Woodie Flowers? ;) - jgannon [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-02-2007, 12:33
razer razer is offline
Registered User
FRC #1690
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Israel
Posts: 24
razer is an unknown quantity at this point
printing FLOAT data type on the terminal window

I have a question -
can i print float variable on the terminal window?
for example:

------------------------------------
float a=2.555;
a*=4.5;
printf("a = %f", a);
------------------------------------

does the RC prints float vriables on the IFILoader's Terminal Window?
  #2   Spotlight this post!  
Unread 02-02-2007, 12:40
eugenebrooks eugenebrooks is offline
Team Role: Engineer
AKA: Dr. Brooks
no team (WRRF)
 
Join Date: Jan 2004
Rookie Year: 2001
Location: Livermore, CA
Posts: 601
eugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond repute
Re: printing FLOAT data type on the terminal window

Quote:
Originally Posted by razer View Post
I have a question -
can i print float variable on the terminal window?
for example:

------------------------------------
float a=2.555;
a*=4.5;
printf("a = %f", a);
------------------------------------

does the RC prints float vriables on the IFILoader's Terminal Window?
Last I checked, the printf in PIC support we use did not support floats. Floats, and doubles, are in general a bad idea on this processor. I reccomend fixed point, or aritimetic using rational numbers. See http://srvhsrobotics.org/eugenebrooks/IntroCProg.pdf There is a routine described in this document, and available for download, that prints fixed point numbers.

Eugene
  #3   Spotlight this post!  
Unread 02-02-2007, 12:52
Salik Syed Salik Syed is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Stanford CA.
Posts: 514
Salik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud of
Send a message via AIM to Salik Syed
Re: printing FLOAT data type on the terminal window

I don't think it's that bad to use a couple floats, but overuse can lead to slow downs in processing time.
the use of floating point numbers is not native to the PIC, Instead MPLAB uses a software routine to do the math (this is done at compile time), internally everything is probably represented differently. So everytime you do a float there extra steps the processor has to take.

If you want to printf it you could just multiply by 100 or 1000 or however much accuracy you want and then cast it to an int.
__________________
Team 701
  #4   Spotlight this post!  
Unread 02-02-2007, 13:59
tdlrali tdlrali is offline
Registered User
FRC #0469 (Las Guerrillas)
Team Role: Programmer
 
Join Date: Sep 2006
Rookie Year: 2006
Location: MI
Posts: 377
tdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud of
Re: printing FLOAT data type on the terminal window

The RC (actually, the microcontroller) does not have hardware support for floats. It supports floats software-side, but it is very slow.
  #5   Spotlight this post!  
Unread 02-02-2007, 14:15
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: printing FLOAT data type on the terminal window

http://www.chiefdelphi.com/forums/sh...89&postcount=6
  #6   Spotlight this post!  
Unread 02-02-2007, 16:33
CrashOverride's Avatar
CrashOverride CrashOverride is offline
Registered User
FRC #1831
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Gilford, NH
Posts: 16
CrashOverride is an unknown quantity at this point
Re: printing FLOAT data type on the terminal window

I looked at the source for the libraries last year and float data type is not included in the vfprinf routine, the code behind printf. Your best bet is to multiply your float by 100 or 1000 depending on how many deicmals you want put the result in a long and printf the result. Aviod floats whenever possible!
  #7   Spotlight this post!  
Unread 02-02-2007, 19:10
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,077
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: printing FLOAT data type on the terminal window

If enough people want to be able to print floats, I'll write code to do it (by decomposing the float into sign, exponent, mantissa). It'll take a couple hours.

Let me know...I'm always looking for something to do.
  #8   Spotlight this post!  
Unread 03-02-2007, 04:09
razer razer is offline
Registered User
FRC #1690
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Israel
Posts: 24
razer is an unknown quantity at this point
Re: printing FLOAT data type on the terminal window

i asked that because we have a function to calculate the range between the robot and the Rack, and it depends the TILT angle of the camera.
the TILT ANGLE is being used as an integer, so if the angle is 8, then the distance is 9 meters. if the angle is 7, than the distance is 6 meters. i want something in the middle like 6.5 angle and so on, to be more accurate.
but thanks ill use something i saw here, you can see this thread as closed.. thanks
  #9   Spotlight this post!  
Unread 03-02-2007, 04:12
razer razer is offline
Registered User
FRC #1690
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Israel
Posts: 24
razer is an unknown quantity at this point
Re: printing FLOAT data type on the terminal window

Quote:
Originally Posted by Abwehr View Post
If enough people want to be able to print floats, I'll write code to do it (by decomposing the float into sign, exponent, mantissa). It'll take a couple hours.

Let me know...I'm always looking for something to do.
if you have a smart way to prints floats, so it will be very usefull here i think. but i saw a reply in this thread which says to print it like " %d.%d ", but if you have another way.... it will be usefull, thanks.
  #10   Spotlight this post!  
Unread 03-02-2007, 09:25
pheadxdll pheadxdll is offline
Registered User
AKA: Alex
FRC #1225 (Amperage Robotics)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2006
Location: North Carolina
Posts: 168
pheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud of
Re: printing FLOAT data type on the terminal window

The prinf function isn't capable of printing floats. Instead convert your float to an integer and multiple it by 100.0. Use %d and print it. That should work.

float tan = -12.423421;
printf("Tan is = %d\r\n",(int)(tan * 100.0));
__________________
Amperage Robotics Team 1225
Site under-going revamp. :/
  #11   Spotlight this post!  
Unread 03-02-2007, 18:17
The yellowdart's Avatar
The yellowdart The yellowdart is offline
Registered User
FRC #1506 (Metal Muscle)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Oakland County
Posts: 22
The yellowdart has a little shameless behaviour in the past
Re: printing FLOAT data type on the terminal window

Floats are bad to use. They are bad because sometimes you get ridiculous numbers, for instance

23.98071849629364097134098729873403214

or larger. It runs slowly because it takes up extra memory, and there is a limited amount of memory in the controller.

Good luck
  #12   Spotlight this post!  
Unread 04-02-2007, 11:27
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: printing FLOAT data type on the terminal window

Floats aren't necessarily bad if used in moderation. They don't take any more data memory than a long does as both float and double are 32 bits long. Floating point operations are emulated in software since there is no on-board FPU hardware. The math library linked in uses a modest amount of additional program memory - but there is a lot of program memory available. It doesn't cost any more program memory to do 1 or 1000 float operations once the library is linked in.

What a programmer needs to be aware of is that the software emulation of the floating point operations can take a lot of time. How much time? I wrote a program to test how many floats/second the library could support and it wasn't much... maybe a few 1000s/second and you'd be saturating the PIC. I'll have to go back and re-run the benchmark to remember exactly.

The float/double data type is 8 bits of signed exponent and 24 bits of data - so a 32 bit integer value actually has 8 bits more precision than a float.

As with anything, understanding its weaknesses as well as its strengths will allow you to make a well informed decision based upon tradeoffs. Personally, I try to avoid both longs and floats but sometimes it just makes more sense to use them vs anything else.
  #13   Spotlight this post!  
Unread 04-02-2007, 19:30
gnirts gnirts is offline
Suspicious pointer conversion
AKA: Robinson Levin
FRC #1648 (The Gearbox Gangstaz)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: ATL
Posts: 116
gnirts will become famous soon enough
Re: printing FLOAT data type on the terminal window

Quote:
Originally Posted by dcbrown View Post
The float/double data type is 8 bits of signed exponent and 24 bits of data - so a 32 bit integer value actually has 8 bits more precision than a float.
What do you mean by 'more precision' in this case?

Thanks,
Robinson
  #14   Spotlight this post!  
Unread 05-02-2007, 02:12
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: printing FLOAT data type on the terminal window

For the same exponent, which is what you'll get when you align float exponents for math operations, you only have 24 bits to represent your number. Longs are 32 bits. Using fixed point arithematic with longs is more precise than using floats as longs have 8 more bits of data than floats.
  #15   Spotlight this post!  
Unread 05-02-2007, 08:55
Metalgod4eva Metalgod4eva is offline
Registered User
None #0870
 
Join Date: Jan 2007
Location: Southold
Posts: 7
Metalgod4eva is an unknown quantity at this point
Re: printing FLOAT data type on the terminal window

Just a quick interjection if you use Floats or Doubles dont forget to format your output with %.Xf. The X is what place you want to format after the decimal. like %.2f outputs to the thousands place || x.00. If the decimal is not a double watch out for grabage data allways do some form of formating on the %F output because on a system there is a max and min a float can be, after that the system literaly gives you garbage and if your working on something that has to be exact then dont forget, in also to that comment if you want things exact then use intergers computers like base 2 and 1 && 0 so if you want to drive the robot 2.3 try to rework your measures 1 place value and move the values down a place value. have a great day!
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Com Terminal 1 Window Problem. groovy69 Programming 4 25-01-2007 22:58
Terminal Window teh_pwnerer795 Programming 1 02-01-2007 00:21
Terminal Window Idaman323 Programming 0 20-02-2006 19:28
Placement of the SLU-35 Terminal Lugs gumbyman-829 General Forum 8 03-02-2006 00:57
Is Terminal Window Evil? Fat Alex Programming 1 20-07-2004 10:57


All times are GMT -5. The time now is 09:36.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi