Clean navigation using IR sensor

g_bot.bas (722Bytes)

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.

 

 

https://www.youtube.com/watch?v=bc-H8OS_y5U

Did you add a capacitor

Did you add a capacitor (soldered as close as possible to the sensor) to the sensor? It will help clean up any spikes in the supply.

Cap

What size cap and can you be more specific as to which wires I should solder it to?

Would that be red and black and should I add it right at the sensor?

A 10uF (10 microfarad)

A 10uF (10 microfarad) capacitor between Power and Ground, and attached directly to the sensor would be best. Be careful that polarity is correct (Ground to ground, power to power).

Here’s a good article, may

Here’s a good article, may help you:

http://www.robotroom.com/DistanceSensor3.html

Keep the cap, helps remove
Keep the cap, helps remove voltage spikes.

I dont have a 10 uf cap,

I dont have a 10 uf cap, will a 0.1uf work.

I cant profess to understand everything on that page.

The 2nd graph shows use with
The 2nd graph shows use with a 0.1uf capacitor, and shows a significantly reduced voltage spike from the sensor, and is much better than no capacitor.

Heck I dont understand
Heck I dont understand enough yet to write my own

Well, it is partially
Well, it is partially working, which is better than not working :slight_smile:

Range / Head

 

I am no PICAXE expert, but you seem to have Head and Range set to the same memory location. I should imagine this is causing some problems.

 

I note in Fritsl’s original code he has:

symbol head = b1
symbol range = w1 ’ 16 bit word variable for range

but you have:

symbol head = b1
symbol range = b1

 

That just shows you how

That just shows you how little i understand the code.

I did think of that but when I changed w1 to b1 things did improve.

 

Comlex

To me the code does seem quite complex - it is quite hard to tell what behavior it is trying to achieve.

Then again, sometimes quirky code generates quirky behavior which is better than what was intended!

If you are having trouble with the code then I suggest starting with something really simple.

For example, just have your robot drive forward (with sensor pointing forward) until it reaches a wall and then have it stop.

Question…
If you can’t figure out how to write your own code, how in the world do you think you can figure out and modify someone else’s code? I’m not sayin’… I’m just sayin’.

You can call it lysdexia,

You can call it lysdexia, call it scatterbrain, call it difficult student, call it what you will.

The same way I got through part one I guess. I did write my own code for part one but would never have been able too without the original code.

I have a problem reading. I have read through the manuals and they are all the paper matter that I read. Its still all a fog to me.
I will get there in time hey, but no harm in trying to get some hand outs from fellow LMRtians. <–(you know I didn’t mean it that way:)

Truth is I have started on my own code but am not getting far with it yet so I decided I have to get Fritsl’s code working with the IR sensor.

At the end in the “BIGGER PICTURE” I will be using an SRF05 but I wont go there till I know what I am working with now.

Anyone contributing will be part of the "BIGGER PICTURE"
What is the “BIGGER PICTURE” you ask?

Stick around to find out :wink:

Thanks for commenting Chris, I have read through most of your posts, comments and projects and have gotten much inspiration from your work.
Thank you

All variables are b1?

It would appear to me that you have 3 vaiables - head, range and puls all set to the same actual variable space (b1). You are then comparing them so obviously the comparison sees equallity. Try setting them to seperate variables, for example -

head b1, range b2, puls b3.

 

It seems a common problem with limited resources to overuse things like this. Another issue with the PICAXE is that the word variables are created by using two byte variables so you shouldn’t use b1 and w1 together for example.

 

Hope this will shed some light on your problem.

 

PeteH

Oh come on ctc, some of the
Oh come on ctc, some of the best ways to learn is by understanding what other people have done…as you gain your own skills you usually end up with an Oh Wow moment. :slight_smile:

Byte / Word overlap

Oooh, good point about the Words and Bytes overlapping.

w0 consists of b0 and b1

w1 consists of b2 and b3, I think.



Puls is a subroutine which populates the range variable from the ADC. Depending on the PICAXE chip, I think the ADC resolution is 10bits? So this needs to be a Word.



Try this, to avoid the overlaps:


symbol head = b0 'Which way the servo & sensor is currently looking
symbol Remember = b1 ’ Temorary variable just used in routines and loops
symbol range = w1 '16 bit word variable for range

Also instead of your code:

puls:
readadc 1, b1
pause 25
return

make sure to use this…


puls:
readadc 1, range
pause 25
Return

Look, all I’m sayin’…

I’m just saying that I tried and tried and tried and tried to modify this very code and failed and failed and failed. I stabbed away at it randomly and managed to do and undo (without knowing what I was doing and undoing). Then I started writing my own code… and it took forever! I started with a simple code for the motors (F,B,R,L) then one for the sonar etc. --each one being just a few lines long. In doing this slow, step-by-step study of each “sub-system” I eventually got to a point where I could interperate code enough to know what was going on in someone else’s code and ONLY THEN be able to modify it.

Now, reading other people’s code, changing it and learning is great, period. But think about this: "I don’t understand code, but I used someone else’s code, changed “something” or many “somethings” now it doesn’t work --what did I do?"

I simply feel that this is one of those questions where we could sit here for months throwing out answers, “it could be this, it could be this, it could be this, it could be this.” I also think this falls into the catagory of “I know nothing of step 1, 2 or 3 and I am asking about step 47”

I mean no disrespect, I just think this problem/ question might be a bit broad.

Chris The Carpenter Is Right!
I agree with Chris The Carpenter. Using your own Super Brain will get you to the top. I too have tampered with Frits’ code and can tell you that it is Dangerous and can cause serious bodily injury! So leave it alone and write your own…