Shop OBEX P1 Docs P2 Docs Learn Events
Line-Maze Algorithm solved..... but??? — Parallax Forums

Line-Maze Algorithm solved..... but???

RichardV2RichardV2 Posts: 4
edited 2008-10-21 12:33 in BASIC Stamp
I completed the initial code for a line maze robot.
I know how to "unwind" all the bad/dead ends so that the robot can avoid all the dead ends the second time through.
I just don't know how to store the shortest path from run #1 and then use it in run #2.
Say after run #1, my shortest path is: LRSSRLSR (L = left, R = right, S = straight)
I have LRSSRLSR in an array (actually as numbers instead of letters) when the program shuts down at the end of run #1. What do I do with this so the robot knows to follow this path on run #2???

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-10-20 22:29
    Store it in EEPROM with write.
  • RichardV2RichardV2 Posts: 4
    edited 2008-10-21 03:46
    If I can be sure a byte in EEPROM is zero when it first lights off, I can do this:

    Read EEPROM byte
    If 0 then
    ...write 1 to EEPROM byte for next trip
    ...GoThroughMazeFromScratch
    else
    ...readShortestPathFromEEPROM
    ...follow shortest path
    endif

    If EEPROM stays the same from the last program, then this won't work... Or can I write a zero to the EEPROM byte when I download the code?

    ·
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-21 12:33
    Normally, eeprom is 'cleared' when you download a new program. "Download" here being defined as "bringing up the IDE, connecting the BS2 to your computer, and clicking "Run".

    When you use "DATA" statements in your code, each time you 'download' a new program, those DATA statements are written to eeprom, and can be read with "READ" and changed with "WRITE".

    There IS a way of "reserving" EEPROM space from being cleared -- I think it's an option of the DATA statement.

    If you don't "download" a new program, whatever you WRITE to eeprom stays until you WRITE something new to eeprom. You can only WRITE each location a million times, so be careful during testing.
Sign In or Register to comment.