Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: How to determine speed with arduino

  1. #1
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    38

    Question How to determine speed with arduino

    I am having problems determining the speed of my robot using encoders in arduino. My encoders have 24 "clicks" per revolution. I am using a arduino dieclmile with the basic arduino environment. How do I figure out a the robots rpm in arduino code? I know I some how need to time it but I have no idea how. My input value is a simple 1 when it is on black and zero when it is on white. Dose anybody have example code for this? I keep getting stuck when I try to figure I out.
    Dalton Caughell

  2. #2
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    124

    Re: How to determine speed with arduino

    Quote Originally Posted by ROBOTMAN View Post
    I am having problems determining the speed of my robot using encoders in arduino. My encoders have 24 "clicks" per revolution. I am using a arduino dieclmile with the basic arduino environment. How do I figure out a the robots rpm in arduino code? I know I some how need to time it but I have no idea how. My input value is a simple 1 when it is on black and zero when it is on white. Dose anybody have example code for this? I keep getting stuck when I try to figure I out.
    I don't have a code example right now, I typically don't bother with speed control... but:

    Have interrupts on each channel of your encoders, when the interrupt for either channel triggers, you increment the value of a Left or Right counter (integer). This may not be quite that simple, especially if you are using quadrature encoders, you'll have to decode them... also, if you can't use the hardware interrupts, the arduino doesnt have a library for the pin-change interrupts (but you can probably find the code out there.. I have a version on my SVN server, under avrra/library/dev/lite.h)

    Once you are counting, then you probably want another interrupt, or maybe just your loop (if you are just trying to match the speeds, not find a definite speed). In there, you would compare your counts to your setpoints, and adjust your PWM values as neccessary...

    -Fergs

  3. #3
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    38

    Re: How to determine speed with arduino

    Not sure what you mean by interrupts but I do have a counting program that counts the number of ticks that have happened. However this program is complex and slow. Not really sure what to do with this data to get speed though!
    Dalton Caughell

  4. #4
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    124

    Re: How to determine speed with arduino

    If you aren't using interrupts, then your program is polling, which is gonna be way slow!

    http://lmgtfy.com/?q=arduino+interrupts

    -Fergs

  5. #5
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    173

    Re: How to determine speed with arduino

    Ok - so you can count ticks. Woot!

    You haven't learned anything helpful in determining speed.

    How big are your wheels? Aha. There's the key. Remember that the circumference of a circle is PI * Diameter or 2PIr?
    I Void Warranties´┐Ż

  6. #6
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    38

    Re: How to determine speed with arduino

    15.3025 is my diameter at least that's what I got! Counting ticks indeed did not help me learn how to determine speed. I don't see how interrupts will help me determine speed; my program was slow because my computer was slow.
    Dalton Caughell

  7. #7
    Join Date
    May 2008
    Location
    TN
    Posts
    853
    Images
    99
    Rep Power
    70

    Re: How to determine speed with arduino

    1 wheel revolution is equal to the circumference of your wheel. Use Adrenalyn's formula to find the circumference of your wheel. If the encoder is broken into 24 sections then the 1 "tick" on the encoder is equal circumference / 24 in inches traveled.

    Interrupts help because they do just that. They interrupt whatever is going on in your microcontroller so that you don't miss a "tick".
    "If A is a success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut."
    -
    Einstein

    Don't be a HelpVampire

  8. #8
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    38

    Re: How to determine speed with arduino

    Thanks! My micro controller for now is dedicated to my encoders so it should not mater much but as I expand I will switch.
    Dalton Caughell

  9. #9
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    124

    Re: How to determine speed with arduino

    Computer was slow? I wouldn't dare count on the computer, you should do most of the processing on the Arduino. General program is like this (I'm gonna only outline one motor, basically you have two loops like this running at the same time for your two motors):

    1) Arduino counts the ticks of the encoder (via an interrupt, which is basically hardware that triggers every time the pin changes from high to low on the arduino).
    2) The laptop/PC gives the Arduino a desired speed, for instance, if you wanted to go X inches forward/second, you would convert that to # of ticks per second.
    3) The arduino has a update loop that runs every Y seconds. In this loop, you compare the actual # of ticks recieved from the motor to the desired #, and then adjust the output speed. Typically you would use something like PID for that.

    Some considerations:
    A) How often should the loop run (denoted Y above)? The more often it runs, the more accurate your speed will be (in theory), however, the speed at which ticks are generated by the encoder will govern the top speed of the loop.
    B) Interrupts on the Arduino. The arduino has libraries using the two hardware interrupts the AVR has. This is probably sufficient, since they aren't multiplexed with the PWM.
    C) Are you using the Arduino to give the motors PWM values? If not, you'll have to send data through the PC when you run your update loop.

    -Fergs

  10. #10
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    38

    Re: How to determine speed with arduino

    Actually this is part of my robot butler project so the arduino will be streaming the data it gathers threw the serial port to my python code. I want the arduino to do all the math and just send something to my python code like this "A: 100" 100 being the speed and A meaning the encoder. Then my python will look at that number assess it and adjust the phidgets motor controller accordingly. Or at least thats the plan!
    Dalton Caughell

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. (very) basic motor speed control
    By boba in forum Robotics General Discussion
    Replies: 3
    Last Post: 03-03-2009, 10:35 PM
  2. PVision library for Arduino (Pixart/Wiimote to Arduino)
    By shobley in forum Robot Computers
    Replies: 1
    Last Post: 03-01-2009, 05:07 PM
  3. Project Arduino and RSRs (Really Small Robots)
    By LinuxGuy in forum Rovers
    Replies: 8
    Last Post: 08-12-2008, 03:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •