Help me SPIN!
Dgswaner
Posts: 795
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
if I put my hand in front of the ping reading 22 it reads
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"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
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
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
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
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
Are you sure that's not just down to "LCD.decx(range[noparse][[/noparse]Index], 2)" ?
Maybe "22" is really 122, 222 etc.
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