Shop OBEX P1 Docs P2 Docs Learn Events
Trouble With Values — Parallax Forums

Trouble With Values

SRLMSRLM Posts: 5,045
edited 2008-11-29 19:45 in Propeller 1
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.
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-29 18:05
    Instead of "LONG[noparse][[/noparse]@headingValues + count]" use "LONG[noparse][[/noparse]@headingValues][noparse][[/noparse]count]".

    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]"
  • SRLMSRLM Posts: 5,045
    edited 2008-11-29 19:45
    Thank you very much! That lead to the solution. My problem was that in the first block of code that I posted, I saved values using LONG[noparse][[/noparse]aheadingValues + counter], which moved it (as you said) by one bye each increment of count. So the problem wasn't reading the values, it was where I saved it.

    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.
Sign In or Register to comment.