Hiya,
I am currently doing my master's project partially using an mbed, designing a inertial navigation system integrated with GPS and a barometric altimeter using an Extended Kalman Filter.
My problem is reproduced in the code as below:
#include "mbed.h"
class tes{
public:
Serial* p;
tes(Serial* pc, Serial* gps){
p = pc;
wait(1);
p->putc('y');
gps->attach(this, &tes::rx, Serial::RxIrq);
}
void rx() {
DigitalOut l(LED2);
l = 1;
p->putc('x');
}
};
Serial gps(p28, p27);
Serial pc(USBTX, USBRX);
int main() {
tes t(&pc, &gps);
gps.baud (115200);
pc.baud(115200);
pc.printf("test\r\n");
}
When this code is run, two problems occur:
1) The 'x' character is never printed to the pc output, but the LED does come on.
2) The 'y' character is never printed to the pc output.
Playing around with the code, I found that problem 1 can be solved by the following three changes:
1) Declaration of tes t made outside of function main, below the serial declarations.
2) t declared as tes* t = new tes(&pc, &gps), inside function main.
3) t declared as tes* t = new tes(&pc, &gps), outside function main, below the serial declarations.
I do not understand why these should work but the original code does not. I also tried moving the gps.attach call to the main function with the corresponding changes, however the results were the same as for above. However, none of these changes solve problem 2.
Hope that is enough information for someone to help me, I've started pulling my hair out now!
Cheers,
Rob
Hiya,
I am currently doing my master's project partially using an mbed, designing a inertial navigation system integrated with GPS and a barometric altimeter using an Extended Kalman Filter.
My problem is reproduced in the code as below:
When this code is run, two problems occur: 1) The 'x' character is never printed to the pc output, but the LED does come on. 2) The 'y' character is never printed to the pc output.
Playing around with the code, I found that problem 1 can be solved by the following three changes: 1) Declaration of tes t made outside of function main, below the serial declarations. 2) t declared as tes* t = new tes(&pc, &gps), inside function main. 3) t declared as tes* t = new tes(&pc, &gps), outside function main, below the serial declarations.
I do not understand why these should work but the original code does not. I also tried moving the gps.attach call to the main function with the corresponding changes, however the results were the same as for above. However, none of these changes solve problem 2.
Hope that is enough information for someone to help me, I've started pulling my hair out now!
Cheers, Rob