Go to Post I have always been of the opinion that if the mechanicals are making noise they are trying to talk to you. - Al Skierkiewicz [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 12-02-2008, 00:11
Chaos in a Can Chaos in a Can is offline
Joel Spadin
FRC #1736 (Robot Casserole)
Team Role: Programmer
 
Join Date: Mar 2007
Rookie Year: 2007
Location: Peoria, IL
Posts: 58
Chaos in a Can is an unknown quantity at this point
Send a message via MSN to Chaos in a Can
Re: problem with printing float

printf does not support %f.
Something like printf("%ld", (long)(ratio * 1000) ); might work, though you're likely to run into a lot of problems with floats.

You can avoid floats entirely by shifting the number up to store your decimal places, but in an integer type. Then in calculations, shift it back down.

For example:
Code:
long ratio;
ratio = (((long)p1_x)<<8 ) / S_PWM_SWING;

if(ratio>128 && magnitude_sum>MAX_SINGLE_MOT_MAG){
		RIGHT_WHEEL_PWM=NEUTRAL+MAX_SINGLE_MOT_MAG;
		LEFT_WHEEL_PWM=NEUTRAL-(((1<<8 - ratio) * MAX_SINGLE_MOT_MAG)>>8);
    }
Keep in mind that bit shifts only work on integers, so 0.5<<8 actually becomes 0<<8, so instead of 128, you get 0. You'll have to enter any decimal constants yourself.

(In case you don't already know, x<<8 = x*(2^8) and x>>8 = x/(2^8).)
__________________
2006 Xerox Creativity Award
2007 General Motors Industrial Design Award
2008 Judges' Award
2009 Chrysler Team Spirit Award

 


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
printing FLOAT data type on the terminal window razer Programming 14 05-02-2007 08:55
Robots that float boy_scout72688 Rules/Strategy 31 15-01-2007 22:18
Float Design i like dirt Technical Discussion 3 13-09-2006 00:21
Float in MPLAB capenga Programming 1 18-02-2005 06:44
Problem with communicating with STAMP through serial port Skabana159 Technical Discussion 2 06-02-2003 21:10


All times are GMT -5. The time now is 19:12.

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