|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!
Ok, now I am getting an output from the gyro but it changes only when you turn it and then it goes back to zero when it stops turning.
Code:
private I2C gyro = new I2C(I2C.Port.kOnboard, 0x68);
protected void initialize () {
gyro.write(0x6B, 0x03); // Power
gyro.write(0x1A, 0x1B); // Basic Config
gyro.write(0x1B, 0x18); // Gyro Config
}
protected void execute () {
byte[] angle = new byte[1];
gyro.read(0x47, 2, angle);
double rotation = (angle[1] << 8) | angle[0];
System.out.println("Rotation: " + rotation);
}
protected boolean isFinished () {
return false;
}
protected void end () {
}
protected void interrupted () {
end();
}
|
|
#2
|
||||
|
||||
|
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!
Ok now I am adding up the values from the gyro to get degrees, but when the robot turns in the positive direction the value shoots up to the thousands, and in the positive direction it goes to -3 max.
|
|
#3
|
||||
|
||||
|
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;
}
|
|
#4
|
|||||
|
|||||
|
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!
Hey Thanks!
We were just looking for something like this <sweet> ![]() |
|
#5
|
|||
|
|||
|
Re: Help! Why Can't I Read Gyro Values Over the I2C Interface!
Bumping this year old thread to thank the authors. This came up on a google search, and it was part of what got me able to get my new mpu6050 working.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|