Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   problem with autonomous that has stumped all programmers so far (http://www.chiefdelphi.com/forums/showthread.php?t=26557)

Daniel 10-03-2004 09:45

Re: problem with autonomous that has stumped all programmers so far
 
In the following code (with lots of test lines) the Move () function is called many time to determine if the move has completed. The printf which the first line of the function appears and so does the second showing "TT=%d". But the subsequent printf statments never appear and it acts like the function just simply returns to the caller.

I'm suspecting a problem with how C18 handles long math. Read the relese note... it can make a person worry about what works.

I've already logged one bug with Microchip. The SetChanADC function needs to shift the channel number one bit to the right. I'm working on another white paper about "Faster Analog" input. Anyone want to review it?

I have talked to other teams and many have seen this problem - but no one has indetified the "root cause". I'm officially told to re-enter my program. There has to be an answer to help all of us.

int Move (void) {
static long l, r;
int ll, rr;
static int t, t1, t2;

printf("In Move STATE 1.\n");
switch (next_state) {

// Ramp Up. Stay in this state for the ramp up time
// or until the braking distance.
case 1 :
// Have you traveled far enough at this speed to brake in a safe distance?
// Compute the average distance remaining to go.
// l = get_LeftWheelDistance () - StartDistanceLeft;
// r = get_RightWheelDistance () - StartDistanceRight;

// why is 1200 / 2 = 22
ll = 1200;
rr = 0;
t = ll + rr;
printf ("TT = %d\n", t);
t = t / 2; // t = 1200 then t = t /2 results in 22!
printf ("TT = %d\n", t);

printf ("1200/2 %d\n", 1200/2);
l = 1200;
r = 0;
t = (int) l + (int) r;
printf ("T = %d\n", t);
t = t / 2; // t = 1200 then t = t /2 results in 22!
printf ("T = %d\n", t);
t = lAbs((long) t);
printf (" Move 1 l %4d r %4d Avg %4d\n", (int) l, (int) r, t);
...

deltacoder1020 10-03-2004 12:25

Re: problem with autonomous that has stumped all programmers so far
 
Quote:

Originally Posted by Daniel
In the following code (with lots of test lines) the Move () function is called many time to determine if the move has completed. The printf which the first line of the function appears and so does the second showing "TT=%d". But the subsequent printf statments never appear and it acts like the function just simply returns to the caller.

I'm suspecting a problem with how C18 handles long math. Read the relese note... it can make a person worry about what works.

I've already logged one bug with Microchip. The SetChanADC function needs to shift the channel number one bit to the right. I'm working on another white paper about "Faster Analog" input. Anyone want to review it?

I have talked to other teams and many have seen this problem - but no one has indetified the "root cause". I'm officially told to re-enter my program. There has to be an answer to help all of us.

...

%d is designed to print out an int, not a long. chances are that is the source of your problem. also, you might try the following to correct the "1200/2 = 22" bug:

Code:

t = t / (long)2;
instead of the current t = t / 2; line.

this is because 2 is automatically type cast to an unsigned char, and thus the math is performed in the unsigned char space, not the long space.

Daniel 10-03-2004 22:22

Re: problem with autonomous that has stumped all programmers so far
 
I'll try it tommorrow between doing inspections.

But as a computer scientis type of person I want to know why something that simple and obscure can make a function prematurely return or act weird. Then I'll know that I have the problem solved, and it will not come back and byte me again.


All times are GMT -5. The time now is 00:14.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi