Shop OBEX P1 Docs P2 Docs Learn Events
Wheel turning 90 degrees — Parallax Forums

Wheel turning 90 degrees

bee896bee896 Posts: 25
edited 2010-10-17 20:37 in Propeller 1
Recently I'm trying to make the boe-bot turn exactly 90 degrees so that it won't keep turning and eventually go "off the line".
CON
                                       
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  
  leftservo = 1
  rightservo = 2

VAR

  byte counter
  long Pause, Pulsout

PUB left

  Pause := clkfreq/1_000
  Pulsout := clkfreq/500_000

  dira[leftservo_pin]~~
  outa[leftservo_pin]~
  
  dira[rightservo_pin]~~
  outa[rightservo_pin]~
 
  repeat counter from 1 to 19                        ' Loop for 1 seconds
    outa[rightservo_pin]~~ 
    waitcnt(Pulsout * 650 + cnt)                     ' clockwise
    outa[rightservo_pin]~ 
    outa[leftservo_pin]~~ 
    waitcnt(Pulsout * 650 + cnt)                     ' clockwise
    outa[leftservo_pin]~
    waitcnt(Pause * 20 + cnt)
The code above causes the robot to turn right but not exactly 90 degrees. Anyone has any idea how to improve it?

Comments

  • william chanwilliam chan Posts: 1,326
    edited 2010-10-15 15:57
    How many degrees the robot turns would depend on the voltage of the batteries and the type of ground.

    To make it move or turn very accurately, you need to get these

    http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/wheel/List/0/SortField/4/ProductID/80/Default.aspx
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-10-15 16:57
    You might want to take a look at the Boe-Bot Digital Encoder Kit. It will help you to make precise turns regardless of battery voltage and servo idiosyncrasies. There's no code for it for the Prop, though, that I know of, so you'll be breaking new ground there.

    -Phil
  • bee896bee896 Posts: 25
    edited 2010-10-15 22:42
    Thanks for the info.
    So with my current condition, without using Boe-Bot Digital Encoder Kit, the best way is to make it turn 90 degrees as accurate as possible?
    The loop value from 1 to 19 causes it turn around 92 degrees, while from 1 to 18 around 88 degrees. I am trying to find a way where I can make the counter repeat like 18.5 times but to no avail
  • william chanwilliam chan Posts: 1,326
    edited 2010-10-16 00:41
    Change the pause from 20ms to 10ms

    waitcnt(Pause * 10 + cnt)

    then you can repeat any number from 38 to 48 times with better accuracy.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-10-16 07:52
    Here is how to turn for a time at millisecond resolution.
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      lServo = 1
      rServo = 2
      turnTime =  800      ' time in millseconds for 90 degree turn adjust as necessary
    OBJ
      Servo  : "servo32v7"        
    
    Pub Main
      Servo.Start 
      Servo.set(lServo, 1300)                               ' set servos for turn
      Servo.set(rServo, 1300)
      waitcnt(clkfreq / 1000 * turnTime + cnt)              ' wait for turn
      Servo.set(lServo, 1500)                               ' stop servos
      Servo.set(rServo, 1500)
    

    John Abshier
  • bee896bee896 Posts: 25
    edited 2010-10-16 10:01
    William: This also means the time the servos respond are faster since the pause time is shorter?
    I actually thought of running the 2 servos in a different cog so that the right servo and left servo can run at the same time.
    The current code invokes the right servo first continued by the left servo, so I believe there will be a short little delay for the left servo to start

    John: If I'm not mistaken
    waitcnt(clkfreq / 1000 * turnTime + cnt)
    
    will wait for 80 ms right?
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-10-16 14:25
    It will wait for turnTime milliseconds

    John Abshier
  • W9GFOW9GFO Posts: 4,010
    edited 2010-10-16 14:30
    Something else to consider when attempting the greatest precision - what is the next command to the servos? If following the turn there is no pulses sent to the servos there may be a bit of coasting. For the best repeatability you would want to follow the turn with a series of centering pulses before the next movement.

    Rich H
  • ercoerco Posts: 20,260
    edited 2010-10-16 15:08
    Many times, accuracy can be improved by doing a one-motor (or one servo) turn. Just move the outside wheel (only) forward and shut off the inside wheel. The wheel will have to turn about twice as long, but your angular velocity and potential overshoot from momentum are cut in half.

    Also, there is a balance in overall wheel velocity that you should explore for best consistency, both in turning and travelling in a straight line. High velocity without ramping may lead to wheel slip on startup or stopping, but the increased torque at high speeds reduces sensitivity to rolling friction and yields more consistent speeds overall. Just the opposite applies at low wheel velocity. Try several different speeds to see what works best for your given bot.
  • william chanwilliam chan Posts: 1,326
    edited 2010-10-16 17:19
    Maybe like this is cleaner
     repeat 42                                ' adjust this value to your requirement
        outa[rightservo_pin]~~          ' clockwise for both wheels
        outa[leftservo_pin]~~ 
        waitcnt(Pulsout * 650 + cnt)           
        outa[rightservo_pin]~ 
        outa[leftservo_pin]~
        waitcnt(Pause * 10 + cnt)
    

    using another cog to control the servos will allow more things to happen simultaneously, making your robot more responsive.
    It is up to your ingenuity to implement the code.
  • bee896bee896 Posts: 25
    edited 2010-10-17 05:48
    It will wait for turnTime milliseconds

    John Abshier
    From your code, turnTime := 800 and waitcnt(clkfreq / 1000 * turnTime + cnt).
    So it will wait for 80 milliseconds right?
  • bee896bee896 Posts: 25
    edited 2010-10-17 05:53
    Maybe like this is cleaner
     repeat 42                                ' adjust this value to your requirement
        outa[rightservo_pin]~~          ' clockwise for both wheels
        outa[leftservo_pin]~~ 
        waitcnt(Pulsout * 650 + cnt)           
        outa[rightservo_pin]~ 
        outa[leftservo_pin]~
        waitcnt(Pause * 10 + cnt)
    

    using another cog to control the servos will allow more things to happen simultaneously, making your robot more responsive.
    It is up to your ingenuity to implement the code.
    I tried moving the servos in separate cogs, but the results are the same. So I guess the best way without using the Boe-Bot Digital Encoder Kit is to make it turn as near to 90 degrees as possible. Anyways it isn't a must to make it turn 90 degrees, just figuring how to make the BoeBot perform better
  • W9GFOW9GFO Posts: 4,010
    edited 2010-10-17 14:07
    bee896 wrote: »
    From your code, turnTime := 800 and waitcnt(clkfreq / 1000 * turnTime + cnt).
    So it will wait for 80 milliseconds right?
    No,

    Clkfreq is always equal to the number of clock tics per second. In other words, clkfreq is equal to one second.

    So (clkfreq / 1000) is one thousandth of a second, otherwise know as a millisecond.

    turntime (800) * one millisecond = 800 milliseconds.

    Rich H
  • bee896bee896 Posts: 25
    edited 2010-10-17 20:37
    Woopsie.. What I meant here is 0.8 seconds. Haha, sorry for the mistake
Sign In or Register to comment.