Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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