I'm looking for some help on this one; I want to test the difference between some gyros, but I got stuck on the MPU6050. I'm using the jrowberg mpu6050 library (which I believe to be corrupting memory). Anyway, I made a wrapper for it based on his arduino test code (lets call it xmpu), then added the xmpu object to my rover object (call it rover) which also has a function pointer. Very strange behavior is exhibited.
Like this (but this is greatly simplified):
class Xmpu {
public:
MPU6050 mpu;
int address;
int packetSize;
byte buffer[64]'
}
class Rover {
public:
Xmpu xmpu;
void (*cb)();
}
Rover::test() {
println("CB VALUE IN TEST: " + cb);
if (cb) cb();
}
[In arduino code]:
rover.cb = &cb_fn;
println("CB VALUE 1: " + rover.cb);
rover.test();
println("CB VALUE 2: " + rover.cb);
void cb_fn() {
println("IN CB!");
}
--------- RESULTS -----
CB VALUE 1: 3257
CB VALUE IN TEST: 0
CB VALUE 2: 3257
Note that "IN CB!" was never printed.
Also, if I define cb in Rover _before_ xmpu, it runs as expected:
CB VALUE 1: 3257
CB VALUE IN TEST: 3257
IN CB!
CB VALUE 2: 3257
So, how does the value of rover.cb change from 3257 to 0 and back when the test() method is called (it doesn't _do_ anything!)? All I can figure is that the stack and/or the heap are seriously messed up, but rover.cb is the only thing that seems to be acting strangely.
I have no idea, but I think that I will try to simply the mpu6050 library and see if the problem goes away.
Ted