Electronic – Motor controller software design

dc motorencoderpid controllerroboticsspeed

I have to design a PID controller for a differential drive robot.

  • The hardware board consists of a AVR atmega168 running at 16mhz.
  • Driven by two 24v scooter motors with 256 CPR encoders
  • The motors spin roughly at about 4700 RPM and has a 51.56:1 gear ratio

So far I can read the encoder direction and the tick count. But I have no idea how to convert this to speed. And eventually a PID controller. I also want to be able to rotate the robot at a given angle. Can someone please help me to get started ?

Currently I am having problems figuring out a suitable timer calculation for this.

Best Answer

Thanks everyone for the useful comments.

I achieved what I wanted by implementing a simple velocity PID controller.

Through two interrupts (for each encoder) I calculated how much encoder ticks have been accumulated at a given time interval. The interval i used was 10ms and this was achieved by using the timer compare feature on timer1 of the AVR mcu. Encoder ticks were calculated by taking the difference of the previous encoder ticks and the current ticks. This was then used as the velocity PV of the PID controller. The PID controller sampling rate was also done at 10ms. Just to keep things simple.

I wrote a simple MATLAB gui to graph the SP, PV of the step response of the PID controller. This is how I manually tuned the PID controller. It may not be the best way but certainly the simplest way I could think of to tune the controller.

I will document this on my blog post when I get a chance and will put a link to it on this post so it will be helpful for anyone.