How to build your first robot - Part II - navigation
| Attachment | Size |
|---|---|
| clean_navigation.BAS | 6.17 KB |
This is Part II of How to build your first robot - tutorial.
you can just take the cool navigation-code in here and have fun with it, or you can follow the whole instruction, or the parts that you like. I try to make it as general and open as possible.
Here is part III of this tutorial - I recomend that you browse this as well!
Progress:
You have made a robot, something like this: How to build your first robot
You have read my deep thoughts on how to move on with the programming "Don't program your robot.. Teach it!", and you have made tricks with your robot, messed around with it, had some fun and is ready to move on.
Perhaps you have tried out this little trick of seeing what your robot sees.
You have seen on the video of "Making Skiwalker", and seen on the pictures of "Yellow Drum Machine" (the pics in the bottom) - that you do not need much for materials to make a robot; Melt-glue, double sided tape, sticks, and you are go!
If so, this part II should be a breeze! You can make this robot in 45 minutes, no sweat.
First, let's make the robot on the picture above. Try to duplicate the main parts, that is the main task here.
It shuld not need much explantion, it is excaxtly like the one from How to build your first robot - only differences:
- Instead of Sharp sensor, I use SRF05
- The servo is a smaller one, and a fast one - you can get these in any size and speed
- The gearing on the motors is lower, so I have a faster robot (though it is not a speed-king, lol)
- instead of just taping it all together, I have used 3 sticks to form some sort of a "chassis"
The closer you get to this, the easier it will be to follow the rest, but of course you can just do it your way, with whatever parts you have etc.
In the first tutorial I wrote that you could make some fancy code for the robot.
I now present you for some code that I have made, it is what is used on the video. It is an example, there are thousands and millions of ways to evolve, you should do it your way. This is just to try to open your eyes, and share what I have learned after countless hours of trial and error.
Try to alter some of the numbers to tune in to your setup, and read the guidelines in the code. That way you can get a robot like the one on the video, and we are going to use that as a base for Part III in this tutorial...
Find the attached code in the top of the post.
.. And the screwdriver-trick on the video?
Well.. Look for places where the code says
servo Servopin,head
and add, just after it
servo 1,head
If you are adding another servo on pin 1.
Think about what to attach instead of the screwdriver?
Something with an LED on? And insert some on/off in the code for the LED? Or a fan? or.. :D
Stay tuned. This bot is getting more enhancements now..
And if some of the comments below does not make sense, please understand that I am changing this over time, so the comments may have been for an earlier text here :)
Thanks, and do post what robots you make, to inspire back. Thank you.
/ Fritsl




@ Tue, 2010-06-22 13:28
it was a big help
it was a big help
@ Fri, 2010-06-18 06:06
SRF05
I'll building this with my 11yo daughter as our first robot. I've been studying the code for the last week waiting for the parts (kit purchased from Solarbotics, SO helpful). The SRF05 didn't come with a cable. I was thinking of soldering header pins on the board. Would that be good or would you recommend soldering wires directly to the board?
Thanks for the tutorial. We're very excited about getting this going!
@ Fri, 2010-06-18 12:40
Header pins and
Header pins and female-to-female wires. Absolutely.
That way you can take it apart and build something new; You have made yourself a kit :)
Have fun, cheers.
@ Thu, 2010-04-15 04:58
My first robot.
Hi frits,
I've built this robot as my first one. First I downloaded the clean_navigator in the 28X1. The SRF05 turns from one side to the other than stops in the center only once,then the wheels are going backwards. The sonar doesn't detect objects and consequences are that there is no direction changes on the wheels.
I've done the SRF05 range test and it's ok. I also checked the motors polarities and directions according to the clean_navigator (forward ,reverse,spins and slides) and it's ok. I've been trying to study the code as much as I can but I don't find the problem. Hope you could give me a hint on that one,it would be appreciated from you. Thanks for your help and keep up the great work.
@ Thu, 2010-04-15 06:36
Code
You must adapt the code to your own hardware inputs and outputs.
@ Thu, 2010-04-15 17:17
Thanks for your reply
Thanks for your reply my friend ,got it work.
@ Wed, 2009-12-16 02:40
how pixace work
@ Fri, 2009-11-20 22:41
OH!!
@ Fri, 2009-11-20 22:37
Just use the old code
Just use the code in Pt1. Yes you are right. It doesn't work because of the code. It is made for the SRF05. The SRF05 has inputs and outputs blah blah. And for once ... Frits got it wrong. It's supposed to be low 4 : low 5 : low 6 : low 7. And if you want to use this code, you probably need an SRF05 and most likely, an SRF05 mounting brackets.
//newtonl
PS. If you need the mounts, if you are in America, I recommend Lynxmotion or Trossen Robotics.
... And this is my first post that help sombody :D :D :D
@ Fri, 2009-11-20 07:24
IR Sensor
Hi Fritsl
Another great robot and tutorial :)
I have just a few questions I hope you can answer.
1) Should the clean navigation code work with the exact robot in the start here tutorial 1?
I have tried it but with no luck. I guess it is because I am using IR Sensor GP2D12? Can you advise on code modification for this?
When I run the program the head moves to the left then it steps to the right (2 small steps) then it moves left again (1 small step) and at this point the wheels rotate forwards, and this is how it stays.
2) Line 202 gives me a syntax error
201- totalhalt:
202- low 4, low 5, low 6, low 7
203- return
I got rid of the error by changing the comma's to colon's (low 4 : low 5 : low 6 : low 7)
I ask this because you say that the code is exact as entered in the program and I would like to understand why I get the error.
Thanks again for all the great work you do here
@ Sun, 2009-11-29 17:08
1) No, the code should be
1) No, the code should be adapted. It is not very often that you can take code from one robot and use it in another without modifications. Alone how you hooked up your motors will affect stuff.
If you use the sharp, you will have to adapt. And note that as far as I remember, the shapr returns higher values the closer an object comes. The SRF05 standard routine returns lower the closer :)
3) The editors are a little different on this, you can use low 4 low 5 low 6 low 7
or
low 4
low 5
low 6
low 7
or
low 4 : low 5 : low 6 : low 7
point is to set all them ports low ;)
Mostly I think you should understand the code, and then adapt it to your own project. It is the principle of looking around while driving, then acting if.. that is the point here :)
@ Thu, 2009-11-19 10:49
CODE!!!!!!
With the clean_navigation code, I seem to have a problem. At the beginning, when I turned it on, the servo jiggles around a bit and then the wheels turn and nothing happens. No sensor pulse (from the led). But the sensor definitely works because when I used that sensor code in part 1 , the led started flashing. Its finished, fully built but I NEED HELP WITH THE CODE.
btw, the wheels go on and on and after a while, the servo jiggles again.
//nerdz1
@ Sat, 2009-11-14 12:27
Don't worry about that! i have another worry!
I was wondering about the speaker. I am using a mylar speaker and I need to know where to solder that speaker. DESPERATE HELP! I'm almost finished this robot and its my FIRST ONE!!!!!! All help appreciated.
BTW il probably post fotos.
@ Sat, 2009-11-14 00:28
Balace
@ Tue, 2009-11-10 10:23
WOOD DIMENSIONS
@ Tue, 2009-11-10 11:10
I do not have the robot here
I do not have the robot here where I am now, but later i can find it for you.
However, please allow me to ask; Why do you mind? The point is (I should think) not to make a replica of my robot, but to learn how to make something yourself.
By "making something yourself", I mean that being able to find some wood, and make a robot out of it, glue it togeter, cut it, make it work, you know :)
@ Fri, 2009-11-06 12:30
AA batteries
@ Fri, 2009-11-06 19:15
yes
@ Sat, 2009-11-07 00:43
BTW!
@ Sun, 2009-11-08 02:58
Yes you can use 3 AA
Yes you can use 3 AA batteries...although for me it affects the performance of the motors...so i use a 2nd power supply...u can search it here it the forum...its quite easy...
whew i remember my first time :)
@ Sat, 2009-05-30 03:41
what is the model of the
@ Mon, 2009-11-16 09:09
HS-55
@ Thu, 2009-06-04 20:20
I would not know, sorry.
@ Tue, 2009-05-26 02:59
ty guys, great effort..i
ty guys, great effort..
i hope we can do it by the voice..it will be more easy to use it by webcam too. then we can contact our robots with our eyes....like (eyetwig)software..
cu
@ Sun, 2009-05-24 15:32
wow!
cool!!
In Fact, This Is My First Time Here..
I Gonna Build My First Robot.
But How Can I Control The Robot By Voice..ex( Go And Turn Right..)ty all
@ Sun, 2009-05-24 16:06
Good luck. That would
@ Sun, 2009-05-24 16:39
Check this builder
@ Thu, 2009-03-12 22:05
BTW...
Forget about Walter swinging his head... I played with the "top of the head" mounted sonar and quickly found it was WAY to high off the ground to be any good. I have pulled the SRF005 and relocated it to the underside of the chassis on a servo in the standard way. I added 2 sharps in the corners to catch walls parallel to travel and so far this seems to be a solid set-up.
Word
@ Thu, 2009-03-12 22:26
Word, I wonder what is going
Word, I wonder what is going to pop up from W's head then?
I'll donate you a laser pointer as replacement :)?
@ Sat, 2009-04-18 05:00
gosub puls error
Hi fritsl,
I've just download the 'clean_navigation.bas' file on this page. When i use 'simulate' on the editor programme it comes up with the error =
gosub puls
^
Error: Only 16 gosub commands allowed!
Is this something I've done or is it something that doesn't affect the running of the program?
Also when I downloaded the program it came down as a .BAS.txt file so had to copy/paste into a new basic file.
@ Sat, 2009-04-18 20:35
You should set up your
You should set up your Picaxe to 256 gosubs or something. It is done in the Options or something :)
(I am not on a PC with the editor installed here)
@ Thu, 2009-03-12 22:02
Hey Frits --I figured it out!!
@ Thu, 2009-03-12 02:19
A little help with your code....
Hey Frits,
I am reworking your code here and noticed something I don't understand... This is in the "Tester" chunk of the code.
gosub puls
if range < Danger and head > ForwardLeft and head < ForwardRight then
GOSUB AFTERTURN
gosub PHASEA2
end if
if range > ClearPathAhead and head > ForwardRight and head <= 225 then
GOSUB AFTERTURN
gosub PHASEA2
end if
if range > ClearPathAhead and head < ForwardLeft and head >= 75 then
GOSUB AFTERTURN
gosub PHASEA2
end if
it seems like no matter what the sonar is sending back, you are still heading back to the Driveahead subroutine (by way of afterturn). I.e. if range is < danger and the head is basically centered, you still go fwd. Or if you have "clearpathahead" and the head is to either side you still go fwd. After that you go back to phasea2 which makes sense, I just don't get the fwd part. Did you include this just so you could add a "totalhalt" if you wanted? Explain this if you would.
@ Thu, 2009-03-12 14:01
You evil person!You are
You evil person!
You are asking me to justify / explain code I made one year ago!?
Heck. This take s a second reply.
@ Thu, 2009-03-12 14:14
Hey, Chris,Just a note
Hey, Chris,
Just a note before I answer your question:
Have you seen how the bot @ http://letsmakerobots.com/node/5751 is navigating?
I think this is way more walter-style! Check the moves, the personality in the slowing down, reversing etc..
You are having such nice PWM-options, so even though I use servos, you should be able to copy what I did.
Also, I know it's an omni wheeler that I made, but 2 wheels and a tail would be the same, code-wise, I only work with 2 "axles".
That code is much smaller, more recent, the next thing.. You just need 2 sensors - static - to make it work. And with your wide front, also one to clear the front.. which is walters head!
With the old code you are on here, you would need to shake he's head so violently, not nice!
http://letsmakerobots.com/node/5751 to control the basics, and he's head to add in with extra is what I'd go for!
@ Thu, 2009-03-12 14:47
The answer:Hey Chris, I have
The answer:
Hey Chris, I have looked at the code and your question.
Yes, aparently it is strange. Yes, perhaps it is a leftover from some debugging. And yes, sometimes I make strange code, because I think it is fun to make something that is not really logic at first sight, but when diving into it, it is pure logic. Sort of like easter eggs.
Weather this one is a bug, a debuging option, or an easter egg, I really cannot tell, as my brain only allows me to look at old stuff in a very limited time - it simply halts and start inventing new, so I cannot go deeper into it, sorry.
Have you seen the new omni-code? It is cool!
@ Sun, 2009-02-22 05:01
Fried pins
Frits-Is it possible to fry just the pins on a chip? I cant get pins 1-3 to work at all ive built a very similar robot to yours and used your exact code with slight modifications but i cant even get a servo to work on Digi out pins 1-3?
@ Sun, 2009-02-22 16:20
It may be possible, but I
It may be possible, but I have never done it. And I have always ben very rude to my chips. They never took any offence, as far as I knw, a Picaxe is very hard to fry!
I am pretty sure you will find the error somewhere else, check one thing at a time, make sure it works..
@ Sun, 2009-02-15 14:41
Voltage
uhm frits...u used 6v as a power supply right?4 AA batteries? doesnt that fry the picaxe and srf05? what if i was to add 2 LEDs and 1 superbright LED..im kinda scared i might fry the board..
@ Mon, 2009-02-16 11:37
I use rechargables, they are
I use rechargables, they are not 1.5V, perhaps 1.2V, so it's close to 5V, all is cool with Picaxe & SRF :)
On LED's I usually insert one 330 Ohm resistor.. but apart from that I have no clue, I burn them all the time, or they are dim because I feed them too litle, don't ask me about electronics ;)
@ Sat, 2009-01-10 08:53
LED skids
@ Sat, 2009-01-10 09:38
LOL, I was really scratching
LOL, I was really scratching my head, like WTF? Yellow LED? There is no such?!?
Uh yes, as always robologist is right: Look here for inspiration: http://letsmakerobots.com/node/2112
@ Sat, 2009-01-10 13:42
LOL ^ ^
I knew that too i was even fighting with a friend and was pretty sure it was used as a slide or a caster so it would not move like the robot on part 1 and look like it needs more balance but to be sure, I asked.
Gosh that was a pretty dumb question. ^ ^
@ Sat, 2009-01-10 05:13
About the led lights at the bottom
@ Fri, 2009-01-09 15:56
Gear Motor
@ Fri, 2009-01-09 18:16
I would assume they are the
I would assume they are the same ones in the start here project.
http://www.hobbyengineering.com/H1415.html
@ Sat, 2009-01-10 03:36
Just to make things clear before starting
What is the use of the Yellow LED down the SRF05?
If i use This servo motor http://www.hvwtech.com/products_view.asp?ProductID=862 shall i change the resistor?
Does the SRF05 comes with the wires and pins for the connection?
Im From Asia and shipping cost more than the items so i like to order them all at once thank you for your help...
Im soooo excited to do this hope u can reply soon :)
and thank you for bearing with me...
@ Mon, 2009-01-05 07:05
Hmmm...
Ok after reading that back I hope that helps some-one. As usual with me, I'm good at explaining things to myself and not so much to other people. Despite that I was wondering if I should make that into a seperate blog as there aren't many blogs which help the programming side of robotics (compared to blogs about building robots).
"Unfortunately, you learn from your mistakes"
@ Mon, 2009-01-05 07:04
I Hope I Covered Everything...
Not meaning to bring an old debate back to life here but as a new member I would like my chance to input having missed out at the appropriate time.
(this is really for people who are don't know how a compiler works and I hope it helps =) )
A compiler reads your high-level code (that being your coded program) and churns out object code that your chipset can understand. Object code is a version of assembly language that your computer (or microcontroller) can understand, it looks a bit like this: 10110000 01100001... (Forgive me for my binary just isn't what it used to be so I copied this code from somewhere online haha...)
This, translated into assembly, gives : MOV AL, 61h
Which means to you and me : initialize something (i.e. a variable representing my current level of tiredness) to the hexidecimal value 0x61 (which would probably be quite accurate).
So the basic rundown,
Highlevel Code --> Assembly Language --> Machine Code (Object Code)
What's the importance of this I hear you say?? aha well here is the interesting and in some cases rather annoying part...
Being a games programmer I have dealt with many different compilers and many different languages and I just want to state that although fritsl is 100% completely correct (and I think I can explain why in a minute) I can understand where jka is coming from as many times I have made this mistake (most of my work is done in languages based on C).
When the compiler does it's job and makes our nice machine code it will (and only in the case of a few compilers) take all the variables in your program and pre initialise them to zero in your machine code for you. And yes obviously PICAXE BASIC is one of those few compilers, therefore, if you initialise variables to zero yourself in PICAXE BASIC, it makes your program look a bit like this (in a human understanding instruction set called psuedo-code) :
Make a variable called 'WASTE' and give it the value 0
Make a variable called 'WASTE' and give it the value 0
Make a variable called 'OF' and give it the value 0
Make a variable called 'OF' and give it the value 0
Make a variable called 'TIME' and give it the value 0
Make a variable called 'TIME' and give it the value 0
And now I have just shown you all how to double the length of your code ;)
Seriously though, I would always recomend initializing to zero unless you know your compiler does it for you!!! It is good code practice and will (in some REALLY annoying cases) give you back a few extra days of your life you would've other-wise wasted
Another similar mistake is thinking that all arrays in all languages start at 0. Boy-oh-boy...
Conclusion!!!
In PICAXE (and other microcontrollers) save your space for code and dont init accumulators but in most other applications it can't hurt.
"Unfortunately, you learn from your mistakes"
@ Fri, 2008-12-26 13:48
That was impressive navigation!