7

This question might seem stupid, but I have been curious about it for a long time.

So I am a new engineering student, and we learned a lot about "designing a controller". For example, design controller for a car steering system and so on. All the "controllers" we designed are in the Laplace domain aka s-domain. And most of the times it will be just a transfer function. So how do real control system engineers use these transfer functions in arduino and other microcontrollers? I mean you cannot just put the function in there right?

Do you have to convert the transfer function to some other form and write the code for the microcontroller or is there a simpler way to do it?

Thanks for your time!

1 Answer 1

5

Let's assume you have an Arduino that you have arranged to sample a signal with a sample rate of 1/T that is then processed by your controller. Let's also assume that the processing time for your controller is small compared to T e.g. 0.1/T

Firstly, you need to convert the controller transfer function to discrete time. There are lots of ways to do this. Matlab has a convenient c2d() function. One way you can do it on paper (not the best way), is to use Euler's Method.

s=(z-1)/T where T is the sampling period.

Converting a transfer function then: (s+a)/(s+b) => (z-(1-aT))/(z-(1-bT))

So now you have a TF in z such as : Y(z)/X(z)=(z-c)/(z-d) where Y is the output and X is the input.

To implement this in a controller you need this as a difference equation in terms of delays. So convert the equation to a function of (z^-1) which is a delay:

Y(z)/X(z) = (1-cz^-1)/(1-dz^-1)

and re-write as: Y(Z)(1-dz^-1) = X(z)(1-cz^-1)

Y(Z)-d.Y(z).z^-1 = X(z)-c.X(z).z^-1

and change to sample time treating z^-1 as a delay: y(n) - d.y(n-1) = x(n) - c.x(n-1)

rearranging: y(n) = d.y(n-1) + x(n) - c.x(n-1)

You can implement this easily in the Arduino by realising that y(n-1) is the previous value of y(n) and similarly for x(n), and x(n) is the value input to the controller; i.e. the reference minus the output from the ADC.

1
  • Would you mind giving us some code example in order to implement these kind of exercises? I would be really thankful to you. In my case a have a transfer function a/s+a, "a" is a value a have to enter through a keyboard connected to the arduino mega, i have calculated the operations like this, using tustin method: a1Z+a2/b1Z+b2 where each value is: a1=a2=(aT/aT+2); b1:is always 1; and b2:aT-2/aT+2. T is the sample time. As you can see I have calculated everything but I have difficulties in the programming code in arduino mega, if you can help me I would be really thankful. Commented Apr 22, 2017 at 11:24

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