Shop OBEX P1 Docs P2 Docs Learn Events
File Merging with BS2sx — Parallax Forums

File Merging with BS2sx

ArchiverArchiver Posts: 46,084
edited 2003-04-08 06:28 in General Discussion
Here it goes -- I am working on my Thesis in Computer Engineering,
and I've encountered some limitations with the Basic Stamp 2sx.

If any of you can get this I will be very impressed:

My program is too big for one slot, so I have decided to break it up
into multiple files. One is the 'main' loop - containing all 'IF ...
THEN function1' type statements. The other files contain the
functions. The problem is that I cannot get the if statements to
goto functions in the other files.

I have already done the linking in the header, and it works fine, but
they will not call each other directly.

The error is as follows...
"Error...undefined label"

Thank you in advance for your response. I'll check back often to see
if there are any questions about it.

Thanks again,
Mike
Tulane University
New Orleans, LA

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-04-04 01:09
    You have to do a little more work than that, I'm afraid. When you move
    to another bank you have to "Run" it and the program starts at the
    beginning in that bank. Of course, you can vector to somewhere in the
    bank using a variable. Then the return is also problematic because you
    have to run back to the original bank.

    Peter Verkaik was nice enough to contribute a lot of work he did on this
    a while back to the unofficial Basic Stamp FAQ:

    http://www.wd5gnr.com/stampfaq.htm?qframe=1&faq=1&article=60

    Al Williams
    AWC
    * 8 channels of PWM
    http://www.al-williams.com/awce/pak5.htm



    >
    Original Message
    > From: MBW [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=lmGb2hMi9cP4A0nuIGBBWZHuRWDBZNrkRq3X4SoQ2N7V0aQfqF-AJIMOzDuVOM-MRnxUy08aQo9aRkGIzw]walker@e...[/url
    > Sent: Thursday, April 03, 2003 5:31 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] File Merging with BS2sx
    >
    >
    > Here it goes -- I am working on my Thesis in Computer Engineering,
    > and I've encountered some limitations with the Basic Stamp 2sx.
    >
    > If any of you can get this I will be very impressed:
    >
    > My program is too big for one slot, so I have decided to break it up
    > into multiple files. One is the 'main' loop - containing all 'IF ...
    > THEN function1' type statements. The other files contain the
    > functions. The problem is that I cannot get the if statements to
    > goto functions in the other files.
    >
    > I have already done the linking in the header, and it works fine, but
    > they will not call each other directly.
    >
    > The error is as follows...
    > "Error...undefined label"
    >
    > Thank you in advance for your response. I'll check back often to see
    > if there are any questions about it.
    >
    > Thanks again,
    > Mike
    > Tulane University
    > New Orleans, LA
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-04 01:28
    You need to use the EEPROM to store flags, and then jump to your subroutines
    (functions) based on these flags once you get to the other slot.


    Original Message

    > Here it goes -- I am working on my Thesis in Computer Engineering,
    > and I've encountered some limitations with the Basic Stamp 2sx.
    >
    > If any of you can get this I will be very impressed:
    >
    > My program is too big for one slot, so I have decided to break it up
    > into multiple files. One is the 'main' loop - containing all 'IF ...
    > THEN function1' type statements. The other files contain the
    > functions. The problem is that I cannot get the if statements to
    > goto functions in the other files.
    >
    > I have already done the linking in the header, and it works fine, but
    > they will not call each other directly.
    >
    > The error is as follows...
    > "Error...undefined label"
    >
    > Thank you in advance for your response. I'll check back often to see
    > if there are any questions about it.
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-04 01:50
    Mike:

    Go to our web site and download my Nuts & Volts article #87 on multi-bank
    programmer. Download the code too. It shows how to call external [noparse][[/noparse]in
    another slot] subroutines from a main program using the scratchpad RAM to
    pass data back and forth.

    -- Jon Williams
    -- Parallax


    In a message dated 4/3/2003 5:33:19 PM Central Standard Time,
    walker@e... writes:

    > Here it goes -- I am working on my Thesis in Computer Engineering,
    > and I've encountered some limitations with the Basic Stamp 2sx.
    >
    > If any of you can get this I will be very impressed:
    >
    > My program is too big for one slot, so I have decided to break it up
    > into multiple files. One is the 'main' loop - containing all 'IF ...
    > THEN function1' type statements. The other files contain the
    > functions. The problem is that I cannot get the if statements to
    > goto functions in the other files.
    >
    > I have already done the linking in the header, and it works fine, but
    > they will not call each other directly.
    >
    > The error is as follows...
    > "Error...undefined label"
    >
    > Thank you in advance for your response. I'll check back often to see
    > if there are any questions about it.
    >
    > Thanks again,
    > Mike
    > Tulane University
    > New Orleans, LA



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-04 02:26
    Try this URL for cross-bank techniques:

    http://www.emesys.com/BS2SX.htm#Crossbank

    - Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-05 19:21
    Thank you all very much. It has taken me a day to go over all of the
    literature that you suggested.

    I'm sad to say that it didn't help solve the problem. I'll try to
    explain it further if you have the time...

    Ok, I have a series of 6 light emitting and detecting diodes that
    are being sent as inputs [noparse][[/noparse]IN0 -> IN5] to the stamp. The entire
    memory of the first file is taken up with IF...THEN statements
    depending on the reading of those diodes. There is no room for
    subroutines in this file (maybe one or two short ones {consisting of
    just a few instructions} if absolutely necessary.

    Depending on the inputs, the machine should respond respectively by
    outputing a code to pins 6-10 [noparse][[/noparse]OUT6 -> OUT10] and manipulating the
    appropriate varaibles and such.

    The problem is that all of the subroutines are called from the main
    loop, and unless they can be put into another file, the main file
    must have all of the subroutines in it. Does this make sense?

    Thank you guys again,
    Mike.


    --- In basicstamps@yahoogroups.com, "MBW" <walker@e...> wrote:
    > Here it goes -- I am working on my Thesis in Computer Engineering,
    > and I've encountered some limitations with the Basic Stamp 2sx.
    >
    > If any of you can get this I will be very impressed:
    >
    > My program is too big for one slot, so I have decided to break it
    up
    > into multiple files. One is the 'main' loop - containing
    all 'IF ...
    > THEN function1' type statements. The other files contain the
    > functions. The problem is that I cannot get the if statements to
    > goto functions in the other files.
    >
    > I have already done the linking in the header, and it works fine,
    but
    > they will not call each other directly.
    >
    > The error is as follows...
    > "Error...undefined label"
    >
    > Thank you in advance for your response. I'll check back often to
    see
    > if there are any questions about it.
    >
    > Thanks again,
    > Mike
    > Tulane University
    > New Orleans, LA
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-05 19:52
    Please post your code


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-07 18:26
    If 6 sensors takes up all your code in a segment I'm betting you have a
    coding problem that could be made more efficient with something like a state
    machine.
    I've written some pretty big programs with lots of subroutines and only run
    out of memory in once.


    Original Message
    From: MBW [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=PWwTkJ21L41JLwelRVMMJeIMo-OmgT777j5ugG4m-APW7KeAPN5yGz_XqSEre5sarF6xWRMXoY08ZF5t]walker@e...[/url
    Sent: Saturday, April 05, 2003 1:21 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Re: File Merging with BS2sx

    Thank you all very much. It has taken me a day to go over all of the
    literature that you suggested.

    I'm sad to say that it didn't help solve the problem. I'll try to
    explain it further if you have the time...

    Ok, I have a series of 6 light emitting and detecting diodes that
    are being sent as inputs [noparse][[/noparse]IN0 -> IN5] to the stamp. The entire
    memory of the first file is taken up with IF...THEN statements
    depending on the reading of those diodes. There is no room for
    subroutines in this file (maybe one or two short ones {consisting of
    just a few instructions} if absolutely necessary.

    Depending on the inputs, the machine should respond respectively by
    outputing a code to pins 6-10 [noparse][[/noparse]OUT6 -> OUT10] and manipulating the
    appropriate varaibles and such.

    The problem is that all of the subroutines are called from the main
    loop, and unless they can be put into another file, the main file
    must have all of the subroutines in it. Does this make sense?

    Thank you guys again,
    Mike.


    --- In basicstamps@yahoogroups.com, "MBW" <walker@e...> wrote:
    > Here it goes -- I am working on my Thesis in Computer Engineering,
    > and I've encountered some limitations with the Basic Stamp 2sx.
    >
    > If any of you can get this I will be very impressed:
    >
    > My program is too big for one slot, so I have decided to break it
    up
    > into multiple files. One is the 'main' loop - containing
    all 'IF ...
    > THEN function1' type statements. The other files contain the
    > functions. The problem is that I cannot get the if statements to
    > goto functions in the other files.
    >
    > I have already done the linking in the header, and it works fine,
    but
    > they will not call each other directly.
    >
    > The error is as follows...
    > "Error...undefined label"
    >
    > Thank you in advance for your response. I'll check back often to
    see
    > if there are any questions about it.
    >
    > Thanks again,
    > Mike
    > Tulane University
    > New Orleans, LA


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-07 18:35

    Original Message
    From: "Sadler Porter" <porter.sadler@s...>
    | If 6 sensors takes up all your code in a segment I'm betting you have a
    | coding problem that could be made more efficient with something like a
    state
    | machine.
    | I've written some pretty big programs with lots of subroutines and only
    run
    | out of memory in once.

    Same here...
    Even with very inefficient coding, I've only run out of code space once, and
    that was with 5 separate lookup tables and a fairly complex user interface
    with lots of Debugs. This was for a very complex project with 5 sensors, an
    LED display, autonomous decision making, and an interface to a data radio.
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-07 23:37
    OK, this is one without every single case (there are about 500
    possibilities of if statements which would be too much to jsut post
    here) but one can easily see how I'm running out of space. I
    realize that it is probably something that I am programming wrong.


    Thank you again.
    Mike.


    '{$STAMP BS2sx}
    DIRS = %1111111111000000

    svo con 0
    sync con 255
    pos var byte
    n24n con $43FD

    emergencyr VAR BIT
    emergencyl VAR BIT
    emergencyrr VAR BIT
    emergencyll VAR BIT

    sensor0 VAR BIT
    sensor1 VAR BIT
    sensor2 VAR BIT
    sensor3 VAR BIT
    sensor4 VAR BIT
    sensor5 VAR BIT

    right VAR BIT
    left VAR BIT
    inter VAR BIT

    image43 VAR BIT
    image32 VAR BIT
    image02 VAR BIT

    emergencyr = 0
    emergencyl = 0
    emergencyrr = 0
    emergencyll = 0

    sensors VAR BYTE

    sensor0 = 0
    sensor1 = 0
    sensor2 = 0
    sensor3 = 0
    sensor4 = 0
    sensor5 = 0

    right = 0
    left = 0
    inter = 0

    image43 = 0
    image32 = 0
    image02 = 0

    OUT8 = 0
    OUT9 = 0
    OUT10 = 0
    OUT11 = 0
    OUT12 = 0
    OUT13 = 0
    OUT14 = 0
    OUT15 = 0
    pos = 130
    serout 6,n24n,[noparse][[/noparse]sync,svo,pos]

    PAUSE 2000
    'OUT8 = 0
    'OUT9 = 0
    'OUT10 = 0
    'OUT11 = 0
    'OUT12 = 1
    'OUT13 = 0
    'OUT14 = 1
    'OUT15 = 0

    main:
    sensors.BIT0 = IN0
    sensors.BIT1 = IN1
    sensors.BIT2 = IN2
    sensors.BIT3 = IN3
    sensors.BIT4 = IN4
    sensors.BIT5 = IN5

    if (sensors = %00111111 AND emergencyr = 0 AND emergencyl = 0 AND
    emergencyrr = 0 AND emergencyll = 0) THEN goforward
    if (sensors = %00111110) THEN turnlefte
    if (sensors = %00111101 AND (emergencyl = 1 OR emergencyll = 1)) THEN
    turnlefte
    if (sensors = %00111011) THEN turnleft
    if (sensors = %00110111) THEN goforward
    if (sensors = %00101111) THEN turnright
    if (sensors = %00011111) THEN turnrighte
    if (sensors = %00111111 AND emergencyr = 1) THEN turnrighte
    if (sensors = %00111111 AND emergencyl = 1) THEN turnlefte
    if (sensors = %00111111 AND emergencyrr = 1) THEN turnright
    if (sensors = %00111111 AND emergencyll = 1) THEN turnleft
    if (sensors = %00000000) THEN stop1

    'Images

    if (sensors = %00010111 AND sensor3 = 1 AND left = 0 AND right = 0)
    THEN leftimage
    if (sensors = %00001111 AND sensor5 = 1 AND left = 0 AND right = 0)
    THEN leftimage
    if (sensors = %00101011 AND sensor2 = 1 AND left = 0 AND right = 0)
    THEN leftimage
    if (sensors = %00110011 AND sensor2 = 1 AND left = 0 AND right = 0)
    THEN leftimage
    if (sensors = %00110101 AND sensor1 = 1 AND left = 0 AND right = 0)
    THEN leftimage
    if (sensors = %00111010 AND sensor0 = 1 AND left = 0 AND right = 0)
    THEN image02f
    if (sensors = %00111001 AND image02 = 1 AND left = 0 AND right = 0)
    THEN leftimage
    if (sensors = %00110000 AND image02 = 1 AND left = 0 AND right = 0)
    THEN rightimage
    if (sensors = %00100111 AND sensor4 = 1 AND left = 0 AND right = 0)
    THEN image43f
    if (sensors = %00100001 AND image43 = 1 AND left = 0 AND right = 0)
    THEN leftimage
    if (sensors = %00000011 AND image43 = 1 AND left = 0 AND right = 0)
    THEN rightimage
    if (sensors = %00110011 AND sensor3 = 1 AND left = 0 AND right = 0)
    THEN image32f
    if (sensors = %00110001 AND image32 = 1 AND left = 0 AND right = 0)
    THEN leftimage
    if (sensors = %00100011 AND image32 = 1 AND left = 0 AND right = 0)
    THEN rightimage

    if (sensors = %00110101 AND sensor3 = 1 AND left = 0 AND right = 0)
    THEN rightimage
    if (sensors = %00111001 AND sensor1 = 1 AND left = 0 AND right = 0)
    THEN rightimage
    if (sensors = %00101011 AND sensor4 = 1 AND left = 0 AND right = 0)
    THEN rightimage
    if (sensors = %00010111 AND sensor5 = 1 AND left = 0 AND right = 0)
    THEN rightimage
    if (sensors = %00111010 AND sensor2 = 1 AND left = 0 AND right = 0)
    THEN rightimage
    if (sensors = %00111100 AND sensor1 = 1 AND left = 0 AND right = 0)
    THEN rightimage
    if (sensors = %00111100 AND sensor0 = 1 AND left = 0 AND right = 0)
    THEN rightimage

    if (sensors = %00001111 AND right = 1) THEN goright
    if (sensors = %00010111 AND right = 1) THEN goright
    if (sensors = %00011011 AND right = 1) THEN goright
    if (sensors = %00011101 AND right = 1) THEN goright
    if (sensors = %00011110 AND right = 1) THEN goright
    if (sensors = %00100111 AND right = 1) THEN goright
    if (sensors = %00101011 AND right = 1) THEN goright
    if (sensors = %00101100 AND right = 1) THEN goright
    if (sensors = %00101110 AND right = 1) THEN goright
    if (sensors = %00110011 AND right = 1) THEN goright
    if (sensors = %00110101 AND right = 1) THEN goright
    if (sensors = %00110110 AND right = 1) THEN goright
    if (sensors = %00111001 AND right = 1) THEN goright
    if (sensors = %00111010 AND right = 1) THEN goright
    if (sensors = %00111100 AND right = 1) THEN goright

    if (sensors = %00001111 AND left = 1) THEN goleft
    if (sensors = %00010111 AND left = 1) THEN goleft
    if (sensors = %00011011 AND left = 1) THEN goleft
    if (sensors = %00011101 AND left = 1) THEN goleft
    if (sensors = %00011110 AND left = 1) THEN goleft
    if (sensors = %00100111 AND left = 1) THEN goleft
    if (sensors = %00101011 AND left = 1) THEN goleft
    if (sensors = %00101100 AND left = 1) THEN goleft
    if (sensors = %00101110 AND left = 1) THEN goleft
    if (sensors = %00110011 AND left = 1) THEN goleft
    if (sensors = %00110101 AND left = 1) THEN goleft
    if (sensors = %00110110 AND left = 1) THEN goleft
    if (sensors = %00111001 AND left = 1) THEN goleft
    if (sensors = %00111010 AND left = 1) THEN goleft
    if (sensors = %00111100 AND left = 1) THEN goleft


    goto main

    goright:
    pos = 70
    serout 6,n24n,[noparse][[/noparse]sync,svo,pos]
    pause 600

    goto main

    goleft:
    pos = 150
    serout 6,n24n,[noparse][[/noparse]sync,svo,pos]
    pause 600

    goto main

    image02f:
    image02 = 1
    goto main

    image32f:
    image32 = 1
    goto main

    image43f:
    image43 = 1
    goto main

    stop1:
    OUT8 = 0
    OUT9 = 0
    OUT10 = 0
    OUT11 = 0
    OUT12 = 0
    OUT13 = 0
    OUT14 = 0
    OUT15 = 0
    pos = 130
    serout 6,n24n,[noparse][[/noparse]sync,svo,pos]
    emergencyr = 0
    emergencyl = 0
    emergencyrr = 0
    emergencyll = 0
    goto main

    goforward:
    'was 130
    pos =130
    serout 6,n24n,[noparse][[/noparse]sync,svo,pos]
    OUT8 = 0
    OUT9 = 0
    OUT10 = 0
    OUT11 = 0
    OUT12 = 1
    OUT13 = 0
    OUT14 = 1
    OUT15 = 0
    emergencyr = 0
    emergencyrr = 0
    emergencyl = 0
    emergencyll = 0
    sensor0 = 0
    sensor1 = 0
    sensor2 = 0
    sensor3 = 1
    sensor4 = 0
    sensor5 = 0
    if (inter = 1) THEN resetinter
    goto main

    resetinter:
    right = 0
    left = 0
    inter = 0
    goto main

    turnleft:
    'was on 150
    pos = 150
    serout 6,n24n,[noparse][[/noparse]sync,svo,pos]
    OUT8 = 1
    OUT9 = 0
    OUT10 = 1
    OUT11 = 0
    OUT12 = 0
    OUT13 = 0
    OUT14 = 1
    OUT15 = 0
    sensor0 = 0
    sensor1 = 0
    sensor2 = 1
    sensor3 = 0
    sensor4 = 0
    sensor5 = 0
    emergencyl = 0
    emergencyll = 1
    goto main

    turnlefte:
    'was 177
    pos = 190
    serout 6,n24n,[noparse][[/noparse]sync,svo,pos]
    OUT8 = 1
    OUT9 = 0
    OUT10 = 1
    OUT11 = 0
    OUT12 = 0
    OUT13 = 0
    OUT14 = 1
    OUT15 = 0
    emergencyl = 1
    emergencyll = 0
    if (IN1 = 0) THEN setsensor1
    if (IN0 = 0) THEN setsensor0
    goto main

    turnright:
    'was on 60
    pos = 70
    serout 6,n24n,[noparse][[/noparse]sync,svo,pos]
    OUT8 = 1
    OUT9 = 0
    OUT10 = 1
    OUT11 = 0
    OUT12 = 0
    OUT13 = 0
    OUT14 = 1
    OUT15 = 0
    sensor0 = 0
    sensor1 = 0
    sensor2 = 0
    sensor3 = 0
    sensor4 = 1
    sensor5 = 0
    emergencyrr = 1
    emergencyr = 0
    goto main

    turnrighte:
    'was 30
    pos = 50
    serout 6,n24n,[noparse][[/noparse]sync,svo,pos]
    OUT8 = 1
    OUT9 = 0
    OUT10 = 1
    OUT11 = 0
    OUT12 = 0
    OUT13 = 0
    OUT14 = 1
    OUT15 = 0
    sensor0 = 0
    sensor1 = 0
    sensor2 = 0
    sensor3 = 0
    sensor4 = 0
    sensor5 = 1
    emergencyr = 1
    emergencyrr = 0
    goto main

    rightimage:
    right = 1
    OUT8 = 0
    OUT9 = 0
    OUT10 = 0
    OUT11 = 0
    OUT12 = 0
    OUT13 = 0
    OUT14 = 0
    OUT15 = 1
    image43 = 0
    image32 = 0
    image02 = 0
    pause 2000
    goto main

    leftimage:
    left = 0
    pause 500
    OUT8 = 0
    OUT9 = 0
    OUT10 = 0
    OUT11 = 0
    OUT12 = 0
    OUT13 = 0
    OUT14 = 0
    OUT15 = 0
    image43 = 0
    image32 = 0
    image02 = 0
    pause 2000

    goto main

    setsensor1:
    sensor0 = 0
    sensor1 = 1
    sensor2 = 0
    sensor3 = 0
    sensor4 = 0
    sensor5 = 0
    goto main

    setsensor0:
    sensor0 = 1
    sensor1 = 0
    sensor2 = 0
    sensor3 = 0
    sensor4 = 0
    sensor5 = 0
    goto main




    --- In basicstamps@yahoogroups.com, smartdim@a... wrote:
    > Please post your code
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-08 02:22
    You have a TON of opportunity to trim your code. There are so many, I'm only
    going to list a couple.

    Your version:

    sensor0 VAR BIT
    sensor1 VAR BIT
    sensor2 VAR BIT
    sensor3 VAR BIT
    sensor4 VAR BIT
    sensor5 VAR BIT

    .. then later:

    sensor0 = 0
    sensor1 = 0
    sensor2 = 0
    sensor3 = 0
    sensor4 = 0
    sensor5 = 0

    Here's a way to save code:

    sensFlags VAR Byte
    sensor0 VAR sensFlags.Bit0
    sensor1 VAR sensFlags.Bit1
    sensor2 VAR sensFlags.Bit2
    sensor3 VAR sensFlags.Bit3
    sensor4 VAR sensFlags.Bit4
    sensor5 VAR sensFlags.Bit5

    .. then you can do this:

    sensFlags = 0

    In another case you're address all of the bits of OutH like this:

    OUT8 = 0
    OUT9 = 0
    OUT10 = 0
    OUT11 = 0
    OUT12 = 0
    OUT13 = 0
    OUT14 = 0
    OUT15 = 0

    When you could have done this:

    OutH = %00000000


    What I will STRONGLY recommend is picking up the April issue of Nuts & Volts
    magazine and read my column "Stamp Applications." The article this month is
    called "Thinking Like an Embedded Programmer" -- it specifically goes into
    memory manipulation and conservation tricks.

    -- Jon Williams
    -- Parallax

    In a message dated 4/7/2003 5:51:50 PM Central Standard Time,
    walker@e... writes:

    > OK, this is one without every single case (there are about 500
    > possibilities of if statements which would be too much to jsut post
    > here) but one can easily see how I'm running out of space. I
    > realize that it is probably something that I am programming wrong.



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-08 03:41

    Original Message
    From: "MBW" <walker@e...>


    | OK, this is one without every single case (there are about 500
    | possibilities of if statements which would be too much to jsut post
    | here) but one can easily see how I'm running out of space. I
    | realize that it is probably something that I am programming wrong.

    Well, I'm not sure how helpful I can be, but here goes...
    First off, try using the new Select...Case statement. I'm not sure if this
    will reduce actual size-on-chip, but it will at least make your code more
    compact and more readable.

    Secondly, you might try having an If-Then section for each sensor with a
    subsumption architecture. For example:
    If Sensor = On Then Take_Action
    where Take_Action is turn left, right, or whatever. Then, have a segment to
    analyze the results of each of these If-Then statements and determine which
    are the highest priority to determine which action will actually be taken
    for a given sensor input.
    More specifically, if you have a bump sensor and a GPS on your robot, your
    bump sensor could say "go backwards" while your GPS is saying "full speed
    ahead, Captain." You would want to give the bump sensor priority, and the
    ultimate action taken would be "go backwards."
    The problem with your present code as I see it is that you try to decide
    what to do for each possible combination of sensors. You should either give
    certain sensors priority, or find a way of merging the results of each
    sensor input to make the decision making much simpler. For instance, if you
    have a ring of ten IR sensors, you would simply determine which set of
    sensors indicate an object is present (say, right side sensors, left side
    sensors, etc.) rather than saying,
    If Sensor_Input = %0000000001 Then Take_Action1
    If Sensor_Input = %0000000011 Then Take_Action2
    If Sensor_Input = %0000000111 Then Take_Action3
    .
    .
    .
    If you had ten sensors you would have 2^10 If...Then statements (or is it
    10^2? I never can remember [noparse]:o[/noparse]) ).
    Sorry if this is not applicable in your particular case... if so, I guess
    you're SOL, unless Dr. Allen can light the way.

    - Robert
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-08 06:28
    Here is how I handle two I/R ranging sensors and an ultrasonic ranging
    sensor:

    '--- read sensors

    GOSUB Read_Right_IR 'get the distance from the right I/R sensor
    GOSUB Read_Left_IR 'get the distance from the left I/R sensor
    GOSUB Ping_Ultrasonic 'get the distance from the ultrasonic sensor

    '--- react to sensor readings

    Sensor_Status = 0 'reset the sensor status

    IF R_IR_Distance > R_IR_Threshold THEN Sensor_Status.BIT0 = 1 'if the
    right I/R sensor reading is greater than the threshold
    'set the right status flag

    IF L_IR_Distance > L_IR_Threshold THEN Sensor_Status.BIT1 = 1 'if the
    left I/R sensor reading is greater than the threshold
    'set the left status flag

    IF US_Distance > US_Threshold THEN Sensor_Status.Bit2 = 1 'if the
    ultrasonic sensor reading is greater than the
    'threshold set the ultrasonic status flag

    SELECT Sensor_Status 'process the sensor status flags

    CASE 0 'do this when no sensors triggered

    'DEBUG "No Sensors Triggered",CR

    CASE 1 'do this when right sensor triggered

    'DEBUG "Right Sensor Triggered",CR

    CASE 2 'do this when front sensor triggered

    'DEBUG "Left (Forward) Sensor Triggered",CR


    CASE 3 'do this when both sensors triggered

    'DEBUG "Left (Forward) & Right Sensor Triggered",CR

    CASE 4

    'DEBUG "Ultrasonic sensor out of range",CR

    CASE ELSE

    DEBUG "Illegal sensor readings",CR 'otherwise don't do anything

    ENDSELECT

    Original Message

    > | OK, this is one without every single case (there are about 500
    > | possibilities of if statements which would be too much to jsut post
    > | here) but one can easily see how I'm running out of space. I
    > | realize that it is probably something that I am programming wrong.
    >
    > Well, I'm not sure how helpful I can be, but here goes...
    > First off, try using the new Select...Case statement. I'm not sure if this
    > will reduce actual size-on-chip, but it will at least make your code more
    > compact and more readable.
    >
    > Secondly, you might try having an If-Then section for each sensor with a
    > subsumption architecture. For example:
    > If Sensor = On Then Take_Action
    > where Take_Action is turn left, right, or whatever. Then, have a segment
    to
    > analyze the results of each of these If-Then statements and determine
    which
    > are the highest priority to determine which action will actually be taken
    > for a given sensor input.
    > More specifically, if you have a bump sensor and a GPS on your robot, your
    > bump sensor could say "go backwards" while your GPS is saying "full speed
    > ahead, Captain." You would want to give the bump sensor priority, and the
    > ultimate action taken would be "go backwards."
    > The problem with your present code as I see it is that you try to decide
    > what to do for each possible combination of sensors. You should either
    give
    > certain sensors priority, or find a way of merging the results of each
    > sensor input to make the decision making much simpler. For instance, if
    you
    > have a ring of ten IR sensors, you would simply determine which set of
    > sensors indicate an object is present (say, right side sensors, left side
    > sensors, etc.) rather than saying,
    > If Sensor_Input = %0000000001 Then Take_Action1
    > If Sensor_Input = %0000000011 Then Take_Action2
    > If Sensor_Input = %0000000111 Then Take_Action3
    > .
    > .
    > .
    > If you had ten sensors you would have 2^10 If...Then statements (or is it
    > 10^2? I never can remember [noparse]:o[/noparse]) ).
    > Sorry if this is not applicable in your particular case... if so, I guess
    > you're SOL, unless Dr. Allen can light the way.
Sign In or Register to comment.