Go to Post The best legacy of this little machine is the inspiration she provided to a whole generation of future explorers who witnessed the unveiling of a planet through the eyes of a robot. - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 29-01-2017, 15:17
sgwin sgwin is offline
Registered User
FRC #6484
 
Join Date: Nov 2016
Location: Greenwich, New York
Posts: 3
sgwin is an unknown quantity at this point
Gyro Issues

We are a rookie team that is trying to setup our drive system to drive straight by utilizing a gyro. We are having an issue with our gyro (ADXRS450) that came in the KoP. When we call getAngle() while our robot is stationary the angle constantly increases. We have tried gyro.reset() when the robot is initialized and the accumulators do reset to zero. However, they start to climb instantly (without touching the robot). Is this something that is supposed to happen or could we have something incorrectly set?

Below is our code:

Code:
package org.usfirst.frc.team6484.robot;

import edu.wpi.first.wpilibj.ADXRS450_Gyro;
import edu.wpi.first.wpilibj.AnalogGyro;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 * This is a sample program to demonstrate how to use a gyro sensor to make a
 * robot drive straight. This program uses a joystick to drive forwards and
 * backwards while the gyro is used for direction keeping.
 */
public class Robot extends IterativeRobot {
	private static final double kAngleSetpoint = 0.0;
	private static final double kP = 0.005; // propotional turning constant

	// gyro calibration constant, may need to be adjusted;
	// gyro value of 360 is set to correspond to one full revolution
	private static final double kVoltsPerDegreePerSecond = 0.0128;

	private static final int kLeftMotorFrontPort = 0;
	private static final int kLeftMotorBackPort = 1;
	private static final int kRightMotorFrontPort = 2;
	private static final int kRightMotorBackPort = 3;
	private static final int kGyroPort = 1;
	private static final int kJoystickPort = 0;

	private RobotDrive myRobot = new RobotDrive(kLeftMotorFrontPort, kLeftMotorBackPort, kRightMotorFrontPort, kRightMotorBackPort);
	private ADXRS450_Gyro gyro = new ADXRS450_Gyro();
	private Joystick joystick = new Joystick(kJoystickPort);

	@Override
	public void robotInit() {
		gyro.reset();
//		gyro.calibrate();

	}
	
	/**
	 * The motor speed is set from the joystick while the RobotDrive turning
	 * value is assigned from the error between the setpoint and the gyro angle.
	 */
	@Override
	public void teleopInit(){
	}

	@Override
	public void teleopPeriodic() {
		double turningValue = (kAngleSetpoint - gyro.getAngle()) * kP;
		double compensation = Math.copySign(turningValue, joystick.getY());
		myRobot.arcadeDrive(joystick.getY(), compensation);
	}
}
Reply With Quote
  #2   Spotlight this post!  
Unread 29-01-2017, 15:49
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,603
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 Issues

At what rate does it increase? Some drift is expected.
Reply With Quote
  #4   Spotlight this post!  
Unread 29-01-2017, 22:25
acastagna acastagna is offline
Registered User
FRC #1493
 
Join Date: Jan 2012
Location: Albany High School
Posts: 38
acastagna is an unknown quantity at this point
Re: Gyro Issues

Does turning the robot have any effect the on the angle from the gyro?
Is the drift rate high? It won't be zero, but it should be well below 1 degree per minute. We haven't used this particular gyro before, but could there be an issue with the SPI port?

You can re-calibrating, not just resetting. Be sure to not move the robot during the re-calibration period. That's a sure way to get high drift.
Reply With Quote
  #5   Spotlight this post!  
Unread 30-01-2017, 00:22
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,770
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Gyro Issues

I suggest that you measure the output voltage of the gyro. We had several of the previous generation of gyro give "at rest" voltages that were nowhere near the expected value of 2.5V. (As I recall, it was much closer to 5.0V). If the output is not exactly 2.5V, but reasonably close, you should be able to make adjustments in software.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #6   Spotlight this post!  
Unread 30-01-2017, 01:08
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,603
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 Issues

Quote:
Originally Posted by GeeTwo View Post
I suggest that you measure the output voltage of the gyro. We had several of the previous generation of gyro give "at rest" voltages that were nowhere near the expected value of 2.5V. (As I recall, it was much closer to 5.0V). If the output is not exactly 2.5V, but reasonably close, you should be able to make adjustments in software.
It wouldn't be useful to measure the output voltage of an SPI gyro.
Reply With Quote
  #7   Spotlight this post!  
Unread 30-01-2017, 13:13
sgwin sgwin is offline
Registered User
FRC #6484
 
Join Date: Nov 2016
Location: Greenwich, New York
Posts: 3
sgwin is an unknown quantity at this point
Re: Gyro Issues

It looks like our drift issue was caused by calling reset() inside TeleopInit(). We initially got about 2 degrees of drift in one minute. Once we removed the reset() we only saw a small drift.

We then tested our gyro by manually turning the bot 90, 180, 270, 360, etc. and we received the correct values. However, now we feel our calculations are not correct since we are still turning instead of driving straight.

If you look at our code above. We have only changed it by commenting out the reset() within the TeleopInit. We are only checking our Y value of our controller and setting our target direction to zero degrees. Any incite would be much appreciated.
Reply With Quote
  #8   Spotlight this post!  
Unread 30-01-2017, 14:18
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 118
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Gyro Issues

Try the following code changes:

To robotInit():

Code:
	@Override
	public void robotInit() {
		gyro.reset();
//		gyro.calibrate();

                // Allow kP to be changed on the fly in the smart dashboard
               SmartDashboard.putNumber("kP", kP);
	}
To teleopPeriodic():

Code:
	public void teleopPeriodic() {
                double err = (kAngleSetpoint - gyro.getAngle());
		double turningValue = err * SmartDashboard.getNumber("kP", kP);
		double compensation = Math.copySign(turningValue, joystick.getY());

                SmartDashboard.putNumber("compensation", compensation);
                SmartDashboard.putNumber("err", err);
		myRobot.arcadeDrive(joystick.getY(), compensation);
	}
The above changes should allow you to adjust your "kP" value on the fly, show you how much error is being detected and show the corresponding compensation. If you go to edit mode on your smart dashboard you can change the err and compensation output to line plots to see it over time as you drive.

Sometimes just seeing the values being produced can lead to some insight.

Hope that helps,
Paul
Reply With Quote
  #9   Spotlight this post!  
Unread 31-01-2017, 08:15
sgwin sgwin is offline
Registered User
FRC #6484
 
Join Date: Nov 2016
Location: Greenwich, New York
Posts: 3
sgwin is an unknown quantity at this point
Re: Gyro Issues

Using Paul's suggestion, we monitored the kP value. We then did some tweaking and came up with a value of 0.007.

We now have a straight-driving robot!

Thank you all for your help!
Shawn
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 13:18.

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