Shop OBEX P1 Docs P2 Docs Learn Events
Centering Ping Servo — Parallax Forums

Centering Ping Servo

HatemHatem Posts: 20
edited 2008-04-29 23:54 in BASIC Stamp
Hello everyone, I have the compass module mounted on the Ping Servo mounting bracket. Every time I turn on the Bot, the Ping servo moves a little to the right and I have to add a long pause time at the beginning of the program to manually center the ping. Is there a way to overcome this glitch???

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-04-29 19:09
    You should not have to touch the servo. Send the servo a 'centering' command (pulsout) at the start of the program and it should come back to the same place as before. If this does not work then make sure the servo is mounted securely and the code does not cause the servo to HIT the ends of it's travel.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • HatemHatem Posts: 20
    edited 2008-04-29 20:44
    Thanks Franklin, I used a PULSOUT command and managed to have the bot center its head before the program starts, another thing is related to angles and heading. If I obtained the angle before and object is detected and titled Angle1, and after the bot maneuvers around it, it will obtain a new angle reading and name it Angle2. The logic is simple. If Angle2 is more than 5% of Angle1, then the Bot will go on circles until the difference is zero, otherwise it will go forward.

    Correct_Heading:

    IF (Angle2 - Angle1) < (Angle1/20) THEN
    InitialValue = InitialValue + 140
    ELSEIF (Angle2 - Angle1) > (Angle1/20) THEN
    GOSUB Turn_to_Heading
    ENDIF
    RETURN

    Turn_to_Heading: '*** I am not sure if this is correct, the Boe-Bot
    '*** will turn untill it becomes within 5 % error of
    relBearing = 360 - (Angle2 - Angle1) '*** Angle1 beofre an object is detected
    counter = relBearing - Angle1
    DO
    PULSOUT LeftServo, 850 ' Left Servo Pulse Value
    PULSOUT RightServo, 850 ' Right Servo Pulse Value
    PAUSE 20
    LOOP UNTIL counter = 0
    InitialValue = InitialValue + 140
    RETURN

    My bot just keeps on turning nonstop. I am not sure how to perform this task.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-04-29 23:54
    Simple problem -- in your "DO" loop, you never decrement "Counter", thus it never reaches zero.
    Put a "Counter = Counter - 1" inside the do loop to fix this.
Sign In or Register to comment.