How to translate between velocity and PWM?


I am making a two wheeled differential drive robot. I want to be able to input velocity commands and then have the robot go at that speed, but motors talk to Arduino via PWM. Right now, what I have is I have set up my encoders, and I am able to read my encoder counts per second. I have been doing some reading and it seems that I also need to use PID to properly be able to do this. If you guys kindly have any suggestion on how I can get started or what arduino references I can look to in order to work towards my goal, I greatly appreciate it. I am very new at controlling motors.


What do you mean by “at that speed”?

If you mean m/s or other standard speed notation, you will have to experimentally determine the relationships between PWM values and the robot speed, and encoder clicks/sec and robot speed.

The first is usually nonlinear, and there will probably be a minimum PWM value at which the motors won’t start at all.

The encoders will produce a number of pulses per revolution. You can work out with a calculator how many pulses per second correspond to different speeds. That relationship will be linear unless the wheels are slipping.

Then use PID to make the motors operate at the speed that produces the correct number of pulses per second.