- motor running at 10,000 rpm, with (say) 3 pole rotary encoder gives 500 pulses / second
2 problems at least in what others have tried:
- trying to do this on an RPi running the full gui. Well gui's are well knows for being *really* nasty if you're trying to do anything time critical, if you want an RPi to do something that has previously been done on dedicated hardware or low level machines like arduinos, starting by running a gui is like swimming in concrete boots!
- The VAST majority of code examples on picking up edges / pulses are using code looping reading the GPIO until it changes. Good grief, nice and simple, but REALY shouldn't be used other than a quick breadboard test to see if something appears to be working. Programming 101 grade F code.
- Use a raspbery Pi Zero - cos we want something small, low power and cheap and if it works on a zero it will work on any other recentish Pi.
- Use raspbian lite. We can put the gui somewhere else - or use a web browser with the Zero running a baby web server.
- Use pigpio's daemon to do the hard work.
- Write in python - 'cos if it works reasonably well in python we can always use C++ to hand crank the 1 or 2 little bits that are critical.
- Use a pipgio callback to pick up the edges - in fact better still just use the callback tally function, because we probably only need the feedback loop to run 20 times a second or so.
- Raspberry Pi Zero
- 2.5Ah power bank - Promate Aidbar-2
- Pure python3
- micrometal DC motor
- pololu magnetic rotary encoder
- H bridge in a pHat to drive the motor. (in fact I use pigpio PWM to drive the H bridge - it's about 1/2 the cpu load of the pimoroni library)
- home rolled motor control class with simple PID feedback running at 20Hz
The motor flat out no load runs at just over 500 ticks per second, this test is at 300 ticks per second and once initial correction has completed, the error is only 1% - 2%. This is with no load. The next graph shows the response to load changes:
Hello,
ReplyDeleteI like what you did on this project and I would like to know if can you provide more information about your wiring and programming. I have a motor with an encoder but I do not know how to get the feedback from the encoder to my Raspberry Pi, I am new in electronics and Raspberry Pi, so your help will be really important for me.
Thank you
same, how to read an encode with a raspberry pi and control the motor using the encoder?
ReplyDeleteThere is proof of concept level code below, and also there are links to further info in the readme. I'm not using this code any more, so can't help you much with any further info beyond what is in the repo.
ReplyDeletehttps://github.com/pootle/pimotors