Go to Post Think, Write, Re-Think, Erase or Post - and Deal With it Either Way. - Chris Fultz [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 18-02-2008, 23:03
Guarana Guarana is offline
Registered User
FRC #1706
 
Join Date: Jan 2008
Location: Wentzville, Missouri
Posts: 16
Guarana is an unknown quantity at this point
gyro problem

I have the gyro on the analog input 01. i am using kevin's code with the gyro and adc enabled. i am getting a reading in the printf for both the rate and the angle. coding it is the trouble.

i am using mecanum programming i found from alan. it works very well on its own.

Code:
/*******************
function:	deadband()
inputs:	inp, input value
		center, value of input that represents neutral
		band, size of deadband to consider neutral
output:	scaled and deadband-compensated output value
		inputs below center will yield negative output
		inputs above center will yield positive output
		inputs within deadband either side of center will yield 0
usage:	typically call with joystick value (0-254) as input,
		joystick neutral (127) as center, and a small number (5)
		as the size of the deadband.  The white POS joysticks
		should probably have a much larger band (10) instead.
*******************/
int deadband(int inp, int center, int band)
{
int oup;
	if (inp < center-band)
		oup = inp - center + band;
	if (center-band <= inp && inp <= center+band)
		oup = 0;
	if (center+band < inp)
		oup = inp - center - band;
	return oup;
}

/*********************
function:	pwm_limit()
inputs:	inp, input value
output:	scaled and range-limited output value
usage:	call with signed value (+/- 127) as input,
		will return a valid pwm value
*********************/
unsigned char pwm_limit (signed int inp)
{
	if(inp<-127)
		inp = -127;
	if (inp>127)
		inp = 127;
	inp = inp+127;

	return (char)inp;
}



void Teleop(void)
{

	l_y = deadband(p1_y,127,10);
	r_y = deadband(p2_y,127,10);
	l_x = deadband(p1_x,127,10);
	r_x = deadband(p2_x,127,10);

	l_y = l_y/2;
	r_y = r_y/2;
	l_x = l_x/2;
	r_x = r_x/2;

	speed = l_y+r_y;
	turn = l_y-r_y;
	slide = -l_x-r_x; 

/*

	if(temp_gyro_angle <= -75) //gyro
	{
		turn = turn+15;
	}
	if(temp_gyro_angle >= 75)
	{
		turn = turn-15;
	}

*/
  	front_r = speed-turn+slide;
	front_l = speed+turn-slide;
	back_r = speed-turn-slide;
	back_l = speed+turn+slide;


	pwm01 = pwm_limit(front_r);
	pwm02 = 255 - pwm_limit(front_l);
	pwm03 = pwm_limit(back_r);
	pwm04 = 255 - pwm_limit(back_l);

}
The commented out part is mine. It is simple and looks like it should work, but whenever the gyro is plugged in, the victors 'flicker'. the orange lights flash very quick, and the wheels get a quick power burst to it, over and over. when the gyro is unplugged, its fine.

suggestions?
  #2   Spotlight this post!  
Unread 22-02-2008, 08:43
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: gyro problem

Print out the pwm values to see if they correspond to what you are seeing or not. If so, your code is causing the pwm values to do weird things; if the pwm values are steady but the motors are doing weird things, that might point to a wiring problem.

Put printf's inside your conditionals (if(temp_gyro_angle <= -75)...) to see what is going on.

You are increasing/decreasing 'turn' based on gyro. What type is turn? char? int? Is it static?

If turn is a static char and you are increasing it by 15 38 times per second, it will overflow more than 2 times each second (15*38/256).
__________________
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 22-02-2008, 13:42
Chipawa's Avatar
Chipawa Chipawa is offline
Registered User
AKA: Mr. Tucker, AKA Chip
FRC #1111 (Powerhawks)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Annapolis, MD
Posts: 41
Chipawa is an unknown quantity at this point
Re: gyro problem

This may be a shot in the dark .... but try plugging the gyro into analog input 02. This fixed a problem we experienced with the gyro.
__________________

2010 DC Engineering Innovation Award
2010 DC Spirit Award
2008 Chesapeake Finalist
2008 Chesapeake Rockwell Automation Innovation in Controls award
  #4   Spotlight this post!  
Unread 23-02-2008, 21:16
Guarana Guarana is offline
Registered User
FRC #1706
 
Join Date: Jan 2008
Location: Wentzville, Missouri
Posts: 16
Guarana is an unknown quantity at this point
Re: gyro problem

thanks for the help. i wont really be able to check it until thursday at competition, so i want to make sure this is right.

turn is declared as a signed int. will this have the same affect? how would i go about fixing that? this gyro is completly new to me.
  #5   Spotlight this post!  
Unread 23-02-2008, 23:38
Uberbots's Avatar
Uberbots Uberbots is offline
Mad Programmer
AKA: Billy Sisson
FRC #1124 (ÜberBots)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Avon
Posts: 739
Uberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond repute
Re: gyro problem

try using a feedback loop...a simple one would look like:

turn = turn - temp_gyro_angle / 15;

or something like that. this will get you (theoretically) a robot that always points forward. you may want to make the ratio that you multiply temp_gyro_angle by higher or lower depending on how fast/slow you want it to correct.


also, gnormhurst, he couldn't be overflowing because turn is set every step...
__________________
A few of my favorite numbers:
175 176 177 195 230 558 716 1024 1071 1592 1784 1816
RPI 2012
BREAKAWAY
  #6   Spotlight this post!  
Unread 24-02-2008, 02:56
Guarana Guarana is offline
Registered User
FRC #1706
 
Join Date: Jan 2008
Location: Wentzville, Missouri
Posts: 16
Guarana is an unknown quantity at this point
Re: gyro problem

Quote:
Originally Posted by Uberbots View Post
you may want to make the ratio that you multiply temp_gyro_angle by higher or lower depending on how fast/slow you want it to correct.
you mean divide by? and yes i get what you mean. but again, i won't be able to test until competition.
  #7   Spotlight this post!  
Unread 24-02-2008, 12:04
Uberbots's Avatar
Uberbots Uberbots is offline
Mad Programmer
AKA: Billy Sisson
FRC #1124 (ÜberBots)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Avon
Posts: 739
Uberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond reputeUberbots has a reputation beyond repute
Re: gyro problem

Quote:
Originally Posted by Guarana View Post
you mean divide by? and yes i get what you mean. but again, i won't be able to test until competition.
well you are multiplying by 1/15, so i mean multiply.
__________________
A few of my favorite numbers:
175 176 177 195 230 558 716 1024 1071 1592 1784 1816
RPI 2012
BREAKAWAY
  #8   Spotlight this post!  
Unread 24-02-2008, 17:06
cgront's Avatar
cgront cgront is offline
Registered User
None #0159
Team Role: Operator
 
Join Date: Jan 2006
Rookie Year: 2000
Location: blah blah
Posts: 5
cgront is an unknown quantity at this point
Re: gyro problem

I think that you should use Get_Gyro_Angle() to get data from the gyro. That is how we used it. Also We had a similar problem with our field centric omni drive. It was caused by a division by 0. Good Luck from 1647
__________________
some of Murphy's Laws of Computing


1)When computing, whatever happens, behave as though you meant it to happen.

  #9   Spotlight this post!  
Unread 24-02-2008, 22:52
Guarana Guarana is offline
Registered User
FRC #1706
 
Join Date: Jan 2008
Location: Wentzville, Missouri
Posts: 16
Guarana is an unknown quantity at this point
Re: gyro problem

Code:
	signed int speed, turn, slide;
	signed int front_r, front_l, back_r, back_l;
	long int l_y, r_y, l_x, r_x;
	static unsigned int i = 0;
	static unsigned int j = 0;
	int temp_gyro_rate;
	long temp_gyro_angle;
	int temp_gyro_bias;
	long temp_gyro_angle_fast;
	long Encoder_Count;

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


	// enable this block of code to test your gyro 
	if(j == 10)
	{
		printf("\r\nCalculating Gyro Bias...\r\n");
	}
	if(j == 38) // let the gyro stablize for a second before starting a calibration
	{
		// start a gyro bias calculation
		Start_Gyro_Bias_Calc();
	}
	if(j == 191) // allow calibration routine to run for four seconds 
	{
		// terminate the gyro bias calculation
		Stop_Gyro_Bias_Calc();

		// reset the gyro heading angle
		Reset_Gyro_Angle();

		temp_gyro_bias = Get_Gyro_Bias();
		printf("Gyro Bias=%d\r\n", temp_gyro_bias);
	}
	if(i == 35 && j >= 191)
	{
		temp_gyro_rate = Get_Gyro_Rate();
		temp_gyro_angle = Get_Gyro_Angle();
		printf("Gyro Rate=%d\r\n", temp_gyro_rate);
		printf("Gyro Angle=%d\r\n\r\n", (int)temp_gyro_angle);
Here is the gyro calibration code. Is there anything wrong with this? Something I noticed, is that i and j both add one for each loop. So how does i = 35 and j be higher than 191 if they are always the same (for the last section). maybe i am missing something. would that be any reason?
  #10   Spotlight this post!  
Unread 03-03-2008, 15:48
Ken Streeter's Avatar
Ken Streeter Ken Streeter is offline
Let the MAYHEM begin!
FRC #1519 (Mechanical Mayhem)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Team: Milford, NH; Me: Bedford, NH
Posts: 475
Ken Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond repute
Re: gyro problem

Quote:
Originally Posted by Guarana View Post
Code:
	signed int speed, turn, slide;
	signed int front_r, front_l, back_r, back_l;
	long int l_y, r_y, l_x, r_x;
	static unsigned int i = 0;
	static unsigned int j = 0;
	int temp_gyro_rate;
	long temp_gyro_angle;
	int temp_gyro_bias;
	long temp_gyro_angle_fast;
	long Encoder_Count;

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


	// enable this block of code to test your gyro 
	if(j == 10)
	{
		printf("\r\nCalculating Gyro Bias...\r\n");
	}
	if(j == 38) // let the gyro stablize for a second before starting a calibration
	{
		// start a gyro bias calculation
		Start_Gyro_Bias_Calc();
	}
	if(j == 191) // allow calibration routine to run for four seconds 
	{
		// terminate the gyro bias calculation
		Stop_Gyro_Bias_Calc();

		// reset the gyro heading angle
		Reset_Gyro_Angle();

		temp_gyro_bias = Get_Gyro_Bias();
		printf("Gyro Bias=%d\r\n", temp_gyro_bias);
	}
	if(i == 35 && j >= 191)
	{
		temp_gyro_rate = Get_Gyro_Rate();
		temp_gyro_angle = Get_Gyro_Angle();
		printf("Gyro Rate=%d\r\n", temp_gyro_rate);
		printf("Gyro Angle=%d\r\n\r\n", (int)temp_gyro_angle);
Here is the gyro calibration code. Is there anything wrong with this? Something I noticed, is that i and j both add one for each loop. So how does i = 35 and j be higher than 191 if they are always the same (for the last section). maybe i am missing something. would that be any reason?
Further down in the code, i is reset to 0 every time that it increases to 38, in a small block as follows:
Code:
	// reset the loop counter
	if(i >= 38)
	{
		i = 0;
	}
Essentially, i is the number of loops in the "current second" of looping; while j is the total number of loops executed in teleop since the robot was reset.
__________________
Ken Streeter - Team 1519 - Mechanical Mayhem (Milford Area Youth Homeschoolers Enriching Minds)
2015 NE District Winners with 195 & 2067, 125 & 1786, 230 & 4908, and 95 & 1307
2013 World Finalists & Archimedes Division Winners with 33 & 469
2013 & 2012 North Carolina Regional Winners with teams 435 & 4828 and 1311 & 2642
2011, 2010, 2006 Granite State Regional Winners with teams 175 & 176, 1073 & 1058, and 1276 & 133
Team 1519 Video Gallery - including Chairman's Video, and the infamous "Speed Racer!"
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
Problem with gyro... capenga Programming 21 16-02-2006 19:25
Gyro not accurate - Problem naor52 Programming 15 27-01-2006 16:50
Gyro code problem AMIRAM Programming 10 23-01-2006 04:26
Gyro magical hands Programming 2 14-01-2005 20:57


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

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