View Single Post
  #5   Spotlight this post!  
Unread 07-02-2015, 14:41
Brindlefly's Avatar
Brindlefly Brindlefly is offline
Registered User
AKA: Jake Kinsella
FRC #4761 (Robockets)
Team Role: Leadership
 
Join Date: Nov 2014
Rookie Year: 2014
Location: Reading, MA
Posts: 8
Brindlefly will become famous soon enough
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!

Ok I just figured it out. Here is the code for anyone who is interested.

Code:
private static double degrees = 0;
	
	private I2C gyro = RobotMap.gyro;
	
	public GyroSensor () {
		gyro.write(0x6B, 0x03); // Power
		gyro.write(0x1A, 0x18); // Basic Config
		gyro.write(0x1B, 0x00); // Gyro Config
	}
	
	public double getDegrees (double deltaTime) {
		byte[] angle = new byte[1];
		gyro.read(0x47, 1, angle);
		
		double rotation = (angle[0] * deltaTime) * 2;
		
		degrees += rotation;
		
		return -degrees;
	}
Reply With Quote