Let's Make Robots!

Source code for Srf05 and picaxe 28x1

is this the correct way to adapt the source code of fritsl's "how to make yfr" for a srf05 sensor? ... i suppose not -_- .. T_T .. can you help me fritsl? :p 




Symbol dangerlevel = 50 ' how far away should thing be, before we react?
symbol turn = 300 ' this sets how much should be turned
symbol servo_turn = 700 ' This sets for how long time we should wait for the servo to turn (depending on it´s speed) before we measure distance
symbol trig = 3 ‘ Define output pin for Trigger pulse
symbol echo = 6 ‘ Define input pin for Echo pulse
symbol range = w1 ‘ 16 bit word variable for range

main: ' the main loop
pulsout trig,2 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echo,1,range ‘ measures the range in 10uS steps
pause 100
let range = range * 10 / 58 ‘ multiply by 10 then divide by 58
readadc range, b1
if b1 < dangerlevel then
gosub nodanger ' if nothing ahead, drive forward
gosub whichway ' if obstacle ahead then decide which way is better
end if
goto main ' this ends the loop, the rest are only sub-routines

nodanger:' this should be your combination to make the robot drive forward, these you most likely need to adjust to fit the way you have wired your robots motors
high 5 : high 6 : low 4 : low 7
goto main

gosub totalhalt ' first stop!

'Look one way:
gosub lturn ' look to one side
pause servo_turn ' wait for the servo to be finished turning
gosub totalhalt
readadc range, b1
'Look the other way:
gosub rturn ' look to another side
pause servo_turn ' wait for the servo to be finished turning
gosub totalhalt
readadc range, b2

' Decide which is the better way:
if b1<b2 then
gosub body_lturn
gosub body_rturn
end if

high 6 : low 5 : low 7 : high 4 ' this should be your combination that turns the robot one way
pause turn : gosub totalhalt

high 5 : low 6 : low 4 : high 7 ' this should be your combination that turns the robot the other way
pause turn : gosub totalhalt

servo 0, 100 ' look to one side

servo 0, 200 ' look to the other side

low 4 : low 5 : low 6 : low 7 ' low on all 4 halts the robot!
Servo 0,150 ' face forward
wait 1 ' freeze all for one second

Comment viewing options

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

Sometimes, for some reason, I need to add a pause command after the servo command to get them to go. I have no idea why. 

www.rocketbrandcustom.com baby!!

Hey Pasquale,

I tried (and failed -over and over and over) to do exactly what you are trying to do right now... I had studied frits's code again and again -even going as far as cutting and pasting (with actual sissors and a glue stick) the various sections of code to a big piece of cardboard to make a flowchart. I can't agree with GobliZ more, you gotta write your own code. As he said, keep an eye on code from others for ideas.

 Another thing I am still trying to learn is break everything up into smaller steps. Start with a program that has all your basic moves on it: Fwd, Back, spin R/L and slide R/L. Label this as "Basic Moves" and you can always come back to it to copy/paste. The same goes for your sensors - Write just the code that makes you sonar work and add a "debug" command at the end. This one is good to use so you can find out what numbers are being spit out. Keep each section small and be sure it works (Well) before going to the next step.

One more: If Frits or others are giving you some grief -Remember, no one is going to write your code for you... It is actually a blessing to have someone point you in the right direction without giving you the answer directly. 

www.rocketbrandcustom.com baby!!

I been trying to program the robot for a few days now. Posting is for asking question and whatever I could not figure it out myself I will ask. If we don't ask question then what is the point of having this blog?

.. in the fritsl's guide there's a great explanation. 

write on the program editor

servo 0,150

press f5 wait for upload then write

servo 0,200

if nothing happen: servo 0 (<= is this the correct pin of your servo?") , 200

or... have you connect it properly? but you should understand what are you doing or it's useless.. read the guide again and take your time..  and read the manual with more attention.

however this is not the correct post to ask this O_o 

I did read the manual but its just mumble jumble to me. I just want to get this thing working or I will throw it in the trash soon. What you talking about respect man? I am just trying to get my robot to work thats it. If you don't want to help thats find but don't talk like I am stupid. I got bettter stuff to do than spending all my spare time with this eventhough I find this interesting and just want to explore it.
I think what he was referring to is asking questions about basic programming topics. If you don't know what comments are or what they do, you won't get very far at all. You won't even be able to modify someone else's code. You really need to learn what the code does before EVER building a robot. Even if someone hands you all their code you have to know what it does or you won't get it to work. Study the code line by line and look up what it is doing so you understand it.

Yes. And stop making more postings in here before you have done so!

It's cool to be newbee and all, but comon, RTFM. I have send you links to it! 

- Or find someone to talk to about it, thay may also help! 

my fricking servo is spining like tomorrow what number should I change?

Hi Vansu


I think you will get more respect and therefor more help if you show that you are trying on your own befor asking questions that are covered in the manuals. You should find the manuals under:


Start > Programs > Revolution education >

  Picaxe Manual 2 -Basic commands.pdf

On page 147 it explains what the servo command does and how to use it.



I'm trying to program a fluid moviment for my robot like the fritls's one in the part II.. the jklug80's code is a very good one but I want to avoid a "total stop" when the sensor sees an ostacle. fristl's can't you post your code? :p .. by the way, I'm going to traslate your tutorial "how to make your first robot part I" in a quite known italian blog, obviously with links and credits for this site. can I?