I’ve set up everything according to the documentation below
init.c:
// Multiple gyros can be declared
Gyro gyro;
void initialize() {
// ...
// If gyro reads inaccurately, change "0" to desired sensitivity
// See documentation on gyroInit for up-to-date sensitivity details
gyro = gyroInit(gyro_port_number, 0);
// ...
}
main.h:
// Variable name matches gyro name(s) in init.c
extern Gyro gyro;
opcontrol.c or auto.c:
void ...() {
// ...
// Get gyro reading in degrees
int heading = gyroGet(gyro);
// Reset gyro to zero
gyroReset(gyro);
// ...
}
When i run the code the value of “heading” starts at 0 and without moving the robot it starts decreasing in the negative range at about 1000 ticks per second.
I’ve also tried to to declare it like this, just like the API But just get a compiler error.
int gyroGet (Gyro gyro)
Any help is greatly appreciated and again Thanks in advanced!
I forgot to mention i was not calling reset every time… I’ve just tried this code with no luck.
init.c
Gyro MyGyro;
void initialize() {
MyGyro = gyroInit( 6, 0 ); //Gyro is on Analog port 6
wait(2000);
}
opcontrol.c
#include "main.h"
extern Gyro MyGyro;
void operatorControl() {
while (1) {
printf("gyro is %d\r\n", gyroGet(MyGyro) );
delay(200);
}
}
This is what I received in my terminal window without moving the robot.
gyro is -4920
gyro is -5198
gyro is -5476
gyro is -5754
gyro is -6033
gyro is -6311
gyro is -6589
gyro is -6867
gyro is -7145
gyro is -7423
gyro is -7701
gyro is -7979
gyro is -8258
gyro is -8536
gyro is -8814
Same result as my code from yesterday. I’ve tested this same configuration successfully with Easy C.
Hmm, I tested that code last night with the gyro plugged into analog input 1. What do you get if you just print the raw analog values coming from the gyro, mine usually reads somewhere around 1860 (should be 2048 in a perfect world).
I guess it could be port related (although I don’t see why), when I get home tonight I will try port 6.
Then it smells like a bug, perhaps you could do the Purdue guys a favor and document which ports are working. You could also see if the gyro plugged into port 5, 7 or 8 works when the code is set for port 6 (probably won’t make a difference as the raw analog reading is correct). The analog port mapping is a bit odd on the cortex, port to ADC mapping is as follows.
Port 1 ADC0
Port 2 ADC1
Port 3 ADC2
Port 4 ADC3
Port 5 ADC12
Port 6 ADC13
Port 7 ADC10
Port 8 ADC11
We have found that the gyro is indeed non-functional on ports 5-8. Code for the analog gyroscope was copied from the analogRead() function, but a bug affecting analogRead() which caused it to use the port-to-channel mapping table more than once was found and fixed after this occurred and before the first PROS release.
The copied code was in another file (analogReadCalibratedHR() to be precise) and was therefore not updated. Automated testing also failed to identify the bug as the gyro was only tested on port 3 as part of a larger sensor test program that tests all types of sensors at once.
This issue has been fixed in the next version of PROS.