I'm trying to build a robot/rover based on Raspberry Pi 3 At the moment I'm straggling with a basic driving in a straight line.

I'm in a process of tuning my PID code andI'm not sure what sampling rate should I choose.

These are the specs of the motors:

Voltage: DC 6V
Speed: 210 rpm
Encoder motor end: 11 signals
Rated voltage: DC 6V
No-load speed: 210RPM 0.13A
Max efficiency: 2.0kg.cm/170rpm/2.0W/0.60A
Max power: 5.2kg.cm/110rpm/3.1W/1.10A
Stall torque: 10kg.cm 3.2A
Retarder reduction ratio: 1 : 34
Hall resolution: hall x ratio 34.02 = 341.2PPR

When the robot moves at the desired speed I get 20 encoder signals if I take a sample every 100ms and I get 10 if I sample every 50ms.

My question is what is the reasonable frequency to collect the encoder counts?
At 50ms I get higher frequency, so my PID adjustments can occur more frequently, but I get only 10 signals, so the resolution seems to be a bit low.
At 100ms I get 20 ticks which should provide more consistent stats, but then maybe adjustments are not happening fast enough.

Is there any rule of thumb for choosing a sampling rate for PID when driving a robot rover?

  • Are you running the motor controller on RPi? And is the encoder connected directly to it's inputs? Do you have a realtime system there? – mactro Oct 19 at 19:27
  • Yes, I am. Encoder is connected directly to GPIO pins and is using interrupts to detect encoder ticks. It's running Raspbian system on it, so not a realtime system. – Leonti Oct 20 at 2:33

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.