Download ME 445 – Lab 5 part 1– Optical encoders and proportional motor

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Control system wikipedia , lookup

Electric motor wikipedia , lookup

Brushless DC electric motor wikipedia , lookup

AC motor wikipedia , lookup

Induction motor wikipedia , lookup

Brushed DC electric motor wikipedia , lookup

Variable-frequency drive wikipedia , lookup

Stepper motor wikipedia , lookup

Rotary encoder wikipedia , lookup

Transcript
ME 445 – Lab 5 part 1– Optical encoders and proportional motor control
Motor Control
As mechanical engineers, one of the most important things that we typically want to do with mechatronic
systems is control motion. DC motors are frequently a convenient actuator for this task, because they
come in a wide variety of sizes and are relatively simple to control. In this lab we will look at several
different methods for controlling the position of a DC motor.
To be clear, when we say we want to control the position of a DC motor, we mean that we want to set a
target angle for the motor shaft in our code, and have the motor move to that target. This sounds like a
simple task, but by the end of this lab you will see that there are many details that need to be right for
motor position control to work well.
We’ve actually used an example of motor control before, specifically the hobby servos from lab 1. They
have a potentiometer attached to the servo horn which feeds the angular position back to a motor
controller. This creates a closed-loop system which attempts to maintain a set position based on the
commands you send from the Arduino.
The next lab will directly build on what you do during this lab, so make sure to keep any of the
circuits you build together. Also, make sure to organize your code well to make your life easier next
week.
Report
This lab will have three major plots for the three gain cases explained in the proportional control section.
For each gain you will have data from a simulated response (from Simulink), the response with a highperformance motor driver and the response with the L293D. Plot all three results in one figure and
create separate figures for each gain. If you prefer, you can use subplots in MATLAB for each gain.
Make sure to clearly label each response.
Optical Encoders
Before we can control the position of a motor, we need to have some type of feedback about the position
of the motor. One of the most common ways to measure the angular position of a motor is to use an
optical encoder as discussed in class. The output pattern of an optical encoder is known as quadrature and
it can be used to sense both position and direction. An example of a quadrature waveform can be seen
below.
Converting optical encoder signals into useable position information can be a fairly difficult task. One of
the biggest challenges is that it can be very processing intensive for a microprocessor to watch for
changes on the encoder lines, and keep track of all of the arithmetic associated with the changing values,
especially if the encoder has a high resolution. There are chips, such as the HTCL-2222 that assist with
this task, however, they can also be somewhat cumbersome to use. For this lab, we will get around this
problem by using a motor with a relatively low resolution encoder and using the Arduino’s interrupts to
page 1 of 3
ME 445 – Lab 5 part 1– Optical encoders and proportional motor control
look for changes on the encoder output pins. The table below summarizes the connections for the Lego
motors:
Lego Motor Connections
Color
Function
Black
Motor A
White
Motor B
Green
Encoder +5V
Red
Encoder GND
Yellow
Encoder A
Blue
Encoder B
In order to help simplify your code, only use an interrupt on one of the encoder pins. Place the following
line of code in void setup() to use an interrupt.
attachInterrupt(0, increment, CHANGE);
This code watches digital pin 2 (which Arduino calls interrupt 0) for any change and calls the function
increment() (which you will have to write) when the pin changes state. You can change the name of the
function if you want to.
Your first task is to write the interrupt function which will add or subtract from a counter that holds the
number of degrees that your motor has turned. Hint: declare a global variable to hold the value of this
counter, and think about how the states of the two encoder lines relate to changes in your counter. Also,
remember that the encoder on the Lego motors has a resolution of one degree. As always, remember to
declare any digital pins you are using as inputs or outputs.
Write a simple piece of code that prints the value of this encoder to the serial monitor as you turn the
motor by hand.
Simulink Modeling
You will need to model this system in Simulink (which comes with MATLAB) so that you can compare
your experimental results with your simulation. If you are unfamiliar with Simulink, a brief tutorial will
be provided online. Below is the transfer function between the output angle in radians of the Lego motor
and the input voltage.
𝜃(𝑠)
1
=
𝑉(𝑠) 2.921𝐸 − 5 ∗ 𝑠 3 + 0.0315 ∗ 𝑠 2 + 0.5048 ∗ 𝑠
In this lab, you will be analyzing step tests. That is, you will command your motor to move to a position
and you will examine how the angle changes over time. You will need to create simulations for the three
proportional gains described below.
Proportional Control
As the name implies, a proportional controller produces an output which is proportional to the error
between the present position of the motor and the target position. As mentioned above, you will measure
the position of the motor using the built-in encoder of the Lego motor. You will use a motor driver to
page 2 of 3
ME 445 – Lab 5 part 1– Optical encoders and proportional motor control
produce a voltage across the terminals of the motor. In equation form a proportional controller looks as
follows:
𝑉𝑜𝑙𝑡𝑎𝑔𝑒 = (𝑡𝑎𝑟𝑔𝑒𝑡 𝑝𝑜𝑠𝑖𝑡𝑖𝑜𝑛 − 𝑐𝑢𝑟𝑟𝑒𝑛𝑡 𝑝𝑜𝑠𝑖𝑡𝑖𝑜𝑛) ∗ 𝑔𝑎𝑖𝑛
The gain in this equation is crucial to the performance of the control system as a whole, which you will
see throughout this lab.
Note: Be careful with the units you use. We modeled our system with radians, so you should use radians
in your proportional calculation.
Write a piece of code that executes a step test as described in the Simulink modeling section. The serial
monitor is the easiest way to get the data from your system. You will use two different motor drivers for
this lab which appear at first to perform the same function, but we will see that they produce different
behavior. One will be a high-performance motor driver from Pololu and the other will be the L293D. The
bulk of your code will be the same for these two drivers, but consider writing a separate function for each
driver to simplify your code. Only use the 5V supply from your breadboard.
Note: For this experiment, you will need to use a serial baud rate of 115200 in order to obtain a close
model match. Later on you will look at what will happen if you use a lower baud rate.
Run your code with gains of 5, 15, and 30 for each motor driver. Copy the data for each gain from the
serial monitor to either MATLAB or Excel and plot the results along with the simulated results.
Report: Include your code for proportional control. You code can run any of the gain cases described
above.
What happens to the motor position in your code every time you restart your program?
Describe the effect of changing the proportional gain of your system.
Compare the response of the Pololu driver with the response of the L293D.
Compare your Simulink results with your experimental results.
page 3 of 3