Go to Post I love how these contests always seem to find their way to go back to Dave Lavery and (pick one) Krispy Kreme/Heidi/Photoshop - DCA Fan [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 29-01-2013, 18:36
progal's Avatar
progal progal is offline
Programmer
AKA: Shelby
FRC #0384 (Sparky)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Glen Allen
Posts: 15
progal is an unknown quantity at this point
Gyro angle increasing while robot is static

We're trying to get the angle during Teleop mode. It worked in the past perfectly, and now every time we enable (and disable) the reading on the Driver Station LCD is rapidly decreasing 1/100th every second. But if the gyro feels like it, it will rapidly increase 1/100th every second.

This is how we're initiating it:
Code:
#include "WPILib.h"

/**
 * This is a demo program showing the use of the RobotBase class.
 * The SimpleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 */ 
class RobotDemo : public SimpleRobot
{
	RobotDrive myRobot; // robot drive system
	Joystick stick1, stick2; // only joystick
	ADXL345_I2C adxl;
	Gyro gyro;
	Relay *blinkylight;

public:
	RobotDemo(void):
		myRobot(2, 3),	// these must be initialized in the same order
		stick1(1),		// as they are declared above.
		stick2(2),
		adxl(1, ADXL345_I2C::kRange_2G),
		gyro(2)
	{
		myRobot.SetExpiration(0.1);
		blinkylight = new Relay(4);
	}
And this is how we're utilizing it:

Code:
void OperatorControl(void)
	{
		gyro.Reset();
		gyro.SetSensitivity(0.007);
		DriverStationLCD *dsLCD = DriverStationLCD::GetInstance();
		myRobot.SetSafetyEnabled(true);
		bool motorinv = false;
		
		while (true)
		{
			blinkylight->Set(Relay::kForward);
			/*
			ADXL345_I2C::AllAxes ax = adxl.GetAccelerations();
			//printf("X: %f, Y: %f, Z: %f", ax.XAxis, ax.YAxis, ax.ZAxis);
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line1, "X: %f", ax.XAxis);
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line2, "Y: %f", ax.YAxis);
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line3, "Z: %f", ax.ZAxis);
			*/
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line1, "X: %f",
					adxl.GetAcceleration(ADXL345_I2C::kAxis_X));
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line2, "Y: %f",
					adxl.GetAcceleration(ADXL345_I2C::kAxis_Y));
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line3, "Z: %f",
					adxl.GetAcceleration(ADXL345_I2C::kAxis_Z));
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line4, "Gyro: %f", gyro.GetAngle());
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line6, "Motorinv: %d", motorinv);
			dsLCD->UpdateLCD();
			
			if(stick1.GetRawButton(2) || stick2.GetRawButton(2))
			{
				if(motorinv == false)
				{
					motorinv = true;
				}
				else if(motorinv == true)
				{
					motorinv = false;
				}
			}
			myRobot.SetInvertedMotor(myRobot.kRearLeftMotor, motorinv);
			myRobot.SetInvertedMotor(myRobot.kRearRightMotor, motorinv);
			if((stick1.GetTrigger() == true) && (stick2.GetTrigger() == true))
			{
				myRobot.TankDrive(stick1,stick2);
			}
			else if(stick1.GetTrigger() == true && (stick2.GetTrigger() == false))
			{
				myRobot.ArcadeDrive(stick1);
				}
			else if(stick2.GetTrigger() == true && (stick1.GetTrigger() == false))
			{
				myRobot.ArcadeDrive(stick2);
			}
			else
			{
				myRobot.TankDrive(0.0, 0.0);
			}
			Wait(0.005);				// wait for a motor update time
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
I guess the question is, what are we doing wrong to get such extreme values? Like I said, this previously worked and we switched out gyros - same problem.

Thank you in advance!
Reply With Quote
  #2   Spotlight this post!  
Unread 31-01-2013, 10:27
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,067
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Gyro angle increasing while robot is static

In the past when I've used gyros, this happens when you set the sensitivity incorrectly.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #3   Spotlight this post!  
Unread 31-01-2013, 11:44
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Gyro angle increasing while robot is static

Changing .01 degrees per second is a pretty good drift rate for the gyros that I've worked with. I'm used to more like 0.05 degrees per second.
Reply With Quote
  #4   Spotlight this post!  
Unread 31-01-2013, 11:59
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
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,817
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: Gyro angle increasing while robot is static

Is the gyro calibrating with a still robot, e.g., hands-off, no compressor or other vibrating object running.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Reply With Quote
  #5   Spotlight this post!  
Unread 31-01-2013, 12:34
Mr. Lim Mr. Lim is offline
Registered User
AKA: Mr. Lim
no team
Team Role: Leadership
 
Join Date: Jan 2004
Rookie Year: 1998
Location: Toronto, Ontario
Posts: 1,125
Mr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond repute
Re: Gyro angle increasing while robot is static

Quote:
Originally Posted by Joe Ross View Post
Changing .01 degrees per second is a pretty good drift rate for the gyros that I've worked with. I'm used to more like 0.05 degrees per second.
Seconded...

I think your gyro is working just fine... probably better than ours!
__________________
In life, what you give, you keep. What you fail to give, you lose forever...
Reply With Quote
  #6   Spotlight this post!  
Unread 31-01-2013, 12:42
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,090
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Gyro angle increasing while robot is static


If the drift is bothersome during an extended practice or demo session, add a button to your code so the driver can re-zero the gyro whenever the robot is pointing in the zero direction.


Reply With Quote
  #7   Spotlight this post!  
Unread 31-01-2013, 14:30
Iaquinto.Joe's Avatar
Iaquinto.Joe Iaquinto.Joe is offline
RPI 2018
AKA: Joe Iaquinto
FRC #0308 (The Monsters)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2011
Location: United States
Posts: 166
Iaquinto.Joe is a jewel in the roughIaquinto.Joe is a jewel in the roughIaquinto.Joe is a jewel in the rough
Re: Gyro angle increasing while robot is static

Quote:
Originally Posted by Ether View Post

If the drift is bothersome during an extended practice or demo session, add a button to your code so the driver can re-zero the gyro whenever the robot is pointing in the zero direction.


Either this or just reset the gyro before you do an action.
__________________
4 year 2011 - 2014 FRC team 308 member, Lead Programmer - C++ / LabVIEW

3 year 2011, 2013, 2014 OCCRA member, Co-Captain OCCRA team 308
  • OCCRA Engineering Excellence - Waterford Kettering 2013
  • Innovation in Control - 2011
  • Quality award- Northville 2012
  • Engineering Excellence- Howell 2014
  • Innovation in Controls- Livonia 2014
Reply With Quote
  #8   Spotlight this post!  
Unread 31-01-2013, 14:35
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,090
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Gyro angle increasing while robot is static

Quote:
Originally Posted by Iaquinto.Joe View Post
Either this or just reset the gyro before you do an action.
That works only if the "action" is intended to be relative to the current position, not if you are using the gyro for true heading (e.g. field-centric control).


Reply With Quote
  #9   Spotlight this post!  
Unread 31-01-2013, 23:31
progal's Avatar
progal progal is offline
Programmer
AKA: Shelby
FRC #0384 (Sparky)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Glen Allen
Posts: 15
progal is an unknown quantity at this point
Re: Gyro angle increasing while robot is static

Thank you for all of your help everyone!

We figured it out:
The problem was the wire that provides power for the gyro wasn't plugged in..
But the code above does work, excluding the sensitivity. So we changed that to 0.05 and the gyro works perfectly now.
Reply With Quote
Reply


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 15:31.

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