Go to Post They could release an update saying they were going to give every team free puppies and kittens, and many teams would vehemently complain this change was too late to budget dry kibbles into their budget. - artdutra04 [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 03-03-2005, 19:35
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,185
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
Casting Floats, printf's, and variable maxing

Ive been having a problem, and I wanted to wait until I was absolutely sure I didnt know how to fix it before posting it here. Well, guess what... I've hit that benchmark. We are implementing a simple navigation system on our robot this year, which is used to keep track of position and give drive commands to drive to waypoints.

This system grabs current angle from an on board gyro, and distance traveled in the sample period from shaft encoders. I have been testing this on an EDU controller, and everything worked flawlessly. But when I moved my code over to the FRC controller, I started getting some fishy outcomes.

I have a function that is called every program loop to keep track of position, then a printf in user routines.c that shows current x, y, and heading variables for debugging purposes.

Heres the navigation function:
Code:
int nav_heading;
int new_pos;
int old_pos;
int dist=0;
int nav_x;
int nav_y;

void Navigation(void)
{
	
	nav_heading = Get_Gyro_Angle();
	
	new_pos = (int)( Get_Left_Encoder_Count() + Get_Right_Encoder_Count() )/2;  
	
	dist = (new_pos - old_pos);

	nav_x+= (int) cos((float) nav_heading /1000) * dist;

	nav_y+= (int) sin((float)nav_heading/1000) * dist;

	
	old_pos = new_pos;
}

int Nav_Get_x(void)
{
	return nav_x;
}

int Nav_Get_y(void)
{
	return nav_y;
}
Heres the print:
Code:
printf("X = %d | Y = %d\r", Nav_Get_x(), Nav_Get_y());
Now, the problem I am getting is as soon as the gyro turns at all, both X and Y values go to the maximum value allowed in an integer (363363 or something ). The cos and sin functions take and output floats. I've tried casting both the arguments and the returns as floats, but that didnt help. Another interesting point is when I put the printf in the actual navigation function, I dont seem to have this problem.

Do you have any idea what is wrong?
  #2   Spotlight this post!  
Unread 03-03-2005, 22:35
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: Casting Floats, printf's, and variable maxing

You might try splitting things up, temporarily to get to the bottom of it...

Code:
int nav_heading;
int new_pos;
int old_pos;
int dist=0;
int nav_x;
int nav_y;

void Navigation(void)
{
	
float temp ;

	nav_heading = Get_Gyro_Angle();
	
	new_pos = (int)( Get_Left_Encoder_Count() + Get_Right_Encoder_Count() )/2;  
	

	dist = (new_pos - old_pos);

        /*nav_x+= (int) cos((float) nav_heading /1000) * dist;*/
        /* ...add printfs to keep checking the value of temp*/ 
         temp = (float) nav_heading ;
         temp /= 1000. ;
         temp = cos(temp) ; 
         temp *= (float)dist ;
	 nav_x = (int)temp ;

	nav_y+= (int) sin((float)nav_heading/1000) * dist;

	
	old_pos = new_pos;
}
That always helps me figure out casting peculiarities...

Eric
__________________

Don't PANIC!
S. P. A. M.
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


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

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