Well, as you can see from my previous post (and the output below), straight() is returning 219, while xoff = 196 and xoff_239 = 159. The values for xoff and xoff_239 are correct and reasonable. The return value from straight() should be -37.
Code:
Offset from straight: 219 xoff: 196 xoff_239: 159
the return value of straight is computed directly on it's last line from these two values
Code:
return xoff_239 - xoff;
I just ran the code, again. With the surveyor just to the right of the center line, where the expected result is positive (the first line, below), it gives responds as expected, but when the surveyor is just left of center, and a negative number is expected (the second line, below), the return value is the two's complement, as if the value was 8 bit unsigned.
Code:
Offset from straight: 26 xoff: 142 xoff_239: 168
Offset from straight: 252 xoff: 172 xoff_239: 168
What else could be causing this discrepancy?
Well, I just made a simple change to the picoC script and it seems to be working, now.
Code:
Offset from straight: -36 xoff: 198 xoff_239: 162
The change that I made was in the declaration of 'x', the variable accepting the return value from straight(). I originally declared and set it to "0" in a single statement
Code:int x = 0;
This resulted in the incorrect result. When I split the above line into two statements
Code:int x;
x = 0;
I get the correct results.
I know that there had been a problem in the past with declaring a variable and setting it in the same statement, but that resulted in an unchangeable variable. This is something different. Perhaps the fix for the previous bug has created a new one?