Trouble With Values
SRLM
Posts: 5,045
Hello,
I'm having trouble with the code shown. The first block of code is in an object that gets launched into a new cog with a stack of 160 just to be sure, and the second block of code is the main program.
This block of code is supposed to get the distances in 18 different directions using the PING on a turret. It's doing 18 turns and pings, so I'm assuming that that part is okay. Also, it is iterating though the outside loop fine: I can print out the loop counter (the one that is incremented near the bottom) and watch the count go up.
This block of code is supposed to print out the distance measurements.
Okay. The odd part is that it prints out all measurements when I use the above code, but they are identical in blocks of four (except for the last two, which are their own group) I've attached a txt with this data. When I print the debug statement above with
then it just prints out five numbers and then the rest are zeros. What's happening here?
Post Edited (SRLM) : 11/29/2008 5:48:51 PM GMT
I'm having trouble with the code shown. The first block of code is in an object that gets launched into a new cog with a stack of 160 just to be sure, and the second block of code is the main program.
This block of code is supposed to get the distances in 18 different directions using the PING on a turret. It's doing 18 turns and pings, so I'm assuming that that part is okay. Also, it is iterating though the outside loop fine: I can print out the loop counter (the one that is incremented near the bottom) and watch the count go up.
PUB Distances | counter repeat repeat counter from 0 to 17 'Move servo repeat 20 servoProcess(pinSpinServo, 1050 + (50*counter)) waitcnt((20*mS) + cnt) 'Get Ping LONG[noparse][[/noparse]aheadingValues + counter] := Millimeters(pinSpinPing) waitcnt(600*uS + cnt) 'For test purposes only LONG[noparse][[/noparse]afrontBump] := 0 LONG[noparse][[/noparse]arearBump] := 0 LONG[noparse][[/noparse]apingSpinCount] ++
This block of code is supposed to print out the distance measurements.
repeat debug.str(string(HOME)) tempCounter := pingSpinCount debug.dec(tempCounter) debug.str(string(13)) repeat count from 0 to 17 debug.dec(LONG[noparse][[/noparse]@headingValues + count]) debug.str(string(" mm", 13))
Okay. The odd part is that it prints out all measurements when I use the above code, but they are identical in blocks of four (except for the last two, which are their own group) I've attached a txt with this data. When I print the debug statement above with
debug.dec(headingValues[noparse][[/noparse]count])
then it just prints out five numbers and then the rest are zeros. What's happening here?
Post Edited (SRLM) : 11/29/2008 5:48:51 PM GMT
txt
219B
Comments
The difference is that the compiler puts in a multiplication by 4 because LONGs are 4 bytes in length.
You could also just use "LONG[noparse][[/noparse]@headingValues + 4*count]"
By the way, it's not clear why you're not using just "headingValues[noparse][[/noparse]count]"
I didn't use headingValues[noparse][[/noparse]count] because I was trying to see where the errors were, and so I wanted to read the values in the exact same way that I wrote them. But, the problem is solved! Thank you very much.