Weird Artifact don't know why

30 Apr 2011

Hello, I'm having a weird artifact issue. I'm converting from a serial incoming string to a float, and sometimes it works sometimes it doesn't. if this was to happen during a flight it would be so bad :)

Here is the output

39.997784 -112.017746 1705.166626 <---- Plane  
39.995972 -112.018707 1609.333374 <---- Ground 
39.997784 -112.017746 1705.166626 <---- Plane  
-212655061101045080000000000000000000000.000000 39.997780 -112.017662 <---- Ground 
-212655061101045080000000000000000000000.000000, 42  1f  fd  bb  

What's happening is ground latitude screws up, and it's always that number -212650...

     while(1){
    while(groundStation.getc() != 0xff); // wait for the start of communication string
    msg[0] = 0xff;
        for(int i=1; i<26; i++) 
        {
        msg[i] = groundStation.getc();
        if (msg[25] == 0xfe)
        led1 = !led1;
        }
    //airplane
	p_lat = toFloat(msg[4], msg[3], msg[2], msg[1]);
	p_lon = toFloat(msg[8], msg[7], msg[6], msg[5]);
	p_alt = toFloat(msg[12], msg[11], msg[10], msg[9]);
	//ground
	g_lat = toFloat(msg[16], msg[15], msg[14], msg[13]);
	g_lon = toFloat(msg[20], msg[19], msg[18], msg[17]);
	g_alt = toFloat(msg[24], msg[23], msg[22], msg[21]);

  usb_232.printf("%f %f %f <---- Plane  \n", p_lat, p_lon, p_alt );
  usb_232.printf("%f %f %f <---- Ground \n", g_lat, g_lon, g_alt);
 
    if (g_lat < 0)
	{
	g_lat = toFloat(msg[16], msg[15], msg[14], msg[13]);
	usb_232.printf("\n\n %f, %0x  %0x  %0x  %0x  " , g_lat, msg[4], msg[3], msg[2], msg[1]);
    return 0;
	}

And Here is the function that does the bytes to float

float toFloat(uchar b0, uchar b1, uchar b2, uchar b3)
{
	float f;
	uchar b[4] = {b3, b2, b1, b0};
	float *fp = (float *)b;
	f  = *fp;
	return f;
}

I really have no idea what is happening. Any clue would be so helpful. Thank you guys

30 Apr 2011

Never mind thanks I was debugging usb_232.printf("\n\n %f, %0x %0x %0x %0x " , g_lat, msg[4], msg[3], msg[2], msg[1]);

which were correct values but what was incorrect was msg[16], msg[15], msg[14], msg[13

Looks like I was loosing some bits in translation here is what fixed it

Ah.. sleep!

void getString()  
    {
    do{
        while( (msg[0] = groundStation.getc()) != 0xff); // wait for the start of communication string
            for(int i=1; i<26; i++)  {
            msg[i] = groundStation.getc(); //fill message string
            }
       }while(msg[25] != 0xfe);
             led1 = led2 = !led1; //blink :)
    }
30 Apr 2011

The groundstation may be sending wrong values. I see that it seems there is a wrong value inserted for g_lat. Next one is 39.9.. as expected. You should check received bytevalues. Noticed that in your test for g_lat the wrong msg values are used in printf. Should be msg(16) etc rather than msg(4) etc. Other potential problems could be that 0xff appears in data and results in synchronisation issues when looking for start of message. The check for end of message does not work unless message buffer is cleared between messages and you wont see effect unless you switch led off between messages. You should add checksum and reject message when it fails.

30 Apr 2011

Wim Huiskamp wrote:

The groundstation may be sending wrong values. I see that it seems there is a wrong value inserted for g_lat. Next one is 39.9.. as expected. You should check received bytevalues. Noticed that in your test for g_lat the wrong msg values are used in printf. Should be msg(16) etc rather than msg(4) etc. Other potential problems could be that 0xff appears in data and results in synchronisation issues when looking for start of message. The check for end of message does not work unless message buffer is cleared between messages and you wont see effect unless you switch led off between messages. You should add checksum and reject message when it fails.

Thanks man.. I deceded not to do checksum, but check just to make sure the star bit and end bit are present.. and haven't had the problem come back... thanks for the help dude