I've now tried to do something different: A friend pointed out that I am declaring my Gx, Gy and Gz as local variables that exist within the loop and suggested I try to make them global variables.
What would making this change actually do? Since the G values are used only within the loop, and have a different value assigned to them at the beginning of each iteration, I don't understand what the difference is.
I've now declared Gx, Gy and Gz as global variables and have put in some "housekeeping" lines to reset their values to zero at the end of the loop. Seems to work, I need to perform a bit more testing to tweak the values.
Here is my "new" implementation:
#include "hardware.h"
//Variables now declared as global
int Gx;
int Gy;
int Gz;
// Initialise the hardware
void appInitHardware(void) {
initHardware();
}
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0;
}
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
gyroRead(pitchRoll);
gyroRead(yaw);
//Gyro offset correction
Gx=pitchRoll.gyro.x_axis_degrees_per_second - 0;
Gy=pitchRoll.gyro.y_axis_degrees_per_second - 0;
Gz=yaw.gyro.z_axis_degrees_per_second + 0;
//Gyro rprintf
rprintf("\nGx= %d (Deg/s), Gy= %d (Deg/s), Gz= %d (Deg/s) \n",
Gx,
Gy,
Gz);
//housekeeping, or resetting Gx,Gy and Gz to zero
Gx=0;
Gy=0;
Gz=0;
//wait to do next reading in ms
delay_ms(500);
return 0;