Society of Robots - Robot Forum

Software => Software => Topic started by: tonto2k on July 22, 2009, 08:18:27 AM

Title: Wavefront BASIC question for Picaxe microcontroller
Post by: tonto2k on July 22, 2009, 08:18:27 AM
Hi Everyone :)

I found this web site through instructables.com which explained about wavefront propagation.

I am trying to code a robot which will navigate through an 6 x 6 squares. I am using the code from http://www.societyofrobots.com/robotforum/index.php?topic=5831.0 and converting it into picaxe basic.

I can understand all of it except one section:

    Dim map(,) As Integer = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {255, 255, 255, 255, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}

Could you please help me and explain if 'map' is an integer, or is it (,) that is the integer? or BOTH ? ! ?

I am used to picaxe basic and I would define map as symbol map = 20 or whatever. Also, are all the numbers in brackets a horizontal representation of the map itself ? and if so why are the middle numbers 255 ? (a wall?)

I am guessing that each number is a memory location on the micro-controller? if someone could clear this up for me it would be a great help :)
Title: Re: Wavefront BASIC question for Picaxe microcontroller
Post by: Admin on August 13, 2009, 10:32:14 AM
That variable is a matrix of unsigned ints. If you look at the comments in my original wavefront C code, you'll find definitions of all the variables.
Title: Re: Wavefront BASIC question for Picaxe microcontroller
Post by: Ro-Bot-X on August 13, 2009, 07:14:25 PM
I have maybe a stupid question: why people use ints instead of bytes when they don't use values greater than 255? I thought that an int is processed as 2 bytes, a high byte and a low byte. So why waste processing time if not needed? It will also take a lot more memory to store a map of ints, be it signed or unsigned. I would like a map of nibbles (4 bits), I can store enough info with that, don't even need a full byte. So what's the deal? Can someone explain this to me? Am I too paranoic?

Thanks!
Title: Re: Wavefront BASIC question for Picaxe microcontroller
Post by: Admin on August 14, 2009, 06:47:24 AM
Hmmmm I think an email Webbot sent me recently might help answer your question . . .

Quote
> should we use 'unsigned long int' instead of
> 'uint16_t'? The latter might be harder for a beginner to understand.

Welcome to the biggest issue in C and many other programming languages except Pascal !!! The original description of an 'int' is that it was a whole number whose bitcount was the same as the width of the data bus. So for an 8 bit bus it was 0..255 (or -128 to +127) but for a 16 bit bus was 0...65535 or (-32768 to +32768). My experience is that when you want to store a number then you know what value range it is within and it has absolutelty nothing to do with whether you have an 8, 16, or 32 bit bus. So the original C definition required you to know what processor you were using - move your program to another cpu and stuff would no longer work - which is rubbish.
If I know that a value will be between 0 and 100 then I know it needs 8 bits. So uint_8t will do it for me across all platforms. Whereas if if use 'unsigned short int' then what does this mean? Move my program to a 32 bit processor and all has changed.
So you mention 'unsigned long int' as being the equivalent of the 16 bit 'uint16_t' - but I think you are wrong. I think an 'unsigned long int' is probably 32 bits in size - and so your resultant code will be bigger.
So my nomenclature (which is also supported by AVRlib) is to define your vars according to how big the number they need to hold - rather than being based on the arbitrary data bus bit width.
BUT at the end of the day: if the two are the same then you wont get compile/runtime errors. ie my 'unit8_t' can hold an unsigned 8 bit number from 0-255 and if an 'unsigned short' approximates to the same thing then all will be ok.
So my defintions are more based on the size of the number you want to hold, vs the generic terms like 'signed short' which depend on the compiler and processor. And so are therefore pretty useless as migrating to a 32 bit architecture will mean that your code is either full of bugs, or at least bigger than it needs to be whereas mine will continue to be as complex and as large as it needs to be.
Sumary: using stuff like 'signed long' in C is complete trash !!!

More useful info here (read it all):
http://en.wikipedia.org/wiki/Integer_(computer_science)