Shop OBEX P1 Docs P2 Docs Learn Events
Help me SPIN! — Parallax Forums

Help me SPIN!

DgswanerDgswaner Posts: 795
edited 2008-07-07 13:57 in Propeller 1
the following code is to read 5 pings, and display a "**" below the one that is the highest value, it works but I get incorrect readings when one of the pings gets a false reading or when it reads a really high distance. the high 4th and 5th pings seem to not get included in the comparison and display a higher number until I get the other pings below 10" or so.

right now it reads
22   12  17   50 45
**



if I put my hand in front of the ping reading 22 it reads
02  12   16  50   45
             **



Is there a better way to do this? I can't see where I'm going wrong here. ultimately this is to tell the bot which direction is clear so it kinda important I get this working.

thanks for any input.

***** reformatted the code below ***** still have formatting errors
[b]PUB[/b] Start

  LCD.init(LCD_Pin, LCD_Baud, LCD_Lines)                ' Initialize LCD Object
  LCD.cursor(0)                                         ' Turn Off Cursor
  LCD.backlight([b]true[/b])                                   ' Turn On Backlight   
  LCD.cls                                               ' Clear Display
  [b]repeat[/b]
    range[noparse][[/noparse]0] := 1 'ping.Inches(PING_Pina)                  ' Get Range In Inches
    range[noparse][[/noparse]1] := 2 'ping.Inches(PING_Pinb)                  ' Get Range In Inches
    range[noparse][[/noparse]2] := 9' ping.Inches(PING_Pinc)                  ' Get Range In Inches
    range[noparse][[/noparse]3] := 4' ping.Inches(PING_Pind)                  ' Get Range In Inches
    range[noparse][[/noparse]4] := 5' ping.Inches(PING_Pine)                  ' Get Range In Inches
    range[noparse][[/noparse]5] := 0    
    [b]repeat[/b] index [b]from[/b] 0 to 4                           
      LCD.gotoxy(Index * 4, 0)                          ' Position Cursor              
      LCD.decx(range[noparse][[/noparse]Index], 2)                         ' Print Inches
      [b]if[/b] Range[noparse][[/noparse]index] > range[noparse][[/noparse]Range[noparse][[/noparse]5]]
           Range[noparse][[/noparse]5] := index
    lcd.clrln(1)
    LCD.gotoxy(range[noparse][[/noparse]5]*4, 1)
    LCD.[b]str[/b]([b]string[/b]("**"))  
    [b]waitcnt[/b](clkfreq / 10 + [b]cnt[/b])                         ' Pause 1/10 Second



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Post Edited (Dgswaner) : 7/7/2008 7:26:27 AM GMT

Comments

  • ColeyColey Posts: 1,110
    edited 2008-07-07 06:30
    Hi,

    I would say it's got something to do with your use of variable names.

    You have used 'range' as the variable you are checking and also the index:-

    Also, your don't seem to be loading the variable range[noparse][[/noparse]x] correctly, I have input some values manually.....

    EDIT, I think you probably did but when you post code into the post it does weird things with square brackets....
    it is discussed in this post http://forums.parallax.com/showthread.php?p=573926
    Best way is to use Phil's (PhiPi) code formatter here www.phipi.com/format/

    I have adapted your routine for TV_Text as I don't have an LCD to hand right now, or a ping module for that matter wink.gif

    [b]CON[/b]
    
    ' .-----------------------------------------------------------------------------------------------------.
    ' |     Board Configuration                                                                             |
    ' `-----------------------------------------------------------------------------------------------------'
    
      [b]_CLKMODE[/b]                      = [b]XTAL[/b]1 + [b]PLL[/b]16x        ' 80MHz System Clock Speed
      [b]_XINFREQ[/b]                      = 5_000_000
    
    [b]OBJ[/b]
    
      tv                            : "TV_Text"             ' Debugging only - can be deleted
    [b]VAR[/b]
    
       [b]long[/b] Range[noparse][[/noparse]10]  
    [b]PUB[/b] Start | pointer, index
    
      tv.start(24)
    
      [b]repeat[/b]
        range[noparse][[/noparse]0] := 22 'ping.Inches(PING_Pina)                  ' Get Range In Inches
        range[noparse][[/noparse]1] := 12 'ping.Inches(PING_Pinb)                  ' Get Range In Inches
        range[noparse][[/noparse]2] := 17 'ping.Inches(PING_Pinc)                  ' Get Range In Inches
        range[noparse][[/noparse]3] := 50 'ping.Inches(PING_Pind)                  ' Get Range In Inches
        range[noparse][[/noparse]4] := 45 'ping.Inches(PING_Pine)                  ' Get Range In Inches
        pointer := 0    
        [b]repeat[/b] index [b]from[/b] 0 to 4                           
          tv.out($0B)
          tv.out($00)
          tv.out($0A)
          tv.out(Index * 4)                                 ' Position Cursor              
          tv.dec(range[noparse][[/noparse]Index])                         ' Print Inches
          [b]if[/b] Range[noparse][[/noparse]index] > range[noparse][[/noparse]Pointer]
               Pointer := index
        'lcd.clrln(1)
        tv.out($0B)
        tv.out($01)
        tv.out($0A)
        tv.out(Pointer * 4)                                 ' Position Cursor
        tv.[b]str[/b]([b]string[/b]("**"))  
        [b]waitcnt[/b](clkfreq / 10 + [b]cnt[/b])                         ' Pause 1/10 Second
    
    
    





    Regards.


    Coley

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PropGFX Forums - The home of the Hybrid Development System and PropGFX Lite

    Post Edited (Coley) : 7/7/2008 6:36:33 AM GMT
  • DgswanerDgswaner Posts: 795
    edited 2008-07-07 07:42
    I tried my original code, but just manually added numbers as you did and it works fine. when I have the PINGS set the value it doesn't indicate the correct number as the highest. unless I put my hand in front ping 0 and 1

    [b]PUB[/b] Start
    
      LCD.init(LCD_Pin, LCD_Baud, LCD_Lines)                ' Initialize LCD Object
      LCD.cursor(0)                                         ' Turn Off Cursor
      LCD.backlight([b]true[/b])                                   ' Turn On Backlight   
      LCD.cls                                               ' Clear Display
      [b]repeat[/b]
        range[noparse][[/noparse]0] :=  ping.Inches(PING_Pina)                  ' Get Range In Inches
        range[noparse][[/noparse]1] :=  ping.Inches(PING_Pinb)                  ' Get Range In Inches
        range[noparse][[/noparse]2] :=  ping.Inches(PING_Pinc)                  ' Get Range In Inches
        range[noparse][[/noparse]3] :=  ping.Inches(PING_Pind)                  ' Get Range In Inches
        range[noparse][[/noparse]4] :=  ping.Inches(PING_Pine)                  ' Get Range In Inches
        'waitcnt(clkfreq / 10 + cnt)                         ' Pause 1/10 Second 
        pointer:= 0    
        [b]repeat[/b] index [b]from[/b] 0 to 4                           
           'waitcnt(clkfreq / 10 + cnt)                         ' Pause 1/10 Second 
          LCD.gotoxy(Index * 4, 0)                          ' Position Cursor              
          LCD.decx(range[noparse][[/noparse]Index], 2)                         ' Print Inches
          [b]if[/b] Range[noparse][[/noparse]index] > range[noparse][[/noparse]pointer]
               Pointer := index
        lcd.clrln(1)
        lcd.clrln(3)
        LCD.gotoxy(pointer*4, 1)
        LCD.[b]str[/b]([b]string[/b]("**"))  
        LCD.gotoxy(3,3)
        LCD.dec(range[noparse][[/noparse]pointer])
        [b]waitcnt[/b](clkfreq / 10 + [b]cnt[/b])                         ' Pause 1/10 Second
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner
  • ColeyColey Posts: 1,110
    edited 2008-07-07 08:27
    Hi Dgswaner,

    I guess it is a variable problem, how have you defined Range[noparse][[/noparse]x] is it byte, word or long?

    Please post the whole spin code and I will have a look at it.

    Regards

    Coley

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PropGFX Forums - The home of the Hybrid Development System and PropGFX Lite
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-07-07 08:28
    hello DGSWANER,

    as you posted only a part of your sourcecode i can only guess:

    your method is called start

    does this mean you use it as a start-method launching a new cog?

    how many bytes are reserved for the stack ?

    did you define your variables in the order
    - first all longs
    - second all words
    - third all bytes ?

    best regards

    Stefan




    to make a better analyse it is nescessary to post your complete code
  • hippyhippy Posts: 1,981
    edited 2008-07-07 09:03
    Dgswaner said...
    right now it reads
    22   12  17   50 45
    **
    
    


    Are you sure that's not just down to "LCD.decx(range[noparse][[/noparse]Index], 2)" ?

    Maybe "22" is really 122, 222 etc.
  • DgswanerDgswaner Posts: 795
    edited 2008-07-07 13:57
    and The winner is Hippy! I didn't think I was in an area with that much open space but it is reading as 122 and only displaying 22.
    I changed it to LCD.decx(range[noparse][[/noparse]Index], 3) and it points to the correct 3 digit number now.


    Thanks for all your help guys.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner
Sign In or Register to comment.