Go to Post Mentors learn from, are inspired by, and emulate each other. A team with a great lead mentor leads to a productive, inspired, and ultimately successful group of mentors. - Jared Russell [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
  #1   Spotlight this post!  
Unread 07-08-2005, 02:35
neilsonster's Avatar
neilsonster neilsonster is offline
Registered User
AKA: Andrew Neilson
FRC #0772 (Sabre Bytes)
Team Role: College Student
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Waterloo, ON, Canada
Posts: 188
neilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to allneilsonster is a name known to all
Send a message via MSN to neilsonster
Strange products upon running code...

Hi, I have been attempting to write up lessons for next year's programmers to practice with. The last problem I made was to write a function that measures distance driven using encoders and display the data to the screen (I'm using a 2004 RC and MPLAB 7.00). In writing the code myself I ran into something strange.

Specifically the problem came up in calculating the wheel circumference. It was a very simple calculation and it spit out 0 for the circumference upon running the program. I then toyed around with just multiplying some random numbers and 15x30 came out to be -62 somehow. Here is the actual line of code that has caused me the trouble:

unsigned int WheelCirc = (2000 * WHEEL_RAD * PI) / 1000000;

In the above I was trying to stay away from using a float or double number obviously. I used 100 for WHEEL_RAD and 3142 for PI. The answer should be 628 but when I display the value to the terminal window it says 0. I then figured it must have somehow gotten a very small number (compared to 1 000 000) for (2000 * WHEEL_RAD * PI) to come up with 0, which doesn't make sense. Sure enough it ends up getting an answer of -24704 for the product of (2000 * WHEEL_RAD * PI), which would be the cause of the 0.

I then tried just writing out the numbers themselves and multiplying them for the WheelCirc variable and got the same thing. I tried it as a float rather than int and did 200*3.142 with no success (the answer came up as 17437). Has anyone else experienced this with the robot controller, MPLAB, or even in just any C program? Am I missing something (I'm hardly an expert at this)? If you haven't experienced this please give it a try and let me know if you get the same odd products. It's really cramping my style .
__________________
Andrew Neilson - Team 772 Alumnus
University of Waterloo Computer Science, Class of 2010
 


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
Out of the Box Camera Code russell Programming 9 21-10-2009 05:28
Team THRUST - Kevin's Code and Camera Code Combine Chris_Elston Programming 3 31-01-2005 22:28
Problem running compiled code jskene Programming 10 23-01-2005 21:13
heres the code. y this not working omega Programming 16 31-03-2004 15:18
Strange IR sensor movement with default tracker code wun Programming 5 19-03-2004 10:51


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

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