Saturday 31 March 2018

DC motor control with an RPi - writing the software

This explains some of the lessons learned and techniques I have used to develop Raspberry Pi software to provide accurate and responsive control for DC motors using feedback from rotary encoders.

It follows on from my previous post, showng the results of some initial testing on the feasability of good motor control using just a Raspberry Pi (i.e. without an arduino or other micro controller).

I very much liked the approach described by David Anderson explaining his approach to basic robot control, so the overall approach I used was to write software that is called from a regular timer function to run the control loop.

Such software can then be run directly from some higher level control loop, or wrapped up to provide a freestanding process controlled through a pipe or web service.

My usual approach to time / function critical software is to start with Python and get to a point where:
  • it all works well - great - job done.
  • it is hopeless - its never going to work this way - try something completely different or give up.
  • its working, but not quite well enough - perhaps a couple of small key parts can be re-implemented -possibly in C.
In this case - so far at least - the pure python version looks to be doing the job well.

I have a couple of repositories on github with the code for this, but these are still very much a work in progress.

motor drivers are here.

simple robot control is here. - So far this only does remote control from a web browser.