Motor Control Lab Procedures - 2024
Motor Control Lab Procedures - 2024
Students will modify MATLAB code to operate a Lego NXT servo motor.
Students will then evaluate impact of controller gain on operational stability.
This exercise will provide experience using MATLAB’s App Designer feature.
Background
The Lego NXT motor, shown below, is comprised of a DC motor and gear
train that turns motor hub.
The gear train increases the torque while reducing speed (rpm). The overall
gear ratio is 1:48 (https://www.philohome.com/nxtmotor/nxtmotor.htm). In
this manner, the DC motor must turn approximately 48 times to make the
hub rotate once.
Encoder pulses are used for positional control of the motor. The Lego NXT
quadrature encoder uses 720 counts (or pulses) for one complete revolution
of the motor hub (this is the conversion for pulses hub turns).
Controller Theory
The MATLAB script has a form of feedback control that adjusts the motor’s
direction based on the difference between the setpoint and actual position (i.e.
the error). A generic form of overall PID control equation is
ChEE 401B Process Dynamics and Control ● Spring 2024 ● University of Arizona 2
where u(t) is the control output, The K’s are proportional, integral and derivative
constants and e(t) is the error.
In this lab, students will modify the script and evaluate the motor control
performance when incorporating proportional (P) control only vs
proportional/integral (PI) control.
Materials:
Software
• Matlab
• The MATLAB script files from D2L directory (should already be on computer)
Hardware:
• Computer
• Oscilloscope Board. Remove both jumpers for Matlab compatibility mode
• USB cable
• 1 – Lego NXT Servo
• 1 – 6-pin cable
• 1 – Cable to inline 6-pin adapter
• 1 – Right angle 6-pin motor connector
• 1 – 9V battery
• 1 – 9V battery connector cable
Hardware Setup:
The NXT servo motor requires 9VDC power from a battery. A 9V connector
and battery are attached to the board through a two-pin jack. Before
attaching any hardware to the board, remove jumpers SW1 and SW2. Check
the connector polarity before attaching it to the board. Attach the battery
after the USB cable is connected to the computer and the motor is attached
to the board using the connections shown in the image below.
ChEE 401B Process Dynamics and Control ● Spring 2024 ● University of Arizona 3
Week 1 Procedures
Part 1 – Proportional Control: Fixed Gain while operating in Step Mode
• Copy the general Matlab files from the public server to the desktop (do not
move the folder!) Place all of your team member’s .mlapp files in the same
folder (needed in Part 2).
• Run the Motor_Servo.mlapp script file. Remember to change the serial port
(COM) name to the one on your system.
• The program uses the encoder count (pulses) from the NXT servo to
measure its position. The servo position is then compared to a commanded
position which generates a count error. This error is multiplied by a gain of
0.001 and sent to the servo motor causing the motor to reposition. The
motor input command is [-1.0 to 1.0]. (Example: an error of 500 counts (or
pulses) generates a motor command of 0.5). As the error decreases, so
does the command to the motor. This is a form of Proportional (P)
Control.
o Click the Run button to command the servo to the new position. The
servo loop runs for 512 samples at a rate of about 90Hz. After the
run, the position response is plotted.
ChEE 401B Process Dynamics and Control ● Spring 2024 ● University of Arizona 5
Part 2: Proportional Control: GUI testing, Fixed Gain while operating in Continuous
Mode
• Evaluate each team member’s homework code. You will evaluate the effect of
each team member’s different GUI components and changing the system to
operate in Continouous mode. NOTE: To operate in continuous mode,
o make sure the <On/Off button> is in the “off” position,
o then, change to “Continuous” operation
o finally, press the <On/Off button> to the “on” position.
• With Gain control set at 0.001 (i.e. small gain), run each team member’s code
• Run a continuous servo loop with the button in “On” position
ChEE 401B Process Dynamics and Control ● Spring 2024 ● University of Arizona 6
• Select one team member’s homework code and test how changing the
proportional gain value affects the servo motor response.
Week 2 Procedures
Part 4 – PI Control
• Load and evaluate each team member’s Week2 Homework#2 code.
• Similar to Part 3, run each program and test the servo response by moving the
turns slider. The difference in Part 4, however, is we have added Integral
control. Note, you can make step-like responses with fast drags of the slider.
• Try the experiment with several gain and integral settings (teams may want to
use same gain values used in part 3 from week 1).
All teams will use same GUI Motor_Servo_PI.mlapp that uses both proportional and
integral control features to move the NXT Motor. Teams will be given a target # of turns
and are tasked with:
1. Optimizing system performance
2. Minimize over/under shoot
3. Shortest settling time (to reach final state)
One winning team, from each lab section, will receive +10pts to the report grade.