26 variable limit

Perhaps I’m missing the obvious, but HOW do I write comands to motors, keep a count, etc. etc. all in 26 variables?:confused: I thought that byte vs nib might be the answer, but it isn’t.

I’m trying to do the “outer” counting loop for the 15 seconds of autonomous mode. I have another counter for putting the robot through its paces.

Any help will be greatly appreciated.


One of the nice features of PBASIC 2.5 if you’re using the new code is that they make it easier to use the scratchpad RAM. Scratchpad RAM is a place where you can store numbers and stuff, but you can’t do operations to it.

Read [location], variablename
Write [location], variablename
[location] = 0-62 (bytes)
See page 7 of the above document for improvements, and read the Parallax Manual for further description.

Other than that, try to strip down your variable requirements to a bare minimum.

I hope that helps, I’m having trouble understanding what you mean… please try to explain again.

goto www.first-codex.net

I love their site!

I’m the real starter of this thread. I wasn’t registered for the forums, so one of my students allowed me to use his login just to get started.

I’ve reluctantly taken on the role of programmer … my experience has been in FORTRAN and I’m not used to being limited in the number of variables that can be declared.

I need at least 4 variables in order to control the robot in autonomous mode. That part is working fine. Now I want to add to the program in order to make the switch from autonomous mode to competition mode and I need to add more variables to the list.

so, my thoughts…please be patient, I didn’t look seriously at PBasic until last Monday.

  1. Are there any variables that are not used in autonomous mode that could be declared later when competition mode begins?
  2. I need to use delta-t and the program doesn’t recognize it unless I put it in the list, even though it is in the list of constants.

im not completely sure but i think that the memory is limited to 26 bytes not 26 variables. If possible i would try using smaller data types for your variables. Also look into the scratchpad ram.

There’s a few little tricks to stay within 26-bytes. Here’s a quick list:

  1. Use the smallest size possible. Words give 0-65535, Bytes are 0-255, Nibs are 0-15, and bits are 0-1.
  2. Reuse variables whenever possible. For example, you said you needed two counter loops–one during auto mode, the other regular. Is there any reason why you can’t use the same variable for both?
  3. Strip down your SERIN. Only import the stuff you actually use, making sure to update the constants accordingly. For example, the default code imports the X and Y axis for all the joysticks. If you don’t use them, get rid of them. Also, just removing them from SERIN doesn’t undeclare them. You need to find that section of the code.
  4. As a last resort, use scratchpad. It can get to be very messy, very fast but it can also save you a lot of variable space if done correctly.

To answer a few of your specific questions:
Make sure delta_t is in the SERIN statement in the proper place
You cannot ever “undeclare” a variable. VAR, CON, and DATA are all compile-time directives that can be placed ANYWHERE in your source code and have the same effect.

One thing to think about is putting the autonomous code in a seperate program, which has its own 26 bytes. To do this, split your programs up, then add “,[second program]” (or something like that) to the stamp directive of the first (autonomous) program. If you need to transfer some of the variables over, keep in mind that when you switch program, the data is not acutally destroyed, only the names are. As an extreme example, if you declared everything in the second program (perhaps using different names) in the same order as the first, you would have all of the same data in all of the same places. The scratch pad also transfers perfectly across programs.

could you please elabotate on this multi-program thing

you can find all the info for multibank codehere . Its the innovation First White Papers. It’s really simple to do.

Here is our program from last year using multiple processor slots (Open Pegasus and the rest open automatically)


However REMEMBER you don’t get another 26 bytes for each slot, it is the same memory, if you call it something different in the next slot you are overriding something in the current slot and I am not sure there is an easy way to find out which variable will overwrite which variable.