Sei sulla pagina 1di 18

Control System For BeastyMouse Jamie Killick, Chris Cronin

Jamie Killick
Chris Cronin
Introduction
A control system is a device, or set of devices to manage, direct or regulate the behaviour of
other devices or a system, a classic example of this is the watt governor used to regulate pressure
in a steam engine system. In our case we need to use the control system to regulate the speed of
the DC motors to allow the robot to move accurately and smoothly throughout the maze, this can
only be done via control specifically we have used a A proportional-integral-derivative controller
(PID controller) for this project.
Aims and Objectives:
To implement and simulate a basic DC motor model based on the Faulhauber
motors and mass of the robot.
To add in a basic friction model to this motor model based on the weight of the
robot.
Add in a Velocity control system using PID.
Tune and simulate this PID controller in MATLAB.
Look at the Motor PWM responses before applying PID velocity control.
Use the tuned PID values in the velocity control of the actual robot.
Compare the results of the simulation and the real world tests.

DC Motor Model
Velocity Controller design and tuning
Motors PWM reaction and PID tunning
Before we apply the simulated PID controller to the motors we have, we have first of all looked
at the motor response to different PWM duty cycles to see how they differ from each.To start I
looked at the difference between the motors in the air and on the ground with a 100% duty cycle
this was over a fixed time period of 2s. below shows a graph of this for each motor:

The blue and red lines are the velocity of motor 1 and motor 2 whilst the motor is in the air from
these two lines we can see that the rise time and the time it takes for each motor to settle is about
15ms, you can also see that there is a difference between the two motors of 0.05m/s. The green
and purple lines represent the motor velocity when in the maze, as expected due to friction you
can see that the rise time is a lot longer and the final velocity is slower by 0.10m/s, also again
there is a difference between the motors of 0.05m/s as before. In both situations there are
oscillations with both motors outputs, possibly caused by fluctuation in current and slight
variation of surface the robot is running over. The next step is to look at changing the PWM duty
cycle whilst monitoring the output of the motors, a graph below shows this over a time of 2s:

As you can see we have 4 PWM duty cycles 100%, 50%, 25%, and 15%. the main point of this
graph is to show that the motor speeds of each motors differ and also that the values put into
PDC are not linearly proportional to the output velocity, that is to say if you have a 50% duty
cycle you would expect 50% velocity outputted. In this case when you output a 50% duty cycle
you get a 80% of the maximum velocity. This is the crucial reason for having a control system so
that you can dictate the speed target speed and make the motor speeds equal to make the robot
travel straight which is the overall goal of this basic control system.
PID Controller Implementation
For this I have implemented the PID function in code, please make reference to appendix A for
full code, in a way that we start a timer and at the same time measure the velocity of the motors
and input that into the PID function which changes the duty cycle to try and achieve the target
velocity this new velocity is then printed via uart to a terminal. this is done until 2s is up then the
wheels stop. below shows a graph of tuning the PID controller term by term whilst the robot is in
the air.

This graph shows the first steps we took to tune the PID we started off with low values for P I
and D and added them in, in steps to see how each term affect the motors and how easy it was to
get a stable motor output, in the case of P it allowed us to increase the output speed whilst being
pretty consistent with some oscillations as shown by the Blue and Red line, the I term allowed us
to hone in on target speeds and allowed us to gain a more accurate stable output but still with
some oscillations as shown by the Green and Purple lines, The D term however made the output
of the motors change drastically and gave more oscillations instead as shown be the Light Blue
and Orange lines. After the initial testing of adding in each term we could now implement the
values of P I and D what tuned in MATLAB, P = 7500, I = 50 and D = 100, below shows the first
results of this:

As you can see these PID values are relatively accurate however these result are with the robot in
the air so the next thing we did was place the robot in the and measure the outputs again. below
shows the graph of this:

As you can see from the red and green lines running the robot on the ground reduce the output

speed by 0.1m/s this is due to such as slip in the gears and wheels, wind resistance of the robot
and the many types of friction related to moving object. To reduce the steady state error we now
had we need to increase P and I, the next graph shows the output of the changed PID values it is
at this point where the PID values for each motor start to differ motor 1 P = 11400, motor 2 P =
10600 the output of the new PID values are shown below:

As you can see the output of each motors has returned to the 0.3m/s target specified however
there is some overshoot but changing the values to compensate for this only gave more
oscillations and a bigger steadystate error. Another thing we factored into the testing at this point
was to reset the target speed of the PID to 0.0m/s after the 2s interval to see how long it took to
react and reduce speed to Zero this is in this case going from 0.3m/s to 0.0m/s takes 300ms for
motor 1, and motor 2 400ms.
DC motor modelling
We used Simulink to model our motors and we did this in a number of stages. Initially we
constructed a simple circuit with a step input, transfer function and scope.
(This circuit is shown below.)
This is the equation that was used in the transfer function,
(Input transfer function equation)
This is the finalised transfer function equation and the values for the variables that we obtained
from the motor data sheet.

(input image of transfer function, with a list of variables)


The next stage of the modelling was to input an error response with a proportional gain.
Increasing this value (Kp) will increase the change in output for a given change in error. This
will give the response a faster rise time but can cause overshooting, oscillation and a steady state
error. The circuit we used to test the response to Kp is shown below.
(Input a circuit with just Kp)
Using Kp to get a fast rise time can sometimes cause a steady state error and a way of reducing
this is to include an integral term into the model. This integral term (Ki) adds all of the error
values together and this acts as a corrective input to the transfer function. However a Ki value
that is too large can cause oscillations. The circuit we used to test how a change in Ki affects the
output of the model is shown below.
(Input a circuit with Kp and Ki)
The final addition to our circuit is a Derivative term (Kd) which acts by slowing the rate of
change of the error signal down. This acts to reduce and possibly remove the oscillations from
the signal but can increase the rise time as it reduces the acceleration of the error change. Having
implemented all three terms (Kp,Ki and Kd) we had to tune the values to end up with a smooth
signal with a fast rise time. The values we found gave us the best result are as follows:
Kd = 100
Ki = 50
Kp = 7500
Using these values we got the following output signal.
(insert image of tuned output signal)
Having tuned the signal we moved on to implementing a simple friction model into the circuit.
We chose to use rolling friction as it is one of the easiest to model. To measure the friction
coefficient between our tires and the micromouse boards we used this method.

Measure distance (D) from micromouse to edge of board.


Lift the back of the board until the micromouse begins to roll.
Measure the height (H) of the board where the micromouse was originally placed.

A diagram illustrating this method is shown below.

Using these values we can calculate the friction force and therefore the friction coefficient using
the following equation.
mass of micromouse = 0.309 Kg
H = 7 cm
D = 56 cm
Angle of board = sin-1(7/56)
Angle of board = 7.018 degrees.
Weight = 0.309 * 9.81
Weight = 3.03 N
Frictional force = 3.03 * (cos 82.982)
Frictional force = 0.37 N
Normal force = 3.03 / (cos 7.018)
Normal force = 3.05 N
Friction coefficient = Frictional force / Normal force.
Friction coefficient = 0.12.

We can then use these values to calculate the force acting against the rotating wheels. The
equation for this force is shown below.

F = (( Velocity / rotational velocity) * Frictional force)


This equation was then inserted into a MATLAB function block and inserted into the circuit as
shown below.

This friction acts against the output of the transfer function and produces this signal.
(Insert image of signal)
The following signals illustrate the different rise times and effects of friction at different step
responses.
(insert images for signals at 0.1, 0.3, 0.5, 0.9 and analyse the results.)
DC motor modelling
We used Simulink to model our motors and we did this in a number of stages. Initially we
constructed a simple circuit with a step input, transfer function and scope.
(This circuit is shown below.)
This is the equation that was used in the transfer function,
(Input transfer function equation)
This is the finalised transfer function equation and the values for the variables that we obtained
from the motor data sheet.
(input image of transfer function, with a list of variables)
The next stage of the modelling was to input an error response with a proportional gain.
Increasing this value (Kp) will increase the change in output for a given change in error. This
will give the response a faster rise time but can cause overshooting, oscillation and a steady state
error. The circuit we used to test the response to Kp is shown below.

DC motor modelling

We used Simulink to model our motors and we did this in a number of stages. Initially we
constructed a simple circuit with a step input, transfer function and scope.
(This circuit is shown below.)
This is the equation that was used in the transfer function,
(Input transfer function equation)
This is the finalised transfer function equation and the values for the variables that we obtained
from the motor data sheet.
(input image of transfer function, with a list of variables)
The next stage of the modelling was to input an error response with a proportional gain.
Increasing this value (Kp) will increase the change in output for a given change in error. This
will give the response a faster rise time but can cause overshooting, oscillation and a steady state
error. The circuit we used to test the response to Kp is shown below.
(Input a circuit with just Kp)
Using Kp to get a fast rise time can sometimes cause a steady state error and a way of reducing
this is to include an integral term into the model. This integral term (Ki) adds all of the error
values together and this acts as a corrective input to the transfer function. However a Ki value
that is too large can cause oscillations. The circuit we used to test how a change in Ki affects the
output of the model is shown below.
(Input a circuit with Kp and Ki)
The final addition to our circuit is a Derivative term (Kd) which acts by slowing the rate of
change of the error signal down. This acts to reduce and possibly remove the oscillations from
the signal but can increase the rise time as it reduces the acceleration of the error change. Having
implemented all three terms (Kp,Ki and Kd) we had to tune the values to end up with a smooth
signal with a fast rise time. The values we found gave us the best result are as follows:
Kd = 100
Ki = 50
Kp = 7500
Using these values we got the following output signal.
(insert image of tuned output signal)
Having tuned the signal we moved on to implementing a simple friction model into the circuit.
We chose to use rolling friction as it is one of the easiest to model. To measure the friction

coefficient between our tires and the micromouse boards we used this method.

Measure distance (D) from micromouse to edge of board.


Lift the back of the board until the micromouse begins to roll.
Measure the height (H) of the board where the micromouse was originally placed.

A diagram illustrating this method is shown below.

Using these values we can calculate the friction force and therefore the friction coefficient using
the following equation.
mass of micromouse = 0.309 Kg
H = 7 cm
D = 56 cm
Angle of board = sin-1(7/56)
Angle of board = 7.018 degrees.
Weight = 0.309 * 9.81
Weight = 3.03 N
Frictional force = 3.03 * (cos 82.982)
Frictional force = 0.37 N
Normal force = 3.03 / (cos 7.018)
Normal force = 3.05 N
Friction coefficient = Frictional force / Normal force.
Friction coefficient = 0.12.

We can then use these values to calculate the force acting against the rotating wheels. The
equation for this force is shown below.
F = (( Velocity / rotational velocity) * Frictional force)
This equation was then inserted into a MATLAB function block and inserted into the circuit as
shown below.

This friction acts against the output of the transfer function and produces this signal.
(Insert image of signal)
The following signals illustrate the different rise times and effects of friction at different step
responses.
(insert images for signals at 0.1, 0.3, 0.5, 0.9 and analyse the results.)

DC motor modelling
We used Simulink to model our motors and we did this in a number of stages. Initially we
constructed a simple circuit with a step input, transfer function and scope.
(This circuit is shown below.)
This is the equation that was used in the transfer function,

(Input transfer function equation)


This is the finalised transfer function equation and the values for the variables that we obtained
from the motor data sheet.
(input image of transfer function, with a list of variables)
The next stage of the modelling was to input an error response with a proportional gain.
Increasing this value (Kp) will increase the change in output for a given change in error. This
will give the response a faster rise time but can cause overshooting, oscillation and a steady state
error. The circuit we used to test the response to Kp is shown below.
(Input a circuit with just Kp)
Using Kp to get a fast rise time can sometimes cause a steady state error and a way of reducing
this is to include an integral term into the model. This integral term (Ki) adds all of the error
values together and this acts as a corrective input to the transfer function. However a Ki value
that is too large can cause oscillations. The circuit we used to test how a change in Ki affects the
output of the model is shown below.
(Input a circuit with Kp and Ki)
The final addition to our circuit is a Derivative term (Kd) which acts by slowing the rate of
change of the error signal down. This acts to reduce and possibly remove the oscillations from
the signal but can increase the rise time as it reduces the acceleration of the error change. Having
implemented all three terms (Kp,Ki and Kd) we had to tune the values to end up with a smooth
signal with a fast rise time. The values we found gave us the best result are as follows:
Kd = 100
Ki = 50
Kp = 7500
Using these values we got the following output signal.
(insert image of tuned output signal)
Having tuned the signal we moved on to implementing a simple friction model into the circuit.
We chose to use rolling friction as it is one of the easiest to model. To measure the friction
coefficient between our tires and the micromouse boards we used this method.

Measure distance (D) from micromouse to edge of board.


Lift the back of the board until the micromouse begins to roll.
Measure the height (H) of the board where the micromouse was originally placed.

A diagram illustrating this method is shown below.

Using these values we can calculate the friction force and therefore the friction coefficient using
the following equation.
mass of micromouse = 0.309 Kg
H = 7 cm
D = 56 cm
Angle of board = sin-1(7/56)
Angle of board = 7.018 degrees.
Weight = 0.309 * 9.81
Weight = 3.03 N
Frictional force = 3.03 * (cos 82.982)
Frictional force = 0.37 N
Normal force = 3.03 / (cos 7.018)
Normal force = 3.05 N
Friction coefficient = Frictional force / Normal force.
Friction coefficient = 0.12.

We can then use these values to calculate the force acting against the rotating wheels. The

equation for this force is shown below.


F = (( Velocity / rotational velocity) * Frictional force)
This equation was then inserted into a MATLAB function block and inserted into the circuit as
shown below.

This friction acts against the output of the transfer function and produces this signal.
(Insert image of signal)
The following signals illustrate the different rise times and effects of friction at different step
responses.
(insert images for signals at 0.1, 0.3, 0.5, 0.9 and analyse the results.)

Using Kp to get a fast rise time can sometimes cause a steady state error and a way of reducing
this is to include an integral term into the model. This integral term (Ki) adds all of the error
values together and this acts as a corrective input to the transfer function. However a Ki value
that is too large can cause oscillations. The circuit we used to test how a change in Ki affects the
output of the model is shown below.

The final addition to our circuit is a Derivative term (Kd) which acts by slowing the rate of
change of the error signal down. This acts to reduce and possibly remove the oscillations from
the signal but can increase the rise time as it reduces the acceleration of the error change. Having
implemented all three terms (Kp,Ki and Kd) we had to tune the values to end up with a smooth
signal with a fast rise time. The values we found gave us the best result are as follows:
Kd = 100
Ki = 50
Kp = 7500

Using these values we got the following output signal.


Having tuned the signal we moved on to implementing a simple friction model into the circuit.
We chose to use a combination of rolling friction and torque as these will give a fairly simple and
accurate model of friction. To measure the friction coefficient between our tires and the
micromouse boards we used this method.

Measure distance (D) from micromouse to edge of board.


Lift the back of the board until the micromouse begins to roll.
Measure the height (H) of the board where the micromouse was originally placed.

A diagram illustrating this method is shown below.


Using these values we can calculate the friction force and therefore the friction coefficient using
the following equation.
mass of micromouse = 0.309 Kg
H = 7 cm
D = 56 cm
Angle of board = sin-1(7/56)
Angle of board = 7.018 degrees.
Weight = 0.309 * 9.81
Weight = 3.03 N
Frictional force = 3.03 * (cos 82.982)
Frictional force = 0.37 N
Normal force = 3.03 / (cos 7.018)
Normal force = 3.05 N
Friction coefficient = Frictional force / Normal force.
Friction coefficient = 0.12.
We can then use these values to calculate the force acting against the rotating wheels when
traveling at a constant speed.
Rotational friction = Friction coefficient * Normal force.
This is the first section of our friction model completed so we moved on to calculating the torque
acting on the wheels.
Torque = (( Velocity / rotational velocity) * Frictional force)

This equation was then inserted into a MATLAB function block and inserted into the circuit as
shown below.

This friction acts against the output of the transfer function and produces this signal.
As you can see there is an initial high friction force that is a combination of the rolling and
torque force.
As the motor accelerates it overcomes the initial friction until it stops accelerating and travels at
a constant velocity. At this point only the rolling friction is acting on the micromouse and this is
shown by constant value of the red line after 0.5s.
Yellow line = input signal
Blue line = signal with no friction.
Purple line = signal with friction.
Red line = Friction force.

The following signals illustrate the different rise times and effects of friction at different step
responses.
The horizontal lines are the step responses from all of the different readings.
The signals all have the same steady state error and this is caused by the
constant rolling friction acting on the circuit.

APENDIX A
PID Code
void PID1 (float Velocity1, float target_val)
{
static float KP1 = 11400;
// Proportional Constant
static float KI1 = 50;
// Integrator Constant
static float KD1 = 100;
// Derivative Constant
static float error1;
static float Target1;
static float KP1_OUT;
static float E_Intergral1;
static float KI1_OUT;
static float Last_error1;
static float KD1_OUT;
static float OUTPUT1;
Target1 = target_val;
// target velocity 0.3m/s
Last_error1 = error1;
// save previous erro
error1 = Target1 - Velocity1;
// calculate new error
KP1_OUT = error1 * KP1;
// work out the KP output using error and KP
E_Intergral1 = E_Intergral1 + (error1 * 0.01);
KI1_OUT = KI1 * E_Intergral1;
// using error and KI work out KI output
KD1_OUT = KD1*((error1 - Last_error1)/0.01);

// work out KD output using KD


// error and previous error
OUTPUT1 = (KP1_OUT + KI1_OUT + KD1_OUT);// limit the output of the PID
if (OUTPUT1 > 20000){OUTPUT1 = 20000}
// limit to 20000 if output is above
20000
else if
else;
P2DC1 =
DirA1 =
DirB1 =
}

(OUTPUT1 < 0){OUTPUT1 = 0;}

// limit to 0 if PID output lover than 0

OUTPUT1; // write new Duty Cycle value to Motor


1;
0;

Potrebbero piacerti anche