Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Gyro angle increasing while robot is static (http://www.chiefdelphi.com/forums/showthread.php?t=112325)

progal 29-01-2013 18:36

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!

virtuald 31-01-2013 10:27

Re: Gyro angle increasing while robot is static
 
In the past when I've used gyros, this happens when you set the sensitivity incorrectly.

Joe Ross 31-01-2013 11:44

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.

Mark McLeod 31-01-2013 11:59

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.

Mr. Lim 31-01-2013 12:34

Re: Gyro angle increasing while robot is static
 
Quote:

Originally Posted by Joe Ross (Post 1225236)
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! :D

Ether 31-01-2013 12:42

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.



Iaquinto.Joe 31-01-2013 14:30

Re: Gyro angle increasing while robot is static
 
Quote:

Originally Posted by Ether (Post 1225278)

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.

Ether 31-01-2013 14:35

Re: Gyro angle increasing while robot is static
 
Quote:

Originally Posted by Iaquinto.Joe (Post 1225348)
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).



progal 31-01-2013 23:31

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.


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

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi