Clean navigation using IR sensor

I hear you on all that

I hear you on all that chris. Thing is there is a right way and a wrong way to do everything, I usually take the wrong route first. Part of my stubborn nature.
The best thing about the internet is I get to do it my way. I am not going to listen to you yet, I am going to do it my way :stuck_out_tongue:

That said, Why dont you put some of that experience of yours to use and help me figure this thing out. Time to get yourself into the "BIGGER PICTURE".

Nope! Like I said I will do

Nope! Like I said I will do it my way. I dont have one of those super brain thingys. I just got a normal one 
 hmm well maybe not so normal. But obviously not the same as yours.

Lets not waste cyberspace on drivel.

A man With an answer WOOT!

Now this is the kinda answer I was looking for.

I had been fooling with those values, read somewhere about not using w with b etc. I had tried b1 b2 and w1 and nothing worked.

The best performance I got was when I had b1 b1 and w1. I think your answer is answering a few of the questions I was asking myself.

Thanks hundreds for the effort.
I am off to fool with this for a bit.

I am sure you will be a part of the "BIGGER PICTURE"

You do what you want

Hey Dude! You do what you want but keep playing with those values and the robot might end up in your ASS! Like I said "Dangerous".

No No No I never let the bot
No No No I never let the bot anywhere near there O_o

Update

Ok so I tried your suggestions but with the code as you have it above It just goes crazy and nothng works.

If I leave the pulse as you have it and keep the 2 b1’s it works like before.

Or as I have it now it works better but but still when the robot senses something on its left it wants to turn to its left.

If it senses something on its right it turns to its left which is right. The motors are wired correctly acording to my code.

Here is the code as I have it now

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

Pulse is still the same as you have it above

Edit; I have updatd the .bas file above

Dude! Are you still trying to solve this?
Dude! Are you still trying to solve this? Just leave that navigation code alone or the “BIGGER PICTURE” will be you with a “BIGGER ASS” when that robot gets stuck in it. I won’t warn you anymore!

I think it better that you
I think it better that you keep my A__ out of your mouth

Just so you know, a quick

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.

Coding is easy is small steps

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.

Bingo! MechGeek hit the nail on the head

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”.

Like I said I hear ya.Im

Like I said I hear ya.

Im different sorry for erking you.

But I am having fun. Learning and erking :wink:

As an fyi, and as people

As an fyi, and as people have pointed out, the values of w1 and b2 are overwriting every time you get an adc read. IE, range = value x, and that ends up setting the head value to the same thing. This is a problem and needs to be fixed. I would suggest reading my post later on that outlines this issue as well as the fact that you also have variables(b1) that have labels set for them but aren’t using these labels for all instances of the variables. This is something important to clean code.

changing the word variable to a byte variable for storage shouldn’t affect the data of that storage since it’s a byte value anyway, but since it was overlapping, it had another side affect.

Anyway, you can verify the issue above by stepping through the simulator and using 75 for the value of adc1. I’ve tried it and watched it reset the value incorrectly.

As for the side affect, you can get into an infinite loop in one case that I looked at where a variable() is set to a value that never gets tested except for once


The case is in the ForwardRight_middle function where the following event takes place.

if head > 159 and head < Forward Right then

head at one point could go up to 164. when it does, it continues to the next line where +15 is added. This sets head up to 179 now. if you step through, you will see where the loop comes into play. IE head is >159 and head is also > ForwardRight. It then goes to endif and repeats
fixing this may not necessarily be setting the value of fowardRight to something higher
but well, I didn’t go that far
You’d have to debug that yourself
 :smiley: this is the fun part of working with others code


He gave an answer based on

He gave an answer based on guess
you can’t guess when you write code unless you like random not workingness


Readadc will give you an 8bit value even though the 28x can read a 10bit value
as the manual states
which you should be reading to understand and figure these things out
is that the 10bit value is rounded to an 8bit value unless you use the readadc10. a second thing, if it were reading a 10bit value, your bot would be doing some very radical things since you’d be working with a range from 0 to 1024
This code doesn’t appear to account for that.

Using w1 or w anything is a waste of a byte which, from looking at the code, has caused issues with variable overlap.

 

YES DUDE! I am still trying

YES DUDE! I am still trying to solve this.
Now if you would just shut up and give your brain a chance you could help me along at breakneck speed.
I am working to a deadline here and posting a bunch of crap here is only going to slow me down.

I need to get stuff done and done in a hurry or it all falls flat. Now I agree that I am going to be very slow at learning this as it all takes time as there is a lot to it. Believe me I will get there but “THE BIGGER” picture is not going to wait for me to get there.

And Chris? it wont take me near a year to learn it and a whole lot more.

What I need right now is positive input from as many members as possible. Please don’t comment here unless you have positive substantial input. I am not a jerk and I know I can learn a lot from each one of you expressing any of your views, lectures and instruction on "how it should be done.
But right now a shortage of time does not allow for this.

My project idea is secretive at this point in time as I am still designing planning, and documenting.
When it is done it will be a massive leap for LMR, and will boost membership with members that will stay and will be active

Fritsl Hope you are watching close as I will be needing your input for some info soon.

Claudia and OddBot you will be needed as well.

Those of you willing to help me? I love you and would love to have you in the "BIGGER PICTURE.

If I knew how and where to

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)

Like I said I am well aware

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.

 

**Hey Man! If you’re planning on leaving **
Hey Man! If you’re planning on leaving this site you don’t need to keep a secret or input from all members, you can just GO! That will boost membership with members that will stay and will be active, resulting in a massive leap for LMR


Come on Zeit

I have no intentions of leaving this site for many years as I have just found it.

Secretive means I dont have all the ins and outs worked out yet. and As I said this project is entirly for LMR

I made no mention about leaving. I get the feeling that perhaps you would like me to leave.

One other thing, You been here a while. Why dont you show us some of your work???

Thanks for this too. It goes

Thanks for this too. It goes with a lot of what I expeted that problems could come from.

 

Lemme go see