0
\$\begingroup\$

I'm using the Arduino Encoder library to keep track of my motor's encoder counts. I need to calculate the motor's speed so it can be compared to a target speed and subjected to PID.

I've thought of one approach:

1) Calculate counts per timestep - Let's say we have a timestep of 100ms and we desire a speed of 50cm/sec. Determine speed in timestep units, 50/10.

To calculate speed motor is traveling at, simply calculate how many counts since last timestep, which will give speed in timestep units, which can be directly compared with desired speed;

speed = counts - prevCounts;
prevCounts = counts;

The advantage I can see with this approach is that it doesn't require us perform division (i.e. speed = (counts - prevCounts) / 0.1 ) in each timestep.

Is this a sensible? Are there any flaws in my method?

\$\endgroup\$
1
  • \$\begingroup\$ "1) Calculate counts per timestep - Let's say we have a timestep of 100ms and we desire a speed of 50cm/sec. Determine speed in timestep units, 50/10." I don't really understand how you can link counts per timestep and desired speed... Isn't there a homogeneity issue? Maybe it is just really simple, but I don't understand how do you obtain this formula. \$\endgroup\$
    – thibs-96
    Commented Jun 18, 2018 at 10:14

1 Answer 1

1
\$\begingroup\$

It seems to be correct as long as you are calculating everything in unit step time because all it does is scaling of units.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.