Let's Make Robots!

First Robot (Stole Frits' Design)

 

He is working as well as he could be. Still some minor bugs. If I hold him he doesn't stop until he gets close to something. On the ground he only moves a few inches then thinks he hit something. I think having the servo, motors, and board on the same power source is messing up the range finder. I'll get a video posted tonight.

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Well it's fixed. For future notice make sure all your solder joints are firm ;) The ground wire was loose and causing it to have problems.

His only problem now is that when going forward and nothing in front of him the servo jerks around. I added some code to the main loop to make it face forward )it was going all the way to one side). Now it moves a few degrees to the left or right then centers. The problem with this is it messes up the reading it does to make sure it is still no in danger. So it thinks it is hitting a wall and turns around every second or so. Any ideas why the servo is acting up? I'm thinking it has to do with being on the same power source as the motors and board. This robot will be harvested in a few days anyway so I can work on my next one, but I want to know what is going on with the poor little guy. I pasted the code below, but I doubt this issue is with the code at all.

 

Symbol dangerlevel = 70 ' 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

It should be if range > dangerlevel then go forward

The problem was I needed to use if b2 > dangerlevel then go forward. That seems to have fixed it. The only problem I have now is one of the leads broke off a motor so I need to solder it back on. It was almost midnight last night and I wasn't up for heating up the soldering iron. I'll get it going tonight...

First of all, you should (IMHO) omit the "let range = range * 10 / 148" - I always work with the real values from the sensor.. But that is just one guy's opinion.

The fix:

Since you are using SRF05, where large number = long distance, I should think there is something wrong with this line:

if range > dangerlevel then

Should it not be

if range < dangerlevel then

?

:)

.. and noone to blaim for poor instructions but me :D 

/ Fritsl

Maybe the ultrasonic range sensor has a lot of variance in it's output. That isn't always correct. I had the same sort of problem with my ping))) ultrasonic sensor. I solved this by measuring 5 times and then take the maximum of this measurements. I also test with taking the average of the 5 measurements, but this didn't have the best results.

Oh no.. the SRF05 & Picaxe is bloody rock solid! Seriously, I am always amazed when checking, it is steady, steady.. 2 milimeters forward, one or two digits change, back, and digits change back, with no variations or hickups at all!

Unlike Infrared - that dances around. 

/ Fritsl