lunes, 26 de junio de 2017

Dc motor pid velicity control


Arduino uno
9vdc adapter

We are going to design a model-based pid controller. First, we need a mathematical model of our plant (dc motor). Second, based in our plant's model, we are going to design a pid to control the motor shaft velocity.

How to obtain the plant's model?

The relationship between the output and the input of a motor is described by a transfer function.
A first order transfer function describes the dynamics of our motor, where the input is voltage or a pwm signal, and the output is a rpm signal. Due to the lack of knowing the coefficients of the first order ode of the motor, we have to estimate the coeficcients or parameters.

Parameters estimation:
In simulink, we build the next model. This has to be deployed to the Arduino. Important: for all the experiments Ts=0.05 (sample time).

Model 1. Parameter estimation embedded.

Connect the hardware as follow:

In the L298n fritzing's part, an enable pin is missing which is connected to pin 7 in the Arduino.

Once the model 1 is embedded in the Arduino, we build the host model 2 in Simulink, where the variables: velocity, position and pwm are going to be shown, saved and processed for further analysis.

Model 2. Parameters estimation host.
Where does the rpm conversion comes from?

Rpm = [pulses / second] / [1496 pulses / revolution] * [60 seconds / 1 minute]


Rpm = [lecture from the encoder (pulses/sec)] / [11 pulses * 34 gear ratio * 4 quadrature encoder] * [60 seconds / min]

After running the model, the variables: velocity, position and pwm are in the Matlab's workspace into one variable x. Therefore, we need to extract each variable as following:

clear ans, clear pos, clear vel, clear pwm; clear i;
for i=1:1:length(senal)
clear ans, clear i, clear senal;

Now we have the input pwm and output velocity which describe the motor's dynamics.

In order to find the parameters, we have to use ident application.

To be continued...