Go to Post Another human taking a job that a robot could do... - Ryan Simpson [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 04:16.

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