Let's Make Robots!

Clean navigation using IR sensor

Anyone willing to give me a hand with this code please feel free to jump right in.

I have spent any hours trying to get this to work. I sure have gotten closer but the bot seems to get stuck n reverse for whatever reason. He will stay in reverse untill i bring my hand close to the sensor and then move it away very quickly.

He then continues forward. Sometimes it seems like he wants to turn toward the object he sees

Picaxe 28x1 with sharp GP2D12

I have made many changes to Fritsl's code, Some changes I understood and others I did not.



g_bot.bas722 bytes

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Pulling out hair here


If you break it up into chunks, it's a lot easier. It's kind of like eating an elephant, you do it a spoonful at a time.  Decide what you want the bot to do, and then break it down into subroutines. At first don't try to be overly efficient, just do it. We all write crappy code in the beginning, some of my first Comp Sci programs were really bad in form, but they worked. Remember to comment as you go. I still comment every line, it helps later to figure out where my head was at that time. 

 Start off with the basic stuff and go from there. Get the bot to move, turn and such, before integrating sensors.

Have fun, don't stress too much. 

If I knew how and where to break the code Up I would but I still get stuck and frustrated and don't understand etc. etc, etc.

I am writing code for some other simple projects from scratch. For these I have all the time in the world so I am not stressed there.
Heck I could just go out and buy an SRF05 and my problems would be over but The SRF does not feature (YET)
I have started with the basics and have gotten my robot to move and perform very well, now I am working on stage 2 of the "BIGGER PICTURE" and I don't have much time to get it right.

Oh and where I come from we eat the elephants live with one bite at a time, Dangerous, but interesting and a lot faster.
He is also still a lot fresher when we get to the last bits (make of that what you will)

This is exactly what I have been saying and why the idea of "jumping ahead" drives me so nuts. Just as an example, Walter has a folder of nearly 50 files with each pertaining to each of his sub-systems. I know for damn fact that each one works individually and I know why each one works. When I got to building Walter's "main" code, I not only had all the building blocks ready to go, but they were all bug-free and most of my code writing was done using cut and paste.

I guess this whole thing just erks me because  I worked my ass off to learn to code... Walter (the sum total of all i have learned) has taken me over a year. Even my questions about this very code (directed to Frits) were about very specific parts of his code instead of again, "I changed something, I don't know what I did, fix it for me".

Ok so here is the thing.

Chris, I am sorry.

For some reason I was not going to listen to your suggestion. Who listens to chicken farmers on robotics anyway.

I have just completed reading all your posts including Walter three point oh my god.

You will be pleased to know that I have scraped the old code and have started from scratch.

Not because I cant do it but because I have a friend that really knows what he is doing.

Thank you Chris

Now be prepared for questions, Lots of them ;-)

Believe me when i say I am now a follower and a student of yours

AND I bet you will be featuring in the "BIGGER PICTURE"

Sorry again for the wise cracks. I should have gotten to know you before shooting crap at you.

Only one other man I know who produces nothing less than the best and he is the man that made me.


Yup. It was surely Scraped.
Just what is it you are trying to say here dude?

Like I said I hear ya.

Im different sorry for erking you.

But I am having fun. Learning and erking ;-)

Just so you know, a quick glance at the code that you have, it shows 3 variables that seem to be defined incorrectly...or at least with the intention of holding a different value.

head = w1 this is a two byte value but may not need to be.

remember = b1 should be fine

 range = b2 this will run into issues based on how the variables are overlapped(see below) this is also stated as a 16bit var when it's using an 8bit var b2. If you code for a larger value, this will fail. If you are using the sharp IR range finder(analogue)this can be read into an 8bit var(adc).

 Also as someone else pointed out the values overlap, which is never a good thing unless you want random data.

w1 which overlaps with b2 as w1=b2:b3  


Further down in the cade a case test is done using the raw var b1(ie, not it's label) this can cause issues if you decide to change the variables so take note, always use the label for a variable if it's defined...thats the point of the label. That way if I change b1 to b0 everything should still work.


1 Question, is have you run this in the simulator to see how it works. this would be the best bet to start understanding how things are branched and what happens when variables are updated throughout the code. Since it's interactive, you can step through the code and see what each part is doing. you can also change the speed at which it is running. 


Just some thoughts from initially looking at the code. 

Like I said I am well aware that my variables are all wrong I can see that right away.
The reason there are there is because that is the best or closet i can get to the desired performance.

I fooled with b1, b2 and b3

or b1, b2 w3  and any combination and guess I could thingk of.

I KNOW it aint right but I dont know why. Also dont know why its best performance is with screwed up code.

I hsave been using the labels as you suggest. I just fooled with it in the select case

As for select case, I am struggling to understand what all those numbers etc mean

Yes I have been playing with the simulator but I get confuzed there too.