Is there a limit to the depth of library nesting?

Hello All

I have a chain of libraries which I have attempted to implement as encapulated objects...

Servo within my own ServoMotor Within my own DriveControl within my own Navigation library.

Now If I create a test project to put DriveControl through its paces the wheels (which are modified servos) turn in the required directions, but if I put the navigation library through it's paces when it calls DriveControl methods such as goForeward or any other, the motors do not turn :(

I have since reduced the level of encapsulation, but I was wondering if there was a limit?

Cheers

I have since reduced the level of encapsulation, but I was wondering if there was a limit?

The only limit is the available memory (all three kinds) on the Arduino that the sketch is for.

You'd need to post the code to get some real idea what the problem was.

Hi Paul

I seem to have run into the memory issue before. Although the compiled program is less than a third of the available space for my given chip, it seems I have had weird errors due to memorey where strings are placed overflowing…

Is it possible to point me towards a source that expalins the various types of memory and their usages?

Cheers

The Hardware tab on the main page has details about the amount of memory available on each Arduino.

The largest value shown is where the sketch code goes. SRAM is where variables (and literals) are stored. EEPROM is user (programmer) readable/writable memory.

t seems I have had weird errors due to memorey where strings are placed overflowing…

Although you may think of things like strings as being constant, they are actually stored in RAM (unless you explicitly store them in PROGMEM and handle them as such), so if you have a few strings and maybe a few large arrays, you can very quickly run out of RAM.

Like the man said, we need to see code.

Paul, AWOL thanks for your time.

I am at work so the code is not handy... It is fairly large so does one really want to put it here?

Anyway, If I am implementing each library as one or more objects Navigation --contains a DriveControl (which contains 2 servoMotors each of which contain 1 servo) --contains a servo object (neck for sensor) --contains a IR sensor object (courtesy of some Distance.h lib I found somewhere)

Could it be the variable memory (SRAM) is running out then? (Atmega328 => SRAM = 2K... not much really)

I wonder if it is possible to determine the size of each object/variable? Can anyone tell me how?

Cheers

The RAM size of an object is just the sum of the sizes of the class variables. Do you have a lot of debug strings?

AWOL

I did have a lot of debug strings, although I have commented most of them out.

I will try by first commenting all the strings out where not absolutely neccesary and see what happens then.

I did have a strange situation where for a while only 1 ServoMotor was turning and then later none were, perhaps after I added some debug messages.

After trimming them down again, the one motor was running again, but not the other.

Will give feedback...

Cheers for your advice. Obviously a lot more to learn than there initially seems to be. Never ever considered the fact that variables needed to be stored somewhere...