This week my colleague Pravallika is back to continue her motor control story!
For this transfer function, we designed the following controller using pidtune:
We will now implement the controller on the Arduino Uno and see how the DC motor fares with this controller. To deploy the controller on the hardware, we will use Simulink’s capability to generate an executable and run it on selected hardware.
Deploying controller to the Arduino board
You probably noticed that the controller shown above is in a continuous form. To use it on our target, the first thing to do is to discretize it using the c2d function:
Then we grab the PID block from the Simulink Library and configure it.
To keep the PID controller’s output within the limits of the hardware, we go to the PID Advanced tab and enable output saturation along with anti-windup protection.
To test the controller on the hardware, we created a Simulink model using blocks from the Arduino Support Package.
As you can see, we receive the desired motor position from the serial port and compare it to the measured position from the Analog Input. The position error goes through the PID block which generates a voltage to be sent to the motor. We also send the measured position through the serial port.
We ran the model on the target, sent it some commands and logged the data transmitted through the serial port. Here is what it looks like:
So, it does a pretty good job of tracking the reference signal. When we compare the response from the hardware to that of the simulation, we observe that they are very close! The System Identification Toolbox model is quite good.
Now it is your turn
How are you designing controllers when a system is difficult to model? Have you tried the Run on Target Hardware capability in Simulink to run your models on the supported boards? Let us know by leaving a comment here.
12 CommentsOldest to Newest
Sorry about a question outside the topic.
How did you make your photos frame like that? I really interested in it.
Hey, this is great! thanks for this.
But you could have realised this in a better manner, by using only 1 output pin. Just check the sign of the outputting PID control signal and basing on that, control the PWM signal by negating it etc.
can i able to do to control the temperature
Hi. How are you representing the angle? 0-360 degrees or 0..+1..+2…+179..+180..-179..-178..-2..-1..0 degrees.
Is this command ‘pidtune’ new introduced in 2013a?
Because in my version 2010a, doc pidtune doesn’t work.
@ Hui Jin
pidtune was introduced in R2010b in Control System Toolbox.
Hello, Can you send me the source file of this controller please?
I don’t understand how it was processed the PID output signal:
How can you transform the PID control law to PWM sequence? What is there inside “Convert to PWM” blocks?
which query would you use serial blocks to angle, 10-bit serial package to angle and message
1. I don’t understand why also send the measured position through the “serial port 0″?
2. we receive the desired motor position from the “serial port 0″,and send the measured position through the same serial port?
3. receive the measured position by USB ?if i want to get the data from arduino serial port,which block should be used?serial receive block or serial transmit block?
I have a question about the “Convert to PWM” block , I can’t understand how did you do it