Let's Make Robots!

Robot sensor won't detect anything

I'm building the "How to make your first robot" robot and i'm stuck on the programming part. I've been trying to figure this out for 2 hours now and i'm about to go insane. 

This is my code

 

 

 

 

 

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 distance

 

main: ' the main loop

readadc 0, b1 ' read how much distance ahead

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 4 : high 6 : low 5 : 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

readadc 0, b1

gosub totalhalt

 

 

'Look the other way:

gosub rturn ' look to another side

pause servo_turn ' wait for the servo to be finished turning

readadc 0, b2

gosub totalhalt

 

' 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,225 ' face forward

wait 1 ' freeze all for one second

return

 

 

 

 

My robot will just go straight forward, without turning at all. I think the problem is that my "b1" value doesn't change at all. It can't be because it doesn't work; when I type in ...

 

 

main:

 

readadc 0, b1

 

debug

 

goto main

 

 

 

...the values change.

 

Thanks for your time.

Comment viewing options

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

Sorry 'bout that --I read right past it.

Then yes, I repeat what Bird wants to know --What were the numbers you were getting and do they relate at all to the "danger" threshold you have set?

I would run a code like this:

main:
Read the sensor
debug
goto main

 

Tidy up the above code and run it. This way you can isolate the sensor and also see what kind of numbers you are getting from it. It should explain a lot. 

the code right above the video? He did just what you suggest. What he doesn't say is whether the sensor data makes any sense with respect to distance.

Or, am I missing your point again?

Test your robot with its wheels off the ground. This way you can keep it connected to your computer and get debug information.

You mention your second program gets varying numbers from your sensor. You don't say it varies in relation to distance.

I was looking at your code, and, in the total halt routine you send 225 to the servo and say that it should be centered, yet, in your lturn and rturn subroutines you use 200 and 100 for your values. 225 > 200 and 225 > 100, centering aint gonna happen. :)

None of my previous statements will fix your problem. Sorry. As we can see you have a camera, have you considered making sure the IR is actually working by looking at the sensor with the camera when it is powered up? It should appear a purple-ish white/grey. If you can't see it, it either means your sensor is dead, or, your camera is filtering IR.