Shop OBEX P1 Docs P2 Docs Learn Events
Out of Variable Space ??!! — Parallax Forums

Out of Variable Space ??!!

HatemHatem Posts: 20
edited 2008-03-26 00:00 in BASIC Stamp
Hello everyone. I am trying to write a code which will have my·Boe-Bot navigate to a desired point or a predetermined path using the Ping)), IR Sensors, and HM55B Compass. I am still in the process of writing the code and I have a problem with the one of the variables. It keeps telling me: "Out of Variable Space". What shall I do to fix this problem?

Comments

  • Lee HarkerLee Harker Posts: 104
    edited 2008-03-23 02:03
    Hatem,

    Most programs have ways in which you can·optimize the code to use less space. If you could post your program, maybe someone can see a way to help.
  • HatemHatem Posts: 20
    edited 2008-03-23 02:14
    This is the code i am having trouble with.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-03-23 02:46
    Hatem said...
    I have a problem with the one of the variables. It keeps telling me: "Out of Variable Space".
    Actually, it's not one of the variables that's a problem; it's telling you that you've run out of RAM, you've burned used it up·with all of the VARs preceding it.· So, you don't have room enough for --
    val          VAR  Word
    axisOffset   VAR  angle  [color=red]'NO! -- must be: bit, nib, byte, word[/color]
    turnDir      VAR  Byte
    

    Post Edit·-- The solution is to make some of your VARs do double-duty.

    Post Edited (PJ Allen) : 3/23/2008 4:05:37 AM GMT
  • HatemHatem Posts: 20
    edited 2008-03-23 05:11
    I am not exactly sure how to make a Variable do double-duty. Do you have a simple example that best explain it to me? Thanks
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-03-23 05:39
    In other words, one or more of your variables will have·to serve·for more than one·purpose.· For instance,·there could be·a VAR byte which might be used during an I-R operation, but it could also be used for a Ping operation (because I can't do both at once anyway.)
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-23 05:58
    Look in the index of the Parallax Basic Stamp Manual under "alias". This is what they call a variable declaration that defines a new name for another already declared variable location. You basically need to use one variable for several things. It works only when variables are use temporarily in one part of a program, maybe another variable is used in another part of a program, and they don't retain a value outside of those parts of the program, so the same variable can be used for two different purposes at different times. For convenience and easier understanding you can have several names for the same variable.

    You can also use less than a full byte for some variables. A nibble is a 4 bit variable and you can declare a variable as a single bit if that's useful.

    You can also use a word in one part of a program and use the same locations as two separate bytes or one byte and two nibbles, etc.

    Essentially, you have only 26 bytes of variables and you have to reuse the space as much as you can for complex programs to fit in the Stamp.
  • HatemHatem Posts: 20
    edited 2008-03-23 17:34
    Thanks Mike for the info. It helped allot by reading. My big question is can I write a navigation code to my Boe-Bot using only IR sensors and Ping)) only or I must include the compass to enhance the navigation process. All what I have to do is the following:

    1) The Boe-Bot will start moving forward for an about 2 meters. Then it will turn left for about 2 meters. Then it must turn right for about 4 meters. Then turn left again for about 2 meters. Then it must stop.
    2) If there is an object on the way, the Boe-Bot must avoid colliding with it, and then it must continue on its original path.

    I was thinking on using the standard IR routine with modified subroutines added in the IF statements. For example, if the Boe-Bot detected an object on the left side, it will go to subroutine named "Turn_Right". In this subroutine, the Boe-Bot will turn right, move forward for about 50 cm, then turn left for another 50 cm then another left for 50 cm, then turn right and resume the original course. Basically, it moved in a square shape around the object.

    I hope you do understand the whole picture I am trying to explain
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-23 18:08
    The IR sensors and the PING are useful for object avoidance. They can also be used to detect landmark objects known to the BoeBot like walls and furniture and that can be used to locate the BoeBot on some kind of internal map. There's no other absolute position markers and the BoeBot has no good way of knowing where it is otherwise. "Dead reckoning" doesn't work because the BoeBot doesn't have good information about how far or fast it's moving. Trying to control the wheel motor speed is not very precise and the wheels can slip anyway. A compass can give the BoeBot additional information on its approximate heading.

    One of the things that can help is to actually measure the speed or the distance covered in a specific period of time (and convert to speed) at several different servo control pulse widths for each of the servos (because they're unlikely to be the same) and define these as constants in your program. That way you will have some confidence that you can make the BoeBot go an approximate known distance.
  • HatemHatem Posts: 20
    edited 2008-03-24 00:36
    That is a good idea Mike, but I am not exactly sure how to get the bot to use the compass data to go back on its original track. Do I need to have the bot obtain the angle (relative to north) at every turning point and when it senses an object and go around it, then it will recall that angle, drive the servos by the angle until it is on track again and resume on original track? Is this a good approach or you think there is a better, simpler way to get the task accomplished.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-24 01:08
    I was thinking more of using the compass reading to verify the heading of the BOT. In other words, I'd have a subroutine to read the compass and use it any time after the BOT has turned. If the BOT isn't within at least 30 degrees of where it should be, turn the BOT a little in the appropriate direction and try again. Since the BOT should be going on paths 90 degrees to each other, this should be easy.
  • HatemHatem Posts: 20
    edited 2008-03-25 18:18
    Hello Mike .. I modified a program I had and the Bot is not doing anything. It started by scanning around using ping and then nothing. I tried to figure out what is wrong but I couldn't. Can you find out what is wrong?
  • phil kennyphil kenny Posts: 233
    edited 2008-03-25 19:24
    When code gets hung up, you need to add Debug statements at various points
    in the program to pinpoint the problem.

    I'm guessing that it is in the DO LOOP in your Get_Angle subroutine.

    For a start, I'd modify that section of the code to read:
    DO                                         ' Status flag checking loop
        HIGH En: LOW En                          ' Measurement status command
        SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Report\4]
        SHIFTIN  DinDout,clk,MSBPOST,[noparse][[/noparse]Status\4]  ' Get Status
    DEBUG HEX Status, CR
    index = index + 1
      LOOP UNTIL status = Ready                  ' Exit loop when status is ready
    



    You will also have to add
    index          VAR      word  'Temporary  counter for Get_Angle routine
    



    Holding the BOEBOT off the ground will let you see the DEBUG screen.

    If debugging the code is needed when the PC isn't connected, you could also
    add an LED that is turned on when you begin to test for Status and the Status indicates READY.
    Then turn the LED off after it becomes ready. A PAUSE 1000 will let you see if it becomes ready
    right away.

    phil
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-25 19:28
    This is much too complicated for me to debug for you, particularly without the original version at hand. I suggest you start with whatever working version you have, then add a little bit at a time, each time making sure it still works and using DEBUG to make sure that any stored data is correct. Problems like this usually are due to the new stuff added and the changes along the way.
  • HatemHatem Posts: 20
    edited 2008-03-26 00:00
    Thanks Phil and Mike, I will try to work on it more and then I can add the required path like We (Mike and I) settled on.
Sign In or Register to comment.