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
else
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

whichway:
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
else
gosub body_rturn
end if
return

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

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

rturn:
servo 0, 100 ' look to one side
return

lturn:
servo 0, 200 ' look to the other side
return

totalhalt:
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
return

This is what I used: Of

This is what I used: Of course you may vary depending on how you wired it.

Symbol dangerlevel = 35 ’ 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
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
symbol lrange = w2 ‘ 16 bit word variable for range
symbol rrange = w3 ‘ 16 bit word variable for range


main: ’ the main loop
Servo 0,150
pulsout trig,2 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echo,1,range ‘ measures the range in 10uS steps
pause 10 ‘ recharge period after ranging completes
debug range

if b2 > dangerlevel then
gosub nodanger ’ if nothing ahead, drive forward
else
gosub whichway ’ if obstacle ahead then decide which way is better
end if
pause 500
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
return


whichway:
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
pulsout trig,2 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echo,1,lrange ‘ measures the range in 10uS steps
pause 10 ‘ recharge period after ranging completes
debug lrange

’Look the other way:
gosub rturn ’ look to another side
pause servo_turn ’ wait for the servo to be finished turning
gosub totalhalt
pulsout trig,2 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echo,1,rrange ‘ measures the range in 10uS steps
pause 10 ‘ recharge period after ranging completes
debug rrange
pause 500

’ Decide which is the better way:
if b4 > b6 then
gosub body_lturn
else
gosub body_rturn
end if
return

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

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

rturn:
servo 0, 100 ’ look to one side
return

lturn:
servo 0, 200 ’ look to the other side
return

totalhalt:
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
return

See, the bad thing about not

See, the bad thing about not writing your own code is that you don’t know how it works. (Or you have to read it very carefully and understand it.) If you don’t know how it works, you can’t alter it. So I suggest you start writing your own code, whilst peeking at frits’ code. Because I don’t know if frits has the time to help everyone with altering his source code.

Just start small. Have your robot drive forward, then backward. Then make it turn. Then make the head turn. Get the SRF05 working. And then finally add everything together.

Good luck!

 

GobliZ - Check out my robots

Well I posted my code
Well I posted my code because I empathize :wink: When I used the start here code I had to modify it too. I went over his code with a fine tooth comb to understand it prior to running it. It was helpful for me to get the code and since mine was wired up just like his I could make it to my robot almost exactly. In this case having the code did actually help me since I also had mine wired up like his (except for the SRF05).

thanks all xD i’ll post my
thanks all xD i’ll post my “frankenstein” soon

If you run my code while the
If you run my code while the stereo adapter is plugged in it will send the value of range to your screen so you can see how it changes as the SRF05 is clsoer to objects. Very handy to tweak the danger level…

- But when done, you want to
- But when done, you want to remove the "debug" commands - they slow down the performance significantly!!

** how far away should thing be, before we react?**
how far away should thing be, before we react?Is this part of the code or is it just an explanation? because it is bolded in Fritsl instruction and I assume it is part of the code.

Its trial and error. Thats
Its trial and error. Thats why I put the debug in. I let it run and waved my hand at what I thought was a safe distance then recorded what the range value was. Then I made that the value of the dangerlevel so it would react when it got to that distance. Everyone will have a different value.

"how far away should thing

"how far away should thing be, before we react?" is NOT part of the actual code. It is comment. So as you said, just and explanation.

Do you have any idea what you are doing? First read a manual about the programming language the picaxe uses. After reading that carefully you should know all this, and be able to write your own programs.

 

GobliZ - Check out my robots

sure I’ll read it if I know where to find it!
where can I find that info? I would love to learn it!

I’m not sure if this is the

I’m not sure if this is the best manual, because I don’t own a picaxe. But after a quick google on ‘picaxe manual’ I found this for you. Try reading it, and try every example in it. You will have fun with it, and you’ll learn to write your own programs, so you can let your robot do whatever you want!

GobliZ - Check out my robots

READ ALL!:PICAXE

READ ALL!:

PICAXE Manual


I’m trying to program a
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? :stuck_out_tongue: … 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?

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

hey man
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.

FYI

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

… 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

Very true! I once did a 38
Very true! I once did a 38 KHz emitter based on PWM but when the debug was on the timing got messed up and I didn’t know what the hell was going on. So beware of the debug command!

ok
ok