Page 1 of 1

Servo - Motor & Pot Control

Posted: Sat Sep 14, 2019 11:56 am
by devnull
To save me reinventing the wheel, has anyone done anything with motor / pot servos (not R/C) servos ?

The motor drives a gearbox and the output shaft rotates a 10K servo pot.

I want to be able to rotate the motor to specific positions using upython.

I am guessing that the servo pot will be read as ADC value, any code snippets or suggestions welcome :-)

Re: Servo - Motor & Pot Control

Posted: Sat Sep 14, 2019 12:26 pm
by jimmo
What you're describing is actually exactly what's inside an RC servo. They have a tiny pot and a simple circuit that drives the motor based on the difference between the analog pot value and the incoming PWM duty cycle. Because servo motors move (relatively) slowly, their control logic can be very simple, they're on/off controllers (not even P).

So you could do that in MicroPython in a couple of lines of code. Like you say, you'd read the pot using one of the ADC pins.

Depending on your motor and load, that might be sufficient. But from there you have a wide range of control system options, starting with a P controller, then PID, etc. Real servo motors (like ones that are used in place of steppers in mechatronic applications), e.g. from companies like ClearPath use much more sophisticated algorithms. And instead of pots, they use more accurate position encoders (e.g. optical or magnetic).

Not MicroPython, but you might find some inspiration from this project. https://github.com/jcchurch13/Mechaduino-Firmware (I have some of these, they run a MicroPython compatible microcontroller, if I had more hours in the day I would totally try and write some MicroPython firmware for them :) )