Go to Post The size, speed, and power of full sized FRC robots are much more sublime. People go to the zoo to see the lions and tigers, not the ants. - 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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-02-2005, 01:31
Zalumaskov's Avatar
Zalumaskov Zalumaskov is offline
Premier
no team
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Place
Posts: 12
Zalumaskov is on a distinguished road
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!
__________________
I would change the world but I don't have the source code.
  #2   Spotlight this post!  
Unread 16-02-2005, 12:29
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
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. */
  {

    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {                                 /* I'm slow!  I only execute every 26.2ms because */
                                      /* that's how fast the Master uP gives me data. */
      rc_dig_out01 = 1;  // *** look at this on a scope to see when loop starts
      Process_Data_From_Master_uP();  /* You edit this in user_routines.c */

      if (autonomous_mode)            /* DO NOT CHANGE! */
      {
        User_Autonomous_Code();        /* You edit this in user_routines_fast.c */
      }
    }
    Process_Data_From_Local_IO();     /* You edit this in user_routines_fast.c */
                                      /* I'm fast!  I execute during every loop.*/
    rc_dig_out01 = 0;  // *** look on scope to see how long it took!
  } /* while (1) */
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #3   Spotlight this post!  
Unread 16-02-2005, 13:55
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,854
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Overflow?

Quote:
Originally Posted by Zalumaskov
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?)
Your code probably thinks pos_x and pos_y are equal to -1.

32767 is also a (signed int) -1 printed as an (unsigned int).
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
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
ADXRS150 gyro yaw rate sensor Brian M. Electrical 13 17-10-2004 02:28
printf isn't printf-ing. Help! Meandmyself Programming 14 15-02-2004 16:27


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

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