0% found this document useful (0 votes)
20 views

Lab#7 Report

The document describes a lab experiment to control a real mechatronic system using a microcontroller. The system consisted of a lever with a weight that had to be balanced to a specified angle using a motor. A potentiometer was used as a position sensor to determine the lever angle. A MATLAB control algorithm was developed to read the potentiometer voltage and control the motor direction and speed with PWM signals to balance the lever. Adjusting the proportional and integral gain constants was important to achieve stable balancing behavior. The concepts of brushed DC motor control from a previous lab were applied.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Lab#7 Report

The document describes a lab experiment to control a real mechatronic system using a microcontroller. The system consisted of a lever with a weight that had to be balanced to a specified angle using a motor. A potentiometer was used as a position sensor to determine the lever angle. A MATLAB control algorithm was developed to read the potentiometer voltage and control the motor direction and speed with PWM signals to balance the lever. Adjusting the proportional and integral gain constants was important to achieve stable balancing behavior. The concepts of brushed DC motor control from a previous lab were applied.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ME4673: Introduction to Mechatronics Winter 2018

Lab #7 – Report Josue Carrillo (3608051)


Real Mechatronic System Nelson Quintanilla (3508051)
Benedikt Fleig (3615532)
__________________________________________________________________________________

Table of Contents
1. Abstract ...........................................................................................................................................................1
2. Procedure ........................................................................................................................................................1
3. Control Algorithm ..........................................................................................................................................2
3.1. MATLAB code ......................................................................................................................................2
3.2. Code Description ...................................................................................................................................3
4. Conclusions and Results.................................................................................................................................3

1. Abstract

The purpose of this lab was for us to be able to apply the concepts learnt in past laboratories to control
a real mechatronics system. This system consisted of a lever with a weight on one side, that had to be
balanced to a specified position/angle using a motor. This had to be done using a position sensor (A
potentiometer), to determine the actual angle of the lever and create PWM signals that would turn the
motor in a certain direction with a certain speed until the lever was balanced at the desired angle.

2. Procedure

The system to be controlled is shown in Figure 1. As we can see, it is simply a lever that has a weight
in one side, which has to be moved so that the whole lever is balanced at a certain angle measured from
a horizontal plane. The weight is moved using a brushed dc motor, which is interfaced in the same way
the motor from Lab #6 was interfaced (Here shown in Figure 2).
To know the angular position of the lever, a potentiometer was put on its pivot point. By measuring
the voltage output from the potentiometer at extreme positions and at the levelled (horizontal), position,
a simple program could be devised so that when the output voltage from the potentiometer was different
than the voltage at the horizontal position, the weight could be moved by the motor accordingly, until
the horizontal position was attained.

Figure 1 Figure 2
3. Control Algorithm

3.1. MATLAB code


clear; clc;
% Digital and analog inputs
a=arduino('COM8','uno');

%Configure Digital Pin as an Output Pin


configurePin(a,'A0','AnalogInput')
configurePin(a,'D3','DigitalOutput')
configurePin(a,'D4','DigitalOutput')
configurePin(a,'D5','PWM')
configurePin(a,'D6','DigitalOutput')

writeDigitalPin(a,'D3',0) % in1
writeDigitalPin(a,'D4',0) % in2
writePWMDutyCycle(a,'D5', 1) % PWM
writeDigitalPin(a,'D6',1) % stby

setvolt = 3.3; % (V) Set point


kp = 125; % gain
ki = 10;
dt = 0.1;
u_prev = 0;
difv_prev = 0;

while (1)
tic;
volt = readVoltage(a,'A0'); % Output
difv = setvolt-volt; % Error

if abs(difv) < 0.0045


difv = 0;
end

u = u_prev + kp*difv + ki*dt*difv - kp*difv_prev;

if u < 0 % set for CCW

writeDigitalPin(a,'D3',0) % in1
writeDigitalPin(a,'D4',1) % int2

elseif u == 0 % set for stop

writeDigitalPin(a,'D3',0) % in1
writeDigitalPin(a,'D4',0) % in2

elseif u > 0 % set for CW

writeDigitalPin(a,'D3',1) % in1
writeDigitalPin(a,'D4',0) % in2

end

2
if u > 12 % dont let u exceed 12
u = 12;

elseif u < -12


u = -12;
end

signal = abs(u)/12;
writePWMDutyCycle(a,'D5',signal);

u_prev = u;
difv_prev = difv;
dt = toc;

end

3.2. Code Description

First, the Arduino board was configured. Then the required pins were determined. We need an analogue
input for reading the values of the potentiometer. The digital outputs are for controlling the servo motor.
At the beginning it is ensured that the servo motor is switched off. The kp and ki values control the
sensitivity of the balancing unit. Before that, however, first the voltage value of the potentiometer had to
be read out in the horizontal position. This was about 2.25V. The voltage difference is needed to
determine the actual voltage and the associated direction of rotation of the motor. The voltage is
composed of the addition of the previously measured voltage and the regulators kp and ki, which are
multiplied by the voltage difference, and the subtraction of the regulator kp, which is multiplied by the
previously measured difference voltage. The If query determines the direction of rotation of the servo
motor, which balances the system. It is then checked whether the voltage is greater than 12 volts. If so,
it will be set to the maximum value. The positive or negative voltage determines whether the motor must
turn to the right or left. Finally, the voltage is set as the previously measured voltage and the difference
voltage as the previously measured differential voltage. After the program was tried the only difficulty
was to set the regulators correctly. This was necessary as the system responded faster or slower to the
change in direction and thus to the balance depending on the setting. The second task was to balance the
system at a certain angle. Here only the value setvolt had to be set to another value.

4. Conclusions and Results

Control systems are used in many applications around us. In this lab we learned the importance of the
static error constants values in a real mechatronic system. These values affect the feedback system
behaviour directly. In the first attempt, we had the following values on our code: kp = 125, ki = 125, dt
= 0.1. With these values the system never reached the equilibrium point, but then, we changed Ki = 10.
Now the system was much more stable and it reach the equilibrium point in a very short time. Therefore,
the integral constant magnifies the effect of long-term steady-state errors helping to reduce them to zero.

We also used the concepts learned in the lab #6 related to brushed dc motors because we had to recall
how to set it up and interface it correctly.

You might also like