Skip to content

Serial readout of a rotary encoder for collecting running wheel data

Notifications You must be signed in to change notification settings

Gronemeyer/arduino-encoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

arduino-encoder

Serial readout of a rotary encoder for collecting running wheel data

Interpreting the Output of the Arduino Encoder in the Context of a Running Wheel

  • Counts Per Revolution (CPR):
    • Number of counts (pulses) per full revolution of the encoder knob.
    • Each count corresponds to a small increment of rotation.
  • Which direction is the wheel turning?
    • A positive positionChange indicates rotation in one direction (e.g., forward), while a negative value indicates rotation in the opposite direction (e.g., backward).
  • Output:
    • The script outputs the encoder counts sampled in positionChange within the 100 millisecond time window.
    • Used to determine how fast the wheel is turning and in which direction.

Calculating Speed and Distance

To calculate speed and distance from the encoder output, you'll need to perform the following steps:

Necessary Parameters:

Wheel Circumference (C): $\text{Circumference}=π×\text{Wheel Diameter}$

Encoder Counts Per Revolution (CPR): encoder counts generated by one full rotation.

Sample Window Duration (T): $\delta$ time interval between readings

  1. Calculate Distance Per Count (DPC):

    $$\text{DPC} = \frac{\text{Circumference}}{\text{CPR}}$$

  2. Calculate Speed:

    • Counts Per Second (CPS):

      $$\text{CPS} = \frac{\text{positionChange}}{T}$$

    • Speed (V; units of distance per second (e.g., meters per second)):

      $$V = \text{CPS} \times \text{DPC}$$

  3. Calculate Distance Traveled:

    • Distance for Each Sample Interval:

      $$\text{Distance} = \text{positionChange} \times \text{DPC}$$

    • Total Distance: Sum the distances calculated for each sample interval over time.

Example Calculation

Assuming:

  • Wheel Diameter (D) = 0.5 meters
  • Encoder CPR = 1024 counts/revolution
  • Sample Window Duration (T) = 0.1 seconds
  1. Wheel Circumference:

    $$C = \pi \times 0.5 \text{ m} \approx 1.5708 \text{ m}$$

  2. Distance Per Count:

    $$\text{Distance Per Count} = \frac{1.5708 \text{ m}}{1024} \approx 0.00153398 \text{ m/count}$$

  3. Assuming a positionChange of 150 counts:

    • Counts Per Second:

      $$\text{CPS} = \frac{150 \text{ counts}}{0.1 \text{ s}} = 1500 \text{ counts/s}$$

    • Speed:

      $$V = 1500 \text{ counts/s} \times 0.00153398 \text{ m/count} \approx 2.30097 \text{ m/s}$$

    • Distance Traveled in Sample Interval:

      $$\text{Distance} = 150 \text{ counts} \times 0.00153398 \text{ m/count} \approx 0.230097 \text{ m}$$

Things to consider

  • The Direction of Rotation:
    • Negative positionChange values indicate reverse rotation.
    • Ensure calculations account for the sign of positionChange.
  • The Encoder Resolution:
    • Higher CPR provides more precise measurements but may require handling larger numbers.
  • The Sampling Rate:
    • The sampleWindow should be chosen based on the expected speed of the wheel and the encoder's capabilities.
    • A shorter sampleWindow provides more frequent updates but may be more susceptible to noise.

About

Serial readout of a rotary encoder for collecting running wheel data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published