Is this program correct?

my board.

Picture_117.jpg

this is my problem.

my servo keeps on jettring when i place my hand in front of the SHARP IR… and when i remove my hand servo wont move to any side nd my robot would jst move forward.

 

Hi Paul. You’ve made a

Hi Paul. You’ve made a symbol Servo_turn but you haven’t used it anywhere. The servo needs time to reach it’s position after you tell it to turn. The reason being the picaxe executes commands much faster than the servo can move. So you slow the processor down with a pause.
Could be something else but I’d start there. Stick a Pause servo_turn in both the lturn and rturn and stopinst  subs just after the servo command.

I see a few (and I got it)

if b1 < danger then  should be if b1 > danger then

if b2 < b3 then might be backward as well

 

Also, this guy here:

gosub lturn 

readadc 0, b2

pause turn 

In this case, you are moving your servo, reading your sensor, THEN doing the pause (to allow time for the servo to move).

The stopinst: routine does not have a pause after the servo move either

One more

When you tested your Sharp sensor by itself, what were the numbers coming out? Is 160 a proper threshold?

160 is correct. wn I changed
160 is correct. wn I changed b1>danger it did nt work properly. It ws stoping when norhing was der in front.

Ok, you just need to isolate

It appears we have exhausted all the “standard” stuff. At this point, you need to break everything down and do this systematically. The first thing I would do is write the simplest program you can to do the following:

  • Center sensor servo at start-up (leave it centered)
  • Drive forward
  • Keep checking sensor
  • if sensor is closer than threshold then stop (as long as something is there, the bot should remain stopped  --remove your hand and the bot should start going forward again)

That’s it. Its really your code, without a servo sweep or any turning. This will tell you if the most basic flow of your code is correct. Once this is established, you can start putting your look-left/look-right back in as well as the turns.

I suspect this simple test program will uproot the problem with your main code quickly.

Have a go with this code Paul

symbol danger = 160
symbol turn = 500
symbol servo_turn = 400
symbol frontVal = b1
symbol leftVal = b2
symbol rightVal = b3

main:
readadc 0, frontVal
if frontVal < danger then
gosub noprob
else
gosub whichway
end if
goto main

noprob:
high 5 : high 6 : low 4 : low 7
return

whichway:
gosub stopinst
gosub lookLeft
readadc 0, leftVal
gosub lookRight
readadc 0, rightVal
gosub lookFront
if leftVal < rightVal then
gosub turnLeft
else
gosub turnRight
end if
return

turnLeft:
high 6 : low 5 : low 7 : high 4
pause turn
gosub stopinst
return

turnRight:
high 5:low 6:high 7:low 4
pause turn
gosub stopinst
return

lookLeft:
servo 0, 200
pause servo_turn
return

lookRight:
servo 0, 100
pause servo_turn
return

lookFront:
Servo 0,150
pause servo_turn
return

stopinst:
low 4 : low 5 : low 6 : low 7
return

 

 

oss & merser

i had installd the resistor chip…
merser the robot did nt turn… :( 

Not enough information sorry

Well I’m sorry Paul. I guess I haven’t got the answer for you then. As all you give me is it doesn’t turn I haven’t got much to go on.
Could be maybe an inadequate power supply, incorrect circuit then.
I’d take Chris’s advice and break it down into smaller parts. Get your servo to turn first, get your motors to run one way then another, make the IR trigger an led, and then put the code blocks and circuits together.
I would suggest you read this article first and then give it another go.

worked a little.

my bot worked it will sence whats in front but it will only turn right nd if nothings ther then it will go forward.
i thing my sharp is not returning a second value in whichway.
how shoul i correct it.

this is the one that worked-

Symbol danger = 160

main: 

readadc 0, b1 

if b1 < danger then

gosub noprob 

else

gosub whichway

end if

goto main 

noprob:

high 5 : high 6 : low 4 : low 7

return

whichway:

high 6 : low 5 : low 7 : high 4 

return

 

Sounds like that just works

It sounds like you have a working system. At this point, I would set it aside and try the next simple code.

For this next program, I would skip the motors and move on to the servo. Leave the chassis motionless and write a program that does only this:

  • Swing servo to left side, take reading
  • Put this reading in a variable called "left-something"
  • Swing servo to the right side, take reading
  • Put this reading in a variable called "right-something"
  • Send these readings to your terminal or debug window 
  • Confirm that these numbers are what you are expecting

When you get these numbers coming thorough ok, I would add some code to simply determine with direction is the better way to go (which direction you would want the robot to go) and have that data sent to the terminal or debug window as well. 

With this “isolated” test, you can confirm your numbers are what they should be, and you can check this one off the list.

Out of curiosity…

What kind of battery pack are you using on this bot? I can’t see it in your pictures.

am using 4 rechargible

am using 4 rechargible battery of 900mAh

servo

i tested as chris have told.
my servo is moving too fast to each side and am not getting a return value from sharp always. some times it return a value.
how can i make the srevo move slowly?? 

Ok, two things

There are two issues here. First, it is not how fast the servo is going to its position, its that it is not staying there long enough. Servos are physical things that take time to get to where they are going, after you tell a servo to go to a given position, you need to add a pause to allow it to do so. If you do not use a pause, or the pause is not long enough, the sharp sensor will try to take a reading while the servo is still moving (not good for solid readings). Your code should be this:

  • Move servo
  • pause 1000 or so
  • read sensor / variable one
  • move servo to other side
  • pause 1000 or so
  • read sensor / variable two

A one-second pause should be more than enough for your servo to get to where its going. If you use the code above, you should be getting two good readings from your sharp in your two variables. If you are not getting both readings, something else is wrong.

 

Apart from the above, if you want to slow down the actual “sweep” of the servo, this can be done. It should be mentioned that the speed at which your servo moves IS NOT  the cause of your sensor problems. --This “slowing down the sweep” issue is UNRELATED to your issue as described above.

–To slow down a servo, you simply need to move it a little bit at a time with a small pause in-between. You are going to use a “for loop” to do this. As a matter of fact, a for-loop is incredibly important and you will use it all the time, it is very important to learn.

 

i found the problem.

chris i had done that before. it did not work because of a loose contact btwn the battery nd the board.

 

symbol servo_turn = 700is

symbol servo_turn = 700

is this correct??

main:

servo 0,100

pause servo_turn

readadc 0, b2

 

debug

goto main

battery.

is 900mAh battery gud for robots…?

4 AA

am using  4 AA batteries. 
is it gud.??