Go to Post Take it from a team that mastered tank treads and still hasn't built them in over a decade - it's not worth it. - Isaac501 [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 19-01-2008, 13:48
Nathans Nathans is offline
Registered User
AKA: Nathan
FRC #0004 (Element)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Los Angeles
Posts: 17
Nathans is an unknown quantity at this point
Send a message via AIM to Nathans
My error derivative is going crazy

I'm trying to get PID control for the gyro working, and so far P is working fine. The D, however, is going to unreasonable values because my angle_err_last variable doesn't work at all. Here's my teleop.c function, sans gyro bias calc and printfs. I'm using the new code with C18 3.10.

Code:
void Teleop(void)
{
	#define KP 20/100;
	#define KD 0/10

	static unsigned int i = 0;
	static unsigned int j = 0;
	int temp_gyro_rate;
	long temp_gyro_angle;
	int temp_gyro_bias;
	long angle_err;
	long angle_err_last;
	long angle_err_d;
	long heading = 1800;
	long turn;

	i++;
	j++; // this will rollover every ~1000 seconds

             ...

		temp_gyro_bias = Get_Gyro_Bias();
		temp_gyro_rate = Get_Gyro_Rate();
		temp_gyro_angle = Get_Gyro_Angle();

	if(j >= 120)
	{
		temp_gyro_angle = gyro_cycle(temp_gyro_angle);
		angle_err = (heading - abs(temp_gyro_angle));

		angle_err_d = (angle_err - angle_err_last);

		

		turn = angle_err * KP + angle_err_d * KD;

		motor_left = limit(127 + turn);
		motor_right = limit(127 + turn);

	}


             ...


	angle_err_last = angle_err;

	Update_OI_LEDs();	// located in ifi_code.c
}
The P correction doesn't know left from right at the moment, but I'm not worried about that at the moment.

I set all of the variables as long to avoid type mismatches. The angle_err_last variable jumps all over the place, never coinciding with what angle_err actually was. Anyone know why?

edit: I commented out everything touching angle_err_last except for the declaration, and it still went all over the place.

Last edited by Nathans : 19-01-2008 at 13:54.
  #2   Spotlight this post!  
Unread 19-01-2008, 14:18
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,534
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: My error derivative is going crazy

angle_err_last should be static.
  #3   Spotlight this post!  
Unread 19-01-2008, 14:41
Nathans Nathans is offline
Registered User
AKA: Nathan
FRC #0004 (Element)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Los Angeles
Posts: 17
Nathans is an unknown quantity at this point
Send a message via AIM to Nathans
Re: My error derivative is going crazy

It worked. Thank you.
  #4   Spotlight this post!  
Unread 19-01-2008, 17:56
intellec7's Avatar
intellec7 intellec7 is offline
108 programmer
AKA: Gustavo
FRC #0108 (SigmaC@ts)
Team Role: Programmer
 
Join Date: Sep 2005
Rookie Year: 2006
Location: Hollywood, Florida
Posts: 65
intellec7 is on a distinguished road
Send a message via AIM to intellec7 Send a message via MSN to intellec7
Re: My error derivative is going crazy

I am not sure if this applies to your case, but if you're integrating the gyro output to get angular position, and then differentiating it to get the change in angular position, wouldn't it be more efficient to just scale the rate output of the gyro? I think that you are differentiating the error though, I am not sure if this has any advantage. From my understanding, the D term of a PID loop is to slow down as you approach the goal, to reduce overshooting/oscillations.
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
Error in code light on, trouble finding error Bryan Herbst Programming 16 12-10-2007 21:59
180:Error: syntax error help! seanl Programming 8 04-02-2007 11:31
stupid Array error: Error [1300] stack frame too l Validius Programming 7 27-01-2006 10:53


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

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