I am trying to control a mechanical system with some transfer function T (output is position & input is voltage). I have implemented a state feedback controller in order for the output of the system to reach a certain position. The actuator of the system is an RC Servo Motor which is actuated by PWM signals. I want to convert the output of the controller into proper PWM in order to control the system. Are there any guidelines which I should follow or is there a specific way in order to manage to convert the signal ?


2 Answers 2


Your controller output needs to be converted to the PWM signal your RC motor can understand and what your controller can output, so you can use a simple linear function like $y(x)=m*x+b$ to achieve this, your x-axis being your position, and your PWM in bits (8, 10, 12, etc) along the y-axis. $b$ if you happen to be off hazy in your linear functions is your zero position of your RC motor, which as it crosses the y axis.

An example converting amps to pwm in Wiring might look like this:

// signal between -2.2 and 2.2 amps
highPWM = 256;
lowPWM = 0;
// convert Amps to PWM signal
float atp(float sgnl) {
  float thing;
  thing = (((highPWM) - (lowPWM)) / 4.4) * sgnl + nullPWM;
  return thing;

However this isn‘t the only functional way to program such a conversion and of course your signal may not be linear which will require a different function.

Depending on which way you write it, some languages also have built in functions such as Map() which will do the math for you.


First, go take a look at some documentation on the servo PWM signal. The gist of it, is that a PWM signal is a pulse between 1000us and 2000us, repeated every 20ms. The signal is interpereted as 0 when the pulse it 1500us. More than that is positive, and less negative (or the reverse, can't remember).

How you convert your output signal to this format will depend on the device. On an arduino there are numerous examples on the internet.

You are trying to control the servos position, and the servo takes a position signal in the form of PWM. So all you have to do is convert your position value into servo position and send that to the servo.

There are many ways to do this, so I will suggest a simple one. Use a table.

Simply move the servo through it's range, and at several points record the servo position using your system as well as the pulse width you're sending. This creates a table converting your position value directly to a PWM value. Between these points you can interpolate.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.