BS2 servos do not turn the opposite way

Hello,
First post here!
I am from Greece and I have collected DeAgostini's robot which has Parallax'es BS2. I am trying to rotate the robot where the light is. This is accomplished with 2 photoresistor one for left and one for right in combination with resistor and capacitor.

This is my programm
' {$STAMP BS2}
' {$PBASIC 2.0}

'----------variables------------------
photo_right VAR Word
photo_left VAR Word

pbin VAR IN2

'------constants---------------
threshold CON 20
left_in CON 10             
right_in CON 9              
left_servo CON 12           
right_servo CON 13          

'---------------activation-------------------

LOW right_servo
LOW left_servo

start:
    IF pbin = 1 THEN start

'---------main--------------

main:

  HIGH right_in
  PAUSE 3
  RCTIME right_in, 1, photo_right


  HIGH left_in
  PAUSE 3
  RCTIME left_in, 1, photo_left

  IF ABS(photo_right-photo_left)  < threshold THEN main
  IF photo_left > photo_right THEN turn_right
  IF photo_left < photo_right THEN turn_left

turn_left:
  PULSOUT right_servo,500
  PULSOUT left_servo,500
  PAUSE 20

turn_right:
  PULSOUT right_servo,1000
  PULSOUT left_servo,1000
  PAUSE 20

GOTO main

There is a problem with the turn_left command. It just turns so slow that is like shaking.
I tried in a new program to try it and it worked perfectly.
' {$STAMP BS2}
' {$PBASIC 2.0}

lowtime VAR Word
lowtime=20

LOW 12
LOW 13
loop:
        PULSOUT 12,500
        PULSOUT 13,500
        PAUSE lowtime
GOTO loop

Any ideas? Thank you for your time!
DeAgostini Robot. Basic Stamp 2. And a lot of peripherals trying to combine!

Comments

  • 3 Comments sorted by Date Added Votes
  • I was searching for an hour or so before post. The moment I posted I found it!
    I forgot the GOTO main under the turn_left!
    DeAgostini Robot. Basic Stamp 2. And a lot of peripherals trying to combine!
  • DaveJensonDaveJenson Posts: 139
    edited February 6 Vote Up0Vote Down
    You probably also want a GOTO main just before the turn_left routine. Because, if none of the conditions are satisfied, it will fall through and execute turn_left.

    (for instance if photo_left = photo_right)
  • DaveJenson wrote: »
    You probably also want a GOTO main just before the turn_left routine. Because, if none of the conditions are satisfied, it will fall through and execute turn_left.

    (for instance if photo_left = photo_right)

    Yes you are right! Thank you.
    Even the possibilities to be equal are very low it is more safe to add it!
    DeAgostini Robot. Basic Stamp 2. And a lot of peripherals trying to combine!
Sign In or Register to comment.