Welcome to the first hands-on experiment!
The current schedule of the Lab 1 is as follow:
Location: ESM G1
Aug 29th - Sep 2nd : Integration and Modelling
Sep 12th - Sep 16th : Position Control
When submitting lab manual on Gradescope please attach rubric on first page before your cover page and clearly tag each section.
The block diagram shown in Figure 16 is a general unity feedback system with a compensator (controller) and a transfer function representing the plant, . The measured output, , is supposed to track the reference signal and the tracking has to match certain desired specifications.
The output of this system can be written as:
As you can see from this equation, the plant is a second-order system. In fact, when a second-order system is placed in series with a proportional compensator in the feedback loop as in Figure 16, the resulting closed-loop transfer function can be expressed as:
Consider a second-order system as shown in Equation 3.4 subject to a step input given by
This is called the peak time of the system.
In a second-order system, the amount of overshoot depends solely on the damping ratio parameter and it can be calculated using the equation
The peak time depends on both the damping ratio and natural frequency of the system and it can be derived as:
Generally speaking, the damping ratio affects the shape of the response while the natural frequency affects the speed of the response.
We can find the steady-state error of this system using the final-value theorem:
Applying the final-value theorem gives
When evaluated, the resulting steady-state error due to a step response is
Based on this zero steady-state error for a step input, we can conclude that the Rotary Servo Base Unit is a Type 1 system.
The desired time-domain specifications for controlling the position of the Rotary Servo Base Unit load shaft are:
and
Thus, when tracking the load shaft reference, the transient response should have a peak time less than or equal to 0.20 seconds, an overshoot less than or equal to 5%, and the steady-state response should have no error.
The proportional-derivative (PD) compensator to control the position of the Rotary Servo Base Unit has the following structure
This is a variation of the classic PD control where the D-term is in the feedback path as opposed to in the forward path.
From the Plant block in Figure 19 and Equation 3.3, we can write
The limitations of the actuator must be taken into account when designing a controller. For instance, the voltage entering the Rotary Servo Base Unit motor should never exceed
From our previous steady-state analysis, we found that the closed-loop Rotary Servo Base Unit system is a Type 1 system. In this section, we will investigate the steady-state error due to a ramp input when using PD controller.
Given the following ramp setpoint (input)
Adding integral control can help eliminate steady-state error. The proportional-integral-derivative (PID) algorithm to control the position of the Rotary Servo Base Unit is shown in Figure 1.6. The motor voltage will be generated by the PID according to:
This is a variation of the standard PID control with the D-term in the feedback path as opposed to the feedforward path.
From the Plant block in Figure 21 and Equation 3.3, we can write
To find the steady-state error of the Rotary Servo Base Unit for a ramp input under the control of the PID substitute the closed-loop transfer function from Equation 3.31 into Equation 3.11
It takes a certain amount of time for the output response to track the ramp reference with zero steady-state error. This is called the settling time and it is determined by the value used for the integral gain.
In steady-state, the ramp response error is constant. Therefore, to design an integral gain the velocity compensation (the V signal) can be neglected. Thus, we have a PI controller left as:
When in steady-state, the expression can be simplified to
Do problems 1 - 7
Calculate the minimum damping ratio and natural frequency required to meet the specifications given in Section 1.1.3.
The main goal of this laboratory is to explore position control of the Rotary Servo Base Unit load shaft using PD and PID controllers. In this laboratory, you will conduct the following experiments:
Step response with PD controller,
Ramp response with PD controller, and
Ramp response with PID controller.
In each experiment, you will first simulate the closed-loop response of the system. Then, you will implement the controller using the Rotary Servo Base Unit hardware and software to compare the real response to the simulated one.
First, you will simulate the closed-loop response of the Rotary Servo Base Unit with a PD controller to step input. Our goals are to confirm that the desired response specifications in an ideal situation are satisfied and to verify that the motor is not saturated. Then, you will explore the effect of using a high-pass filter, instead of a direct derivative, to create the velocity signal in the controller.
The s_servo_pos_cntrl
SIMULINK diagram shown in Figure 22 will be used to simulate the closed-loop position control response with the PD and PID controllers. The Rotary Servo Base Unit Model uses a Transfer Fcn block from the SIMULINK library. The PID Control subsystem contains the PID controller detailed in Section 1.3. When the integral gain is set to zero, it essentially becomes a PD controller.
Download the PositionControl_files.zip and extract the files to the desktop.
Open the setup_servo_pos_cntrl.m
file to open the setup script for the position control Simulink models.
Replace the default model parameters (K
and tau
) with the values calculated from the Modelling section in the setup script.
Run the script, which will generate the model parameters, specifications, and default PID gains. Note: The calculated PID gains are all set to zero by default and they need to be changed over the course of the experiment.
Enter the proportional and derivative control gains found in Pre-Lab Question 4 in the Matlab command window as kp
and kd
.
Set the integral gain to 0 in the Matlab window, denoted as ki
.
To generate a step reference, ensure the Signal Generator
is set to the following:
Signal type = square
Amplitude = 1
Frequency = 0.4 Hz
Set the Manual Switch
such that the velocity of the motor load shaft is fed back directly.
Open the servo position Position (rad)
scope and the motor input voltage Vm (V)
scope.
Start the simulation. By default, the simulation runs for 5 seconds. The scopes should be displaying responses similar to Figure 23a and Figure 23b. Note that in the theta_l (rad)
scope, the yellow trace is the setpoint position while the purple trace is the simulated position (generated by the Rotary Servo Base Unit Model block). This simulation is called the Ideal PD response as it uses the PD compensator with the derivative block.
After each simulation run, each scope automatically saves its response to a variable in the MATLAB workspace. That is, the Position (rad)
scope saves its response to the variable called data_pos
and the Vm (V)
scope saves its data to the data_vm
variable. The data_pos
variable has the following structure: data_pos(:,1)
is the time vector, data_pos(:,2)
is the setpoint, and data_pos(:,3)
is the simulated angle. For the data_vm
variable, data_vm(:,1)
is the time and data_vm(:,2)
is the simulated input voltage.
Save Vm
and data_pos
data and name it suitably (e.g. posnctrl_section#_Group#_step).
Result: Generate a MATLAB figure showing the Ideal PD position response and the ideal input voltage.
Measure the steady-state error, the percent overshoot and the peak time of the simulated response.
Result: Does the response satisfy the specifications given in Section 1.1.3?
Hint: You can use the Cursor Measurements tool in the Simulink scopes or save the data and use MATLAB function : stepinfo()
.
When implementing a controller on actual hardware, it is generally not advised to take the direct derivative of a measured signal. Any noise or spikes in the signal becomes amplified and gets multiplied by a gain and fed into the motor which may lead to damage. To remove any high-frequency noise components in the velocity signal, a low-pass filter is placed in series with the derivative, i.e. taking the high-pass filter of the measured signal. However, as with a controller, the filter must also be tuned properly. In addition, the filter has some adverse effects (ex. filter could add some delays to the system).
Set the Manual Switch
block to the down position to enable the derivative and filter.
Start the simulation. The response in the scopes should still be similar to Figure 23a and Figure 23b. This simulation is called the Filtered PD response as it uses the PD controller with the high-pass filter block. Result: Generate a MATLAB figure showing the Filtered PD position and input voltage responses.
Measure the steady-state error, peak time, and percent overshoot. Result: Are the specifications still satisfied without saturating the actuator? Recall that the peak time and percent overshoot should not exceed the values given in Section 1.1.3. Discuss the changes from the ideal response. Hint: The difference in the response is minor. Make sure you use Cursor Measurements tool in the Simulink scope to take precise measurements.
In this experiment, we will control the angular position of the Rotary Servo Base Unit load shaft, i.e. the disc load, using the PD controller. Measurements will then be taken to ensure that the specifications are satisfied.
The q_servo_pos_cntrl
SIMULINK diagram shown in Figure 24 is used to implement the position control experiments. The Rotary Servo Interface - Position
subsystem contains QUARC blocks that interface with the DC motor and sensors of the Rotary Servo Base Unit system, as discussed in the Integration laboratory experiment. The PID Control subsystem implements the PID controller detailed in Section 1.3, except a low-pass filter is placed in series with the derivative to remove the noise.
From the extracted files, open q_servo_pos_cntrl
Simulink file.
Configure DAQ: Double-click on the HIL Initialize block in the Rotary Servo Interface
subsystem (which is located inside the Rotary Servo Interface - Position
subsystem) Simulink diagram and ensure it is configured for the DAQ device that is installed in your system (e.g. Q2-USB).
Open setup_servo_pos_cntrl.m
file and run the script.
Enter the proportional and derivative control gains found in Pre-Lab Question 4.
Set Signal Type in the Signal Generator
block to square to generate a step reference.
Set the Amplitude (rad)
gain block to 0.4 to generate a step with an amplitude of 45.8 degrees.
Open the load shaft position scope, Position (rad)
, and the motor input voltage scope, Vm (V)
.
When a suitable response is obtained, click on the Stop button in the SIMULINK diagram toolbar to stop running the code. As in the s_servo_pos_cntrl SIMULINK diagram, when the controller is stopped each scope automatically saves its response to a variable in the MATLAB workspace. Thus the theta_l (rad)
scope saves its response to the data_pos
variable and the Vm (V)
scope saves its data to the data_vm
variable.
Save the data in the MATLAB workspace with a suitable name. Result: Generate a MATLAB figure showing the PD position response and its input voltage.
Measure the steady-state error, the percent overshoot, and the peak time of the Rotary Servo Base Unit load gear. Result: Does the response satisfy the specifications given in Section 1.1.3?
Click the Stop button on the SIMULINK diagram toolbar to stop the experiment.
In this simulation, the goal is to verify that the system with the PD controller can meet the zero steady-state error specification without saturating the motor.
Similar to the Step Response experiment in Section 3.1, in this experiment you need to use the s_servo_pos_cntrl
Simulink diagram shown in Figure 22 in Section 3.1.1 again.
Clear the workspace and run the setup_servo_pos_cntrl.m
script in MATLAB.
Enter the proportional and derivative control gains found in Pre-Lab Question 4 and set the integral gain to 0.
Set the Signal Generator
parameters to the following to generate a triangular reference (which corresponds to a ramp input):
Signal Type = triangle
Amplitude = 1
Frequency = 0.8 Hz
Inside the PID Control
subsystem, set the Manual Switch
to the down position so that the High-Pass Filter
block is used.
Open the load shaft position scope, Position (rad)
, and the motor input voltage scope, Vm (V)
.
Start the simulation. The scopes should display responses similar to Figure 26a and Figure 26b.
Save the data in the workspace using a suitable name. Result: Generate a MATLAB figure showing the Ramp PD position response and its corresponding input voltage trace.
Measure the steady-state error. Result: Compare the simulation measurement with the steady-state error calculated in Pre-Lab Question 6.
In this experiment, we will control the angular position of the Rotary Servo Base Unit load shaft, i.e. the disc load, using a PD controller. The goal is to examine how well the system can track a triangular (ramp) position input. Measurements will then be taken to ensure that the specifications are satisfied.
As in the Step Response experiment in Section 3.1, in this experiment, you also need to use the q_servo_pos_cntrl
SIMULINK diagram shown in Figure 24 to implement the position control experiments.
Clear the workspace and run the setup_servo_pos_cntrl.m
script in MATLAB.
Enter the proportional and derivative control gains found in Pre-Lab Question 4.
Set the Signal Generator
parameters to the following to generate a triangular reference (i.e. ramp reference):
Signal Type = triangle
Amplitude = 1
Frequency = 0.8 Hz
Open the load shaft position scope, Position (rad)
, and the motor input voltage scope, Vm (V)
.
Save the data in the workspace using a suitable name. Result: Generate a MATLAB figure showing the Ramp PD position response and its corresponding input voltage trace.
Measure the steady-state error. Result: Compare it with the steady-state error calculated in Pre-Lab Question 6.
Design an experiment to see if the steady-state error can be eliminated when tracking a ramp input. First, simulate the response, then implement it using the Rotary Servo Base Unit system.
How can the PD controller be modified to eliminate the steady-state error in the ramp response? State your hypothesis and describe the anticipated cause-and-effect leading to the expected result. Hint: Look through Section 1.
List the independent and dependent variables of your proposed controller. Explain their relationship.
Your proposed controller, like the PD compensator, is a model-based controller. This means that the control gains generated are based on a mathematical representation of the system. Given this, list the assumptions you are making in this control design. State the reasons for your assumptions.
For each case, generate a Matlab figure showing the position response of the system and its corresponding input voltage.
In each case, measure the steady-state error.
For each case comment on whether the steady-state specification given in Section 1.1.3 was satisfied without saturating the actuator.
Pre-lab calculations.
Response plots from In-Lab Simulations and Experiments (Section 3.1.1: Step 9, Step 2; Section 3.1.2: Step 8; Section 3.2.1: Step 9; Section 3.2.2: Step 8; Section 3.3: Step 5).
Corresponding measured peak time, percent overshoot and steady-state error for the response plots mentioned above (Section 3.1.1: Step 10, Step 3; Section 3.1.2: Step 9; Section 3.2.1: Step 10; Section 3.2.2: Step 9; Section 3.3: Step 6). Note: Peak time and percent overshoot are required only for step response simulation and experiment, not ramp response.
Answer all the questions asked in all the In-Lab simulations and experiments (Section 3.1.1: Step 10, Step 3; Section 3.1.2: Step 9; Section 3.2.1: Step 10; Section 3.2.2: Step 9; Section 3.3: Steps 1, 2, 3 and 7).
There are two pre-lab calculations (Integration and Modelling) that need to be done before coming for the Lab 1 Week 1 lab session. Please write it down on paper with any necessary work. Failure to do pre-lab will result in points deduction for lab report.
The Quanser Rotary Servo Base Unit rotary servo plant, shown below, consists of a DC motor that is encased in a solid aluminum frame and equipped with a planetary gearbox. The motor has its own internal gearbox that drives external gears. The Rotary Servo Base Unit is equipped with two sensors: a potentiometer and an encoder. The potentiometer and the encoder sensors measure the angular position of the load gear using different methods.
The Rotary Servo Base Unit incorporates a Faulhaber Coreless DC Motor model 2338S006 and is shown in Figure 1c with ID #9. This is a high-efficiency, low-inductance motor that can obtain a much faster response than a conventional DC motor.
A rotary potentiometer, or pot, is a manually controlled variable resistor. See the example shown below. It typically consists of an exposed shaft, three terminals (A, W, and B), an encased internal resistive element shaped in a circular pattern, and a sliding contact known as a wiper. By rotating the shaft, the internal wiper makes contact with the resistive element at different positions, causing a change in resistance when measured between the centre terminal (W) and either of the side terminals (A or B). The total resistance of the potentiometer can be measured by clamping a multimeter to terminals A and B.
An incremental optical encoder is a relative angular displacement sensor that measures angular displacement relative to a previously known position. Unlike an absolute encoder, an incremental encoder does not retain its position information upon power loss. An incremental encoder outputs a series of pulses that correlate to the relative change in angular position. Encoders are commonly used to measure the angular displacement of rotating load shafts. The information extracted from an incremental encoder can also be used to derive instantaneous rotational velocities.
An incremental optical encoder typically consists of a coded disk, an LED, and two photo sensors. The disk is coded with an alternating light and dark radial pattern causing it to act as a shutter. As shown schematically above, the light emitted by the LED is interrupted by the coding as the disk rotates around its axis. The two photo sensors (A and B) positioned behind the coded disk sense the light emitted by the LED. The process results in A and B signals, or pulses, in four distinct states: (1) A off, B on; (2) A off, B off; (3) A on, B off; (4) A on, B on. Encoders that output A and B signals are often referred to as quadrature encoders since the signals are separated in phase by 90◦. The resolution of an encoder corresponds to the number of light or dark patterns on the disk and is given in terms of pulses per revolution, or PPR. In order to make encoder measurements, you need to connect the encoder to a counter to count the A and B signals. Then use a decoder algorithm to determine the number of counts and direction of rotation. Three decoding algorithms are used: X1, X2, X4.
X1 Decoder: When an X1 decoder is used, only the rising or falling edge of signal A is counted as the shaft rotates. When signal A leads signal B, the counter is incremented on the rising edge of signal A. When signal B leads signal A, the counter is decremented on the falling edge of signal A. Using an X1 decoder, a 1,024 PPR encoder will result in a total of 1,024 counts for every rotation of the encoder shaft. X2 Decoder: When an X2 decoder is used, both the rising and falling edges of signal A are counted as the shaft rotates. When signal A leads signal B, the counter is incremented on both the rising and falling edge of signal A. When signal B leads signal A, the counter is decremented on both the rising and falling edges of signal A. Using an X2 decoder, a 1,024 PPR encoder will generate a total of 2,048 counts for every rotation of the encoder shaft. X4 Decoder: When an X4 algorithm is used, both the rising and falling edges of both signals A and B are counted. Depending on which signal leads, the counter will either increment or decrement. An X4 decoder generates four times the number of counts generated by an X1 decoder resulting in the highest resolution among the three types of decoders. Using an X4 decoder, a 1,024 PPR encoder will generate a total of 4,096 counts for every rotation of the encoder shaft.
The angular resolution of an encoder depends on the encoder’s pulses per revolution (PPR) and the decoding algorithm used:
where N = 1, 2, or 4 corresponds to X1, X2, and X4 decoders respectively
While encoders are typically used for measuring angular displacement, they can also measure rotational speeds. The velocity can be found by taking the difference between consecutive angle measurements
In practice, determining rotational speeds by means of derivation of the discontinuous encoder output often results in signal noise. The ripple in the velocity signal due to sampling can be reduced by filtering. Applying a first-order low-pass filter to the measured velocity signal
Rearranging the filter transfer function above,
we can represent the filtering using the differential equation
Given that the Rotary Servo Base Unit rotary encoder has 1024 PPR and the quadrature decoding is used in the DAQ, what is the resolution of the encoder?
What is the sensor gain for the rotary potentiometer that converts voltage measured into load gear angle (in radians)? Sensor Gain is used to convert output signal to desired output unit. For the potentiometer the output ranges from -5V to +5V. In this case, the sensor gain converts voltage into corresponding radians. Information: the rotary potentiometer on the Rotary Servo Base Unit outputs ±5 V over 352 deg.
Assuming the DAQ device you are using has a 16-bit signed encoder counter. What is the counter range and how does that affect the measuring encoder signal?
Find the velocity estimation ripple of the Rotary Servo Base Unit when the sampling interval is 0.01 s, 0.002 s, and 0.001 s. How does increasing the sampling rate (i.e., decreasing the sampling interval) affect the ripple?
We have tried a simple SIMULINK model diagram of the Rotary Servo Base with encoder and potentiometer reading from Lab 0 QLabs. This time we will build a SIMULINK model from scratch to read the motor velocity using actual equipment.
Follow the steps and build the SIMULINK model below:
Follow these steps to read the motor velocity:
First, download and open q_servo_vel_direct.slx Simulink model.
Configure the model to apply a 0.4 Hz square wave voltage signal going between 0.5V and 2.5V.
Change the simulation time to 5 seconds from Simulation tab, stop time.
Go to Modelling tab and open modelling setting. Check that sample time is set to 0.002s and check that solver is set to ode1 (euler).
The velocity measurement using a direct derivative will be noisy. After the SIMULINK has run for 5 seconds and stopped, measure the velocity ripple (peak to peak within ripple). You can use the Cursor Measurements tool in the Scope for more accurate measurements. Result: compare the measured ripple to the calculation made in Pre-Lab Q4 with sampling interval of 0.002s. Save the speed data (wl) to plot in the report. Name the file such as integration_sampletime0.002s.
Increase the control loop rate of the QUARC controller by decreasing the sampling interval to 0.001 s, i.e. increasing the sampling rate to 1 kHz. Build, Connect and run the Simulink. Once SIMULINK has run for 5 seconds and stopped, examine the change in the ripple velocity measurement. Result: compare the measured ripple to the calculation made in Pre-lab Q4 with sampling interval of 0.001s. Save the speed data (wl) to plot in the report. Name the file such as integration_sampletime0.001s.
Save the speed data (wl) to plot in the report. Name the file such as integration_wrapping.
Save the speed data (wl) to plot in the report. Name the file such as integration_lowpass.
Result: Compare the velocity estimation using the direct derivative with filtering. How much noise does the filter remove? Is this in-line with the ripple velocity calculated in Pre-lab Q5? Result: Attach the response of the filtered velocity estimate and the Simulink model you designed.
Pre-lab calculations.
Complete SIMULINK block diagram with low-pass filter.
Response plots from In-Lab Experiment Step 7,8,9 and 10. Comparison between measured and calculated values.
Answer all the questions asked in the In-Lab experiment.
By solving for , we can find the closed-loop transfer function:
Recall in the Integration laboratory experiment, the Rotary Servo Base Unit voltage-to-speed transfer function was derived. To find the voltage-to-position transfer function, we can put an integrator in series with the speed transfer function (effectively integrating the speed output to get position). Then, the resulting open-loop voltage-to-load gear position transfer function becomes:
where is the natural frequency and is the damping ratio. This is called the standard second-order transfer function. Its response depends on the values of and .
with a step amplitude of . The system response to this input is shown in Figure 17, where the red trace is the response (output), , and the blue trace is the step input .
The maximum value of the response is denoted by the variable and it occurs at a time . The initial value of the response is denoted as . For a response similar to Figure 17, the percent overshoot is found using
From the initial step time, , the time it takes for the response to reach its maximum value is
Steady-state error is illustrated in the ramp response given in Figure 18 and is denoted by the variable . It is the difference between the reference input and output signals after the system response has settled. Thus, for a time when the system is in steady-state, the steady-state error equals
where is the value of the steady-state input and is the steady-state value of the output.
We can find the error transfer function in Figure 16 in terms of the reference , the plant , and the compensator . The Laplace transform of the error is
Solving for from Equation 3.3 and substituting it in Equation 3.11 yields
In this equation, we need to substitute the transfer function for from Equation 3.12. The transfer function requires, , and . For simplicity, let as a compensator. The and were given by equations Equation 3.3 and Equation 3.5, respectively. Then, the error becomes:
where is the proportional control gain, is the derivative control gain, is the setpoint or reference load shaft angle, is the measured load shaft angle, and is the Rotary Servo Base Unit motor input voltage. The block diagram of the PD control is given in Figure 19.
We need to find the closed-loop transfer function for the closed-loop position control of the Rotary Servo Base Unit. Taking the Laplace transform of Equation 3.20 gives
Substituting Equation 3.21 into Equation 3.22 and solving for gives the Rotary Servo Base Unit position closed-loop transfer function as:
In control design, a factor to be considered is saturation. This is a nonlinear element and is represented by a saturation block as shown in Figure 20. In a system like the Rotary Servo Base Unit, the computer calculates a numeric control voltage value. This value is then converted into a voltage, , by the digital-to-analog converter of the data-acquisition device in the computer. The voltage is then amplified by a power amplifier by a factor of . If the amplified voltage, , is greater than the maximum output voltage of the amplifier or the input voltage limits of the motor (whichever is smaller), then it is saturated (limited) at . Therefore, the input voltage is the effective voltage being applied to the Rotary Servo Base Unit motor.
we can find the error transfer function by substituting the Rotary Servo Base Unit closed-loop transfer function in Equation 3.23 into the formula given in Equation 3.11. Using the variables of the Rotary Servo Base Unit, this formula can be rewritten as . After rearranging the terms we find:
Substituting the input ramp transfer function Equation 3.25 into the variable gives
where is the proportional control gain, is the integral gain, is the derivative control gain, is the setpoint or reference load shaft angle, is the measured load shaft angle, and is the Rotary Servo Base Unit motor input voltage.
We need to find the closed-loop transfer function for the closed-loop position control of the Rotary Servo Base Unit. Taking the Laplace transform of Equation 3.28 gives
Substituting Equation 3.29 into Equation 3.30 and solving for gives the Rotary Servo Base Unit position closed-loop transfer function as:
Then, substituting the reference ramp transfer function Equation 3.25 into the variable gives
where the variable is the integration time.
Calculate the maximum overshoot of the response (in radians) given a step setpoint of 45 deg and the overshoot specification given in Section 1.1.3. Hint: By substituting and step setpoint into Equation 3.6, we can obtain . Recall that the desired response specifications include 5% overshoot.
The Rotary Servo Base Unit closed-loop transfer function was derived in Equation 3.23 in Section 1.2.1. Find the control gains and in terms of and . Hint: Remember the standard second-order system equation.
Based on the nominal Rotary Servo Base Unit model parameters, and , found in the Modeling laboratory experiment, calculate the control gains needed to satisfy the time-domain response requirements given in Section 1.1.3. (Use rad/(Vs) and ) (Need answers from Q2 and Q3)
In the PD controlled system, for a reference step of (i.e. 45 deg step) starting from position, calculate the maximum proportional gain that would lead to providing the maximum voltage to the motor. Ignore the derivative control (). Can the desired specifications be obtained based on this maximum available gain and what you calculated in Question 4? (Need answer from Q4)
For the PD controlled closed-loop system, find the steady-state error and evaluate it numerically given a ramp with a slope of rad/s. Use the control gains found in Question 4. (Need answer from Q4)
What should the integral gain be so that when the Rotary Servo Base Unit is supplied with the maximum voltage of V it can eliminate the steady-state error calculated in Question 6 in 1 second? (Need answers from Q4 and Q6) Hint: Start from Equation 3.35 and use , , the you found in Question 4 and found in Question 6. Remember that is constant.
In the Simulink diagram, set the Amplitude (rad)
gain block to 0.4 (rad) to generate a step with an amplitude of 45.8 degrees (i.e. square wave goes between which results in a step amplitude of 0.8 rad).
Build the model by clicking on the down arrow on Monitor & Tune under the Hardware tab and then select Build for monitoring . This compiles the Simulink diagram.
Click Connect button under Monitor & Tune and then run SIMULINK by clicking Start to begin running the controller. The scopes should display responses similar to Figure 25a and Figure 25b.
Setting the frequency to 0.8 Hz will generate an increasing and decreasing ramp signal with the same slope used in the Pre-Lab Question 6. The slope is calculated from the Triangular Waveform amplitude, Amp, and frequency, f, using the expression:
In the SIMULINK diagram, set the Amplitude (rad)
gain block to .
In the Simulink diagram, set the Amplitude (rad)
gain block to .
Build the model by clicking on the down arrow on Monitor & Tune under the Hardware tab and then select Build for monitoring .
Click Connect button under Monitor & Tune and then run SIMULINK by clicking Start to begin running the controller. The scopes should display responses similar to Figure 27a and Figure 27b.
Give a brief, general overview of the steps involved in your experimental procedure for two cases: (1) Simulation, and (2) Experimental implementation. Note: In case of time constraints, follow the same steps for Simulation as per Section 3.2.1 and Experiment as per Section 3.2.2, except the value of ki (i.e., ki 0).
Model parameters ( and ) and controller gains (, and ) implemented during the In-Lab Simulations and Experiments.
A schematic diagram of the voltage dividing characteristic of a potentiometer is illustrated below. By applying a known voltage between terminals A and B (), voltage is divided between terminals AW and WB where:
When connected to an external shaft, a rotary potentiometer can measure absolute angular displacement. By applying a known voltage to the outside terminals of the pot, we can determine the position of the sensor based on the output voltage or which will be directly proportional to the position of the shaft. One of the advantages of using a potentiometer as an absolute sensor is that after a power loss, position information is retained since the resistance of the pot remains unchanged. While pots are an effective way to obtain a unique position measurement, caution must be used since their signal output may be discontinuous. That is, after a few revolutions potentiometers may reset their signal back to zero. Another disadvantage of most pots is that they have physical stops that prevent continuous shaft rotation.
where represents the position measurement sample and is the sampling interval of the control software. The resolution or ripple in the velocity measurement is given by
is rotational speed (rad/s) and is the resolution of the encoder given in Equation 1.1, and is the sampling interval. Note that the ripple velocity increases when the sampling period decreases.
where is the measured signal, is the filtered signal, and is the filter time constant. Low-pass filters are also often represented in terms of cutoff frequency :
where . The low-pass filter attenuates the high-frequency components of the signal higher than the cut-off frequency specified, i.e. passes signal with frequencies
The derivative can be approximated by the difference between the currently measured sample, , and the previous sample, :
Solving for ,
Thus the high-frequency error is reduced by a factor of . The ripple in the filtered velocity signal caused by the encoder is
Note: Filtering does add dynamics to the signal, i.e. small delay, as given by the term in Equation 1.3.
Encoder counters on data acquisition (DAQ) devices have a rated number of bits, n. For example, a DAQ with an 8-bit signed counter has a range between −128 and +127 (i.e. and ). When the encoder counts go beyond this range, the measured counts from the DAQ ends up wrapped. Consider the following example. If the encoder is measuring 100 counts, then the DAQ counter will output 100 (no wrapping). However, if the encoder is measuring 150 counts, then the 8-bit signed counter will read counts. Thus the encoder wraps and causes a discontinuity. This can be very problematic in closed-loop feedback control. The QUARC software includes an Inverse Modulus block that unwraps the counter signal and keeps a continuous signal. For more information, see the Inverse Modulus block in the QUARC documentation.
A low-pass filter with a time constant of is used in the velocity estimator and the sampling of the control runs at s. Evaluate the ripple in the velocity with this filter.
To build the model, click the down arrow on Monitor & Tune under the Hardware tab and then click Build for monitoring . This generates the controller code.
Click Connect button under Monitor & Tune and then run SIMULINK by clicking Start .
Run the controller for a minute or two (stop time to inf). Depending on the data acquisition device you are using (e.g. Q2-USB or Q8-USB), you may notice a spike or discontinuity that occurs in the velocity estimation, as shown below (once the discontinuity occurs stop the simulation) : This encoder wrapping is due to the range of the DAQ encoder counter. To remove the wrapping and maintain a continuous signal, use the QUARC Inverse Modulus block before Encoder: count to rad block. Build, connect and run your QUARC controller and ensure the signal is now continuous (i.e. no spike occurs). Note : The Inverse Modulus block should be added to the output of the HIL Read Encoder and set to the where n is the bits of the DAQ encoder counter. Quanser Q2-USB has 16-bit encoder counter and Quanser Q8-USB has 24-bit encoder counter.
Add a low-pass filter with a time constant of s using the Simulink Transfer Fcn block. This translate into having a filter with a cutoff frequency of 1/0.01 = 100 rad/s. Run it for 5 seconds.
1
Top plate
12
Encoder
2
Bottom plate
13
Ball-bearing block
3
Posts
14
Motor
4
Motor pinion gear: 72-teeth (low-gear)
15
Motor Gearbox
5
Load gear: 72 teeth (low-gear)
16
Motor connector
6
Potentiometer gear
17
Encoder connector
7
Anti-backlash springs
18
Potentiometer connector
8
Load shaft (i.e. output shaft)
19
Bar inertial load
9
Motor pinion gear: 24-teeth (high-gear)
20
Disc inertial load
10
Load gear: 120-teeth (high-gear)
21
Thumb screws
11
Potentiometer
The objective of this experiment is to find a transfer function that describes the rotary motion of the Rotary Servo Base Unit load shaft. The dynamic model is derived analytically from classical mechanics principles and using experimental methods.
The angular speed of the Rotary Servo Base Unit load shaft with respect to the input motor voltage can be described by the following first-order transfer function:
where is the Laplace transform of the load shaft speed , is the Laplace transform of motor input voltage , is the steady-state gain, is the time constant, and is the Laplace operator. The Rotary Servo Base Unit transfer function model is derived analytically in Modelling Using First-Principles and its and parameters are evaluated. These are known as the nominal model parameter values. The model parameters can also be found experimentally. Modeling Using Experiment describes how to use the frequency response and bump-test methods to find and . These methods are useful when the dynamics of a system are not known, for example in a more complex system. After the lab experiments, the experimental model parameters are compared with the nominal values.
The DC motor armature circuit schematic and gear train is illustrated in Figure 7.
is the motor resistance, is the inductance, and is the back-emf constant.
The back-emf (electromotive) voltage depends on the speed of the motor shaft, , and the back-emf constant of the motor, . It opposes the current flow. The back emf voltage is given by:
Using Kirchoff’s Voltage Law, we can write the following equation:
Since the motor inductance is much less than its resistance, it can be ignored. Then, the equation becomes:
Solving for , the motor current can be found as:
In this section, the equation of motion describing the speed of the load shaft, , with respect to the applied motor torque, , is developed. Since the Rotary Servo Base Unit is a one degree-of-freedom rotary system, Newton’s Second Law of Motion can be written as:
where is the moment of inertia of the body (about its center of mass), is the angular acceleration of the system, and is the sum of the torques being applied to the body. As illustrated in Figure 7, the Rotary Servo Base Unit gear train along with the viscous friction acting on the motor shaft, , and the load shaft are considered. The load equation of motion is:
where is the moment of inertia of the load and is the total torque applied on the load. The load inertia includes the inertia from the gear train and from any external loads attached, e.g. disc or bar. The motor shaft equation is expressed as:
where is the motor shaft moment of inertia and is the resulting torque acting on the motor shaft from the load torque. The torque at the load shaft from an applied motor torque can be written as:
where is the gear ratio and is the gearbox efficiency. The planetary gearbox that is directly mounted on the Rotary Servo Base Unit motor (see Rotary Servo Base Unit User Manual for more details) is represented by the and gears in Figure 7 and has a gear ratio of
This is the internal gear box ratio. The motor gear and the load gear are directly meshed together and are visible from the outside. These gears comprise the external gear box which has an associated gear ratio of
The gear ratio of the Rotary Servo Base Unit gear train is then given by:
Thus, the torque seen at the motor shaft through the gears can be expressed as:
Intuitively, the motor shaft must rotate times for the output shaft to rotate one revolution.
We can find the relationship between the angular speed of the motor shaft, , and the angular speed of the load shaft, by taking the time derivative:
To find the differential equation that describes the motion of the load shaft with respect to an applied motor torque substitute (Eq 2.13), (Eq 2.15) and (Eq 2.7) into (Eq 2.8) to get the following:
Collecting the coefficients in terms of the load shaft velocity and acceleration gives
Defining the following terms:
simplifies the equation as:
In this section the electrical equation and the mechanical equation are brought together to get an expression that represents the load shaft speed in terms of the applied motor voltage.
The motor torque is proportional to the voltage applied and is described as
where is the current-torque constant (), is the motor efficiency, and is the armature current. See Rotary Servo Base Unit User Manual for more details on the Rotary Servo Base Unit motor specifications. We can express the motor torque with respect to the input voltage and load shaft speed by substituting the motor armature current given by Eq 2.5, into the current-torque relationship given in Eq 2.21:
To express this in terms of and , insert the motor-load shaft speed Eq 2.15, into Eq 2.21 to get:
If we substitute (Eq 2.23) into (Eq 2.20), we get:
After collecting the terms, the equation becomes
This equation can be re-written as:
where the equivalent damping term is given by:
and the actuator gain equals
A linear model of a system can also be determined purely experimentally. The main idea is to experimentally observe how a system reacts to different inputs and change structure and parameters of a model until a reasonable fit is obtained. The inputs can be chosen in many different ways and there are a large variety of methods. Two methods of modeling the Rotary Servo Base Unit are: (1) frequency response and, (2) bump test.
In Figure 8, the response of a typical first-order time-invariant system to a sine wave input is shown. As it can be seen from the figure, the input signal () is a sine wave with a fixed amplitude and frequency. The resulting output () is also a sinusoid with the same frequency but with a different amplitude. By varying the frequency of the input sine wave and observing the resulting outputs, a Bode plot of the system can be obtained as shown in Figure 9.
The Bode plot can then be used to find the steady-state gain, i.e. the DC gain, and the time constant of the system. The cuttoff frequency, , shown in Figure 9 is defined as the frequency where the gain is 3 dB less than the maximum gain (i.e. the DC gain). When working in the linear non-decibel range, the 3 dB frequency is defined as the frequency where the gain is , or about 0.707, of the maximum gain. The cutoff frequency is also known as the bandwidth of the system which represents how fast the system responds to a given input.
The magnitude of the frequency response of the Rotary Servo Base Unit plant transfer function given in equation Eq 2.1 is defined as:
where is the frequency of the motor input voltage signal . We know that the transfer function of the system has the generic first-order system form given in Eq 2.1. By substituting in this equation, we can find the frequency response of the system as:
Then, the magnitude of it equals
Let’s call the frequency response model parameters and to differentiate them from the nominal model parameters, and , used previously. The steady-state gain or the DC gain (i.e. gain at zero frequency) of the model is:
The bump test is a simple test based on the step response of a stable system. A step input is given to the system and its response is recorded. As an example, consider a system given by the following transfer function:
The step response shown in Figure 10 is generated using this transfer function with and .
The step input begins at time . The input signal has a minimum value of and a maximum value of . The resulting output signal is initially at . Once the step is applied, the output tries to follow it and eventually settles at its steady-state value yss. From the output and input signals, the steady-state gain is
where and . In order to find the model time constant, , we can first calculate where the output is supposed to be at the time constant from:
Then, we can read the time that corresponds to from the response data in Figure 10. From the figure we can see that the time is equal to:
From this, the model time constant can be found as:
Going back to the Rotary Servo Base Unit system, a step input voltage with a time delay can be expressed as follows in the Laplace domain:
where is the amplitude of the step and is the step time (i.e. the delay). If we substitute this input into the system transfer function given in Eq 2.1, we get:
We can then find the Rotary Servo Base Unit load speed step response, , by taking inverse Laplace of this equation. Here we need to be careful with the time delay and note that the initial condition is
We obtained Eq (2.26) which described the dynamic behavior of the load shaft speed as a function of the motor input voltage. Starting from this equation, find the transfer function
Express the steady-state gain () and the time constant () of the process model Eq (2.1) in terms of the , , and parameters.
Calculate the and model parameters using the system specifications given in Rotary Servo Base Unit User Manual. The parameters are to be calculated based on an the Rotary Servo Base Unit in the high-gear configuration.
The load attached to the motor shaft includes a 24-tooth gear, two 72-tooth gears, and a single 120-tooth gear along with any other external load that is attached to the load shaft. Thus, for the gear moment of inertia and the external load moment of inertia , the load inertia is . Using the specifications given in the Rotary Servo Base Unit User Manual find the total moment of inertia from the gears. Hint: Use the definition of moment of inertia for a disc .
Assuming that the disc load is attached to the load shaft, calculate the inertia of the disc load, , and the total load moment of inertia acting on the motor shaft from the disc and gears, .
Evaluate the equivalent moment of inertia . This is the total inertia from the motor, gears, and disc load. The moment of inertia of the DC motor can be found in the Rotary Servo Base Unit User Manual.
Calculate the steady-state model gain and time constant . These are the nominal model parameters and will be used to compare with parameters that are later found experimentally.
Referring to the Frequency Response, find the expression representing the time constant of the frequency response model given in Eq. (2.31). Begin by evaluating the magnitude of the transfer function at the cutoff frequency .
Referring to Bump Test, find the equation of steady-state gain of the step response and compare it with Eq 2.34. Hint: The the steady-state value of the load shaft speed can be defined as .
Evaluate the step response given in Eq. (2.40) at and compare it with Eq. (2.35).
The q_servo_modeling Simulink diagram shown in Figure 11 will be used to conduct the experiments. The Rotary Servo Base Unit subsystem contains QUARC blocks that interface with the DC motor and sensors of the Rotary Servo Base Unit system. The Rotary Servo Base Unit Model uses a Transfer Fcn block from the SIMULINK library to simulate the Rotary Servo Base Unit system. Thus, both the measured and simulated load shaft speed can be monitored simultaneously given an input voltage.
Download the Modeling_files.zip and extract the files to desktop.
Open q_servo_modeling.m
SIMULINK file.
Configure DAQ: Double-click on the HIL Initialize block in the SIMULINK diagram and ensure it is configured for the DAQ device that is installed in your system (e.g. Q2-USB).
Open setup_servo_modeling.m
file to open the setup script for the q_servo_modeling SIMULINK model.
Run the script. Note: The calculated servo model parameter are default model parameters and do not accurately represent the Rotary Servo Base Unit system.
The frequency response of a linear system can be obtained by providing a sine wave input signal to it and recording the resulting output sine wave from it. In this experiment, the input signal is the motor voltage and the output is the motor speed. In this method, we keep the amplitude of the input sine wave constant but vary its frequency. At each frequency setting, we record the amplitude of the output sine wave. The ratio of the output and input amplitudes at a given frequency can then be used to create a Bode magnitude plot. Then, the transfer function for the system can be extracted from this Bode plot.
First, we need to find the steady-state gain of the system. This requires running the system with a constant input voltage. To create a constant input voltage follow these steps:
In the SIMULINK diagram, double-click on the Signal Generator block and ensure the following parameters are set: • Wave form: sine • Amplitude: 1.0 • Frequency: 0.4 • Units: Hertz
Set the Amplitude (V) slider gain to 0.
Set the Offset (V) block to 2.0 V.
Set the Simulation stop time to 5 seconds.
Open the load shaft speed scope, Speed (rad/s), and the motor input voltage scope, Vm (V) .
The Rotary Servo Base Unit unit should begin rotating in one direction. The scopes should be reading something similar to figure below. Note that in the Speed (rad/s) scope, the yellow trace is the measured speed while the blue trace is the simulated speed (generated by Servo Model block).
Measure the speed of the load shaft and enter the measurement in Table B.1 below under the f = 0 Hz row. Since amplitude gain is set to 0. Technically no sine input or f = 0Hz is applied.
Hint: The measurement can be done directly from the scope using the Cursor Measurements tool. Alternatively, you can use MATLAB commands max(wl(:,2))
to find the maximum load speed using the saved wl
variable. When the controller is stopped, the Speed (rad/s) scope saves data to the MATLAB workspace in the wl
parameter. It has the following structure: wl(:,1)
is the time vector, wl(:,2)
is the measured speed, and wl(:,3)
is the simulated speed.
Result: Calculate the steady-state gain both in linear and decibel (dB) units as explained in Frequency Response. Enter the resulting numerical value in the f = 0 Hz row of Table B.1. Also, enter its non-decibel value in Table B.2 in Result.
In this part of the experiment, we will send an input sine wave at a certain frequency to the system and record the amplitude of the output signal. We will then increment the frequency and repeat the same observation. To create the input sine wave:
In the SIMULINK diagram, double-click on the Signal Generator block and ensure the following parameters are set: • Wave form: sine • Amplitude: 1.0 • Frequency: 1.0 • Units: Hertz
Set the Amplitude (V)
slider gain to 2.0 V.
Set the Offset (V)
block to 0 V.
Set the Simulation stop time to 5 seconds.
The Rotary Servo Base Unit unit should begin rotating smoothly back and forth and the scopes should be reading a response similar to Figure 13 a) and b).
Measure the maximum positive speed of the load shaft at f = 1.0 Hz
input and enter it in Table B.1 below. As before, this measurement can be done directly from the scope using the Cursor Measurements tool or you can use MATLAB commands to find the maximum load speed using the saved wl
variable.
Result: Calculate the gain of the system (in both linear and dB units) and enter the results in Table B.1.
Increase the frequency to f = 2.0 Hz
by adjusting the frequency parameter in the Signal Generator block. Measure the maximum load speed and calculate the gain. Repeat this step for each of the frequency settings in Table B.1.
Result: Using the MATLAB plot command and the data collected in Table B.1, generate a Bode magnitude plot. Make sure the amplitude and frequency scales are in decibels. When making the Bode plot, ignore the f = 0 Hz
entry as the logarithm of 0 is not defined.
Result: Calculate the time constant using the obtained Bode plot by finding the cutoff frequency. Label the Bode plot with the -3 dB gain and the cutoff frequency. Enter the resulting time constant in Table B.2.
Hint: Use the Data Tips tool to obtain values from the MATLAB Figure.
In this method, a step input is given to the Rotary Servo Base Unit and the corresponding load shaft response is recorded. Using the saved response, the model parameters can then be found as discussed in Bump Test.
To create the step input:
Double-click on the Signal Generator block and ensure the following parameters are set: • Wave form: square • Amplitude: 1.0 • Frequency: 0.4 • Units: Hertz
Set the Amplitude (V)
gain block to 1.0 V.
Set the Offset (V)
gain block to 2.0 V.
Set the Simulation stop time to 5 seconds.
Open the load shaft speed scope, Speed (rad/s)
, and the motor input voltage cope,
Vm (V)
.
The gears on the Rotary Servo Base Unit should be rotating in the same direction and alternating between low and high speeds. The response in the scopes should be similar to Figure 14 a) and b).
Save wl data and name it as modelling_section#_Group#_step.
Result: Plot the response in MATLAB. Recall that the maximum load speed is saved in the MATLAB workspace under the wl
variable.
Result: Find the steady-state gain using the measured step response and enter it in Table B.2.
Hint: Use the MATLAB ginput
command to measure points off the plot.
Find the time constant from the obtained response and enter the result in Table B.2.
Click the Stop button on the SIMULINK diagram toolbar (or select QUARC | Stop from the menu) to stop the experiment.
In this experiment, you will adjust the model parameters you found in the previous experiments to tune the transfer function. Our goal is to match the simulated system response with the parameters you found as closely as possible to the response of the actual system. To create a step input:
Double-click on the Signal Generator block and ensure the following parameters are set: • Wave form: square • Amplitude: 1.0 • Frequency: 0.4 • Units: Hertz
Set the Amplitude (V)
slider gain to 1.0 V.
Set the Offset (V)
block to 1.5 V.
Set the Simulation stop time to 5 seconds.
Open the load shaft speed scope, Speed (rad/s)
, and the motor input voltage scope, V_m (V)
.
The gears on the Rotary Servo Base Unit should be rotating in the same direction and alternating between low and high speeds and the scopes should be as shown in Figure 15 a) and b). Recall that the yellow trace is the measured load shaft rate and the purple trace is the simulated trace. By default, the steady-state gain and the time constant of the transfer function used in simulation are set to: K = 1 rad/s/V and = 0.1s. These model parameters do not accurately represent the system.
Save wl data and name it as modelling_section#_Group#_K1tau01.
Enter the command K = 1.25 in the MATLAB Command Window.
Update the parameters used by the Transfer Function block in the simulation by updating diagram in the q_servo_modeling SIMULINK diagram. To update the diagram, from the Modeling tab, click Update Model. Alternatively, press Ctrl+D. Connect and run the SIMULINK model and observe how the simulation response changes. Remember we have increased K from 1 to 1.25.
Save wl data and name it as modelling_section#_Group#_K125tau01.
Enter the command tau = 0.2
in the MATLAB Command Window.
Update the simulation again by updating diagram. Connect and run the SIMULINK model and observe how the simulation response changes. Remember we have increased from 0.1 to 0.2.
Save wl data and name it as modelling_section#_Group#_K125tau02. Result: We have varied the gain and time constant model parameters. How do the gain and the time constant affect the system response?
Enter the nominal values, and , that were found in Pre-lab Q7 in the MATALB Command Window. Update the parameters and examine how well the simulated response matches the measured one.
Save wl data and name it as modelling_section#_Group#_K#tau#.
If the calculations were done properly, then the model should represent the actual system quite well. However, there are always some differences between each servo unit and, as a result, the model can always be tuned to match the system better. Try varying the model parameters until the simulated trace matches the measured response better. Enter these tuned values under the Model Validation section of Table B.2.
If you have tried with different and values save the data.
Result: Provide two reasons why the nominal model might not represent the Rotary Servo Base Unit with better accuracy.
Result: Create a MATLAB figure that shows the measured and simulated response of the model validation response using the tuned model parameters of and . This can be done by manually changing the Servo Model Transfer Function block parameters or changing the K
and tau
parameters in the MATLAB Command Window and going to Simulation | Update Diagram in the SIMULINK model.
Result: Explain how well the nominal model, the frequency response model, and the bump-test model represent the Rotary Servo Base Unit system.
To build the model, click the down arrow on Monitor & Tune under the Hardware tab and then click Build for monitoring . This generates the controller code.
Click Connect button under Monitor & Tune and then run SIMULINK by clicking Start .
Click Connect button under Monitor & Tune and then run SIMULINK by clicking Start .
To build the model, click the down arrow on Monitor & Tune under the Hardware tab and then click Build for monitoring . This generates the controller code.
Click Connect button under Monitor & Tune and then run SIMULINK by clicking Start .
To build the model, click the down arrow on Monitor & Tune under the Hardware tab and then click Build for monitoring . This generates the controller code.
Click Connect button under Monitor & Tune and then run SIMULINK by clicking Start .