![]() |
Overflow?
My robot's pos_x and pos_y variables seem to overflow over time but not because of incrementing...
If I don't move the robot the pos_x and pos_y stay 0 for a while then suddenly become 32767 (max int value?) pos_x += sin(heading_radians) * dist; pos_y += cos(heading_radians) * dist; I'm using the float trig functions in math.h that comes with the new compiler. Is this happening because the float functions take too much time? Would Int Trig solve this? thanks for your help! |
Re: Overflow?
I'm not familiar with the float trig functions, so I'm no help there.
Should pos_x and pos_y be static variables? Are you expecting their values to be remembered from call-to-call? Can you post some more code? The two lines you posted don't tell us much. Here's a definitive way to determine how much time your code is taking, but you will need an oscilloscope and will need to know how to use it. Just before the call to Process_Data_From_Master_uP(), set one of the digital output pins to '1'. At the end of every main loop, reset the pin to '0' (see code below). Run your code and look at the pin with a scope. You should see a positive-going pulse every 26 ms. The duration (width) of the pulse is the duration of your code's execution. You may see the width change as you operate the robot. However, the frequency of the pulse should be a constant 38 Hz. Be sure to trigger the scope on the rising edge of the pulse. Don't forget to configure your chosen output pin as an output. Here's code I used last year, Note the two lines with // ***:: Code:
while (1) /* This loop will repeat indefinitely. */ |
Re: Overflow?
Quote:
32767 is also a (signed int) -1 printed as an (unsigned int). |
| All times are GMT -5. The time now is 00:00. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi