hello!
Every 0.02 (50Hz) I have to read a serial data. I didn't want to wait for the start of the line so I used an attach fuction to read the signal every 0.02 seconds. I did this with a GPS module and had no problems but now I haven't got a clue of what I am doing wrong. Here is the code:
#include "mbed.h"
Ticker signalrazor;
Serial pc(USBTX, USBRX); // tx, rx
Serial razor(NC,p14);
float roll, pitch, yaw;
void razorLine() {
while (razor.getc() != '!');
razor.scanf("ANG:%f,%f,%f", &roll, &pitch, &yaw);
return;
}
void ini_razor() {
razor.baud(57600);
while (razor.getc() != '!');
}
void inicializacion() {
pc.baud(115200);
ini_razor(); //main loop runs at 50Hz
wait(0.019);
signalrazor.attach(&razorLine, 0.02);
}
int main(){
inicializacion();
while(1){
wait(1);
pc.printf("%f\r\n",roll);
}
}
But it doesn't work. When I modify "wait(1);" from the main loop to "wait(0.02);" I get this:
2.190000
2.790000
3.250000
3.360000
3.330000
3.160000
2.930000
2.970000
3.060000
3.030000
2.670000
1.930000
0.870000
-0.040000
-0.430000
0.020000
0.200000
0.210000
0.140000
0.170000
0.160000
0.130000
At this point the transmision stops. When I increase the "wait" number I get less and less data till I get no data at all.
Is this the best way to do this? What I am doing wrong?
Thanks!
hello!
Every 0.02 (50Hz) I have to read a serial data. I didn't want to wait for the start of the line so I used an attach fuction to read the signal every 0.02 seconds. I did this with a GPS module and had no problems but now I haven't got a clue of what I am doing wrong. Here is the code:
But it doesn't work. When I modify "wait(1);" from the main loop to "wait(0.02);" I get this:Is this the best way to do this? What I am doing wrong?
Thanks!