System Simulation using Matlab

Similar documents
ROBOTICS Laboratory Problem 02

MSMS Matlab Problem 02

Lab 1: Dynamic Simulation Using Simulink and Matlab

The roots are found with the following two statements. We have denoted the polynomial as p1, and the roots as roots_ p1.

Physics 584 Computational Methods

STATE VARIABLE (SV) SYSTEMS

1 Overview of Simulink. 2 State-space equations

Initial value problems for ordinary differential equations

Simulink Tutorial 1 CPE562

CHAPTER 6 STATE SPACE: FREQUENCY RESPONSE, TIME DOMAIN

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit V Solution of

Laboratory 1. Solving differential equations with nonzero initial conditions

Linear System Theory

Ordinary Differential Equations (ODEs) Background. Video 17

(t) ), ( ) where t is time, T is the reaction time, u n is the position of the nth car, and the "sensitivity coefficient" λ may depend on un 1(

ES205 Analysis and Design of Engineering Systems: Lab 1: An Introductory Tutorial: Getting Started with SIMULINK

EE 4314 Lab 1 Handout Control Systems Simulation with MATLAB and SIMULINK Spring Lab Information

AMS 27L LAB #8 Winter 2009

MATLAB BASICS. Instructor: Prof. Shahrouk Ahmadi. TA: Kartik Bulusu

CONTROL SYSTEMS LABORATORY ECE311 LAB 1: The Magnetic Ball Suspension System: Modelling and Simulation Using Matlab

Numerical solution of ODEs

Matlab Course. Anna Kristine Wåhlin. Department of Geophysics, University of Oslo. January Matlab Course p.1/??

Lecture 8: Calculus and Differential Equations

Lecture 8: Calculus and Differential Equations

MATLAB Ordinary Differential Equation (ODE) solver for a simple example 1. Introduction

Using MATLAB with the Convolution Method

Lab 5a: Pole Placement for the Inverted Pendulum

Lab 1g: Horizontally Forced Pendulum & Chaotic Motion

BMEN 398: MATLAB Module: Higher Order Differential Equations; SIMULINK Fall 2005 Updated 8/21/2005 Hart

Model of a DC Generator Driving a DC Motor (which propels a car)

EXPERIMENT 7: ANGULAR KINEMATICS AND TORQUE (V_3)

Stability and Frequency Response of Linear Systems

Appendix 3B MATLAB Functions for Modeling and Time-domain analysis

Laboratory 11 Control Systems Laboratory ECE3557. State Feedback Controller for Position Control of a Flexible Joint

Lab 6a: Pole Placement for the Inverted Pendulum

Lecture 14 - Using the MATLAB Control System Toolbox and Simulink Friday, February 8, 2013

Lab 3: Quanser Hardware and Proportional Control

Solving Differential Equations Using MATLAB

Simulink Modeling Tutorial

Rotary Motion Servo Plant: SRV02. Rotary Experiment #11: 1-DOF Torsion. 1-DOF Torsion Position Control using QuaRC. Student Manual

1. Type your solutions. This homework is mainly a programming assignment.

2 Solving Ordinary Differential Equations Using MATLAB

ENGG 5402 Course Project: Simulation of PUMA 560 Manipulator

Rotary Motion Servo Plant: SRV02. Rotary Experiment #01: Modeling. SRV02 Modeling using QuaRC. Student Manual

Experiment A11 Chaotic Double Pendulum Procedure

System Parameters and Frequency Response MAE 433 Spring 2012 Lab 2

Homework 1 Solutions

EE/ME/AE324: Dynamical Systems. Chapter 4: Block Diagrams

Manifesto on Numerical Integration of Equations of Motion Using Matlab

Time Response of Dynamic Systems! Multi-Dimensional Trajectories Position, velocity, and acceleration are vectors

Graphical User Interface (GUI) for Torsional Vibration Analysis of Rotor Systems Using Holzer and MatLab Techniques

Motion with Constant Acceleration

SRV02-Series Rotary Experiment # 1. Position Control. Student Handout

1. Consider the 1-DOF system described by the equation of motion, 4ẍ+20ẋ+25x = f.

DC-motor modelling and parameter identification

MEAM 520. More Velocity Kinematics

Modeling and Experimentation: Compound Pendulum

Fall 2003 Math 308/ Numerical Methods 3.6, 3.7, 5.3 Runge-Kutta Methods Mon, 27/Oct c 2003, Art Belmonte

Motion II. Goals and Introduction

Figure 12.1: A simple pendulum

1 M62 M62.1 CONSERVATION OF ANGULAR MOMENTUM FOR AN INELASTIC COLLISION

Lab Partner(s) TA Initials (on completion) EXPERIMENT 7: ANGULAR KINEMATICS AND TORQUE

to have roots with negative real parts, the necessary and sufficient conditions are that:

Mathematical Modelling Using Simulink

WILEY. Differential Equations with MATLAB (Third Edition) Brian R. Hunt Ronald L. Lipsman John E. Osborn Jonathan M. Rosenberg

General Physics I Lab. M1 The Atwood Machine

-ASTR 204 Application of Astroimaging Techniques

Physics 8 Monday, October 28, 2013

Newton's 2 nd Law. . Your end results should only be interms of m

Video Analysis Inertial and non-inertial reference frames

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB

(W: 12:05-1:50, 50-N202)

Applying MapCalc Map Analysis Software

Introduction to MATLAB

State Feedback Controller for Position Control of a Flexible Link

TUTORIAL: STATE VARIABLES and MATLAB

The University of Hong Kong Department of Physics. Physics Laboratory PHYS3350 Classical Mechanics Experiment No The Physical Pendulum Name:

EE 474 Lab Part 2: Open-Loop and Closed-Loop Control (Velocity Servo)

Using Simulink to analyze 2 degrees of freedom system

Finite Element Modules for Enhancing Undergraduate Transport Courses: Application to Fuel Cell Fundamentals

TIphysics.com. Physics. Pendulum Explorations ID: By Irina Lyublinskaya

1. Write the symbolic representation and one possible unit for angular velocity, angular acceleration, torque and rotational inertia.

Chapter 2: Numeric, Cell, and Structure Arrays

Experiment P28: Conservation of Linear and Angular Momentum (Smart Pulley)

DP Physics Torque Simulation

AE2610 Introduction to Experimental Methods in Aerospace DYNAMIC RESPONSE OF A 3-DOF HELICOPTER MODEL

2.004 Dynamics and Control II Spring 2008

Lab 1 Uniform Motion - Graphing and Analyzing Motion

Octave. Tutorial. Daniel Lamprecht. March 26, Graz University of Technology. Slides based on previous work by Ingo Holzmann

Tutorial. Getting started. Sample to Insight. March 31, 2016

Appendix A Prototypes Models

Mecanum-Wheeled Vehicle Base

Lecture Schedule Week Date Lecture (M: 2:05p-3:50, 50-N202)

You w i ll f ol l ow these st eps : Before opening files, the S c e n e panel is active.

17-Nov-2015 PHYS MAXWELL WHEEL. To test the conservation of energy in a system with gravitational, translational and rotational energies.

APPENDIX 1 MATLAB AND ANSYS PROGRAMS

Some tools and methods for determination of dynamics of hydraulic systems

A Simple Introduction to EES Version (Handout version 5.1) Copyright C. S. Tritt, Ph.D. September 20, 2005

Solution for Assignment 4

Computer Aided Control Design

Transcription:

EE4314 Fall 2008 System Simulation using Matlab The purpose of this laboratory work is to provide experience with the Matlab software for system simulation. The laboratory work contains a guide for solving the following general problem: Given the dynamics of a system in the form of a set of differential equations, use Matlab to find what n p m the response of the system is, i.e. x( t) R or y( t) R, to a given input, u( t) R, considering certain initial values for the states of the system, x(0) = x0. I. Simulation of dynamical systems using ode integration in Matlab The first method used to obtain in simulation the response of a system involves the use of the ode functions in Matlab. The ode -type of functions provide solutions to Ordinary Differential Equations, such as the ones which describe the systems in our consideration. We will restrict our study to the use of the ode23 Matlab function. To find out more about the ode functions type for example help ode23 in the Matlab command window and read the help file. The first paragraph in the help file describes how the ode23 function can be called and what parameters it returns: ODE23 Solve non-stiff differential equations, low order method. [TOUT,YOUT] = ODE23(ODEFUN,TSPAN,Y0) with TSPAN = [T0 TFINAL] integrates the system of differential equations y' = f(t,y) from time T0 to TFINAL with initial conditions Y0. ODEFUN is a function handle. For a scalar T and a vector Y, ODEFUN(T,Y) must return a column vector corresponding to f(t,y). Each row in the solution array YOUT corresponds to a time returned in the column vector TOUT. To obtain solutions at specific times T0,T1,...,TFINAL (all increasing or all decreasing), use TSPAN = [T0 T1... TFINAL]. The first parameter that the ode23 function requires, i.e. ODEFUN, is in fact a handle to a Matlab function which describes the dynamics of the system to be simulated, i.e. the differential equations y' = f(t,y). Say for example that we are given the system described by the differential equation: 2 1 1 1 1 1 1 m a q + m ga cos( q ) = τ This is the differential equation which describes the dynamics of a one-link planar rotational stiff robotic arm, in an environment without friction. The q 1 is the angle of the robotic arm with respect to the horizontal, τ is the torque that is rotating the arm, a 1 is the length of the arm, m 1 is the mass of the arm and g is the acceleration of gravity. This equation has been obtained using Lagrange s equation (as discussed in class). The ode23 function can only integrate first order differential equations, and for this reason we will introduce a second state to be able to describe this system with a system of two first order differential equations. Thus, with the notations, x1 = q1, x2 = q 1, u = τ, we obtain 1

x 1 = x2 g 1. x 2 = cos( x1 ) + u a 2 1 m1a 1 Using these two first order differential equations we can now write the Matlab function which describes the dynamics of this system. function xdot=robot(t,x); %the x input variable of the function is in fact a vector containing the values %of the states x1 and x2; x1=x(1) and x2=x(2) g=9.8 ; a1=1 ; m1=10 ; %defines the values for the constant parameters in the system dynamics xdot= [x(2) ; -(g/a1)*cos(x(1))+u/(m1*a1^2)]; %defines a vector which is in fact the derivative of the states x1_dot and x2_dot Note that there is a variable which we have not defined. That is u, which is the input function. Say for example that we what to simulate the behavior of the system in response to a input torque -0.2t τ = 20*e cos(2 πt), which is a weighted attenuated cosine function with a period of one second. Then in our program we have to insert a line which will calculate the value of the input at each given moment in time. We now have function xdot=robot(t,x); g=9.8 ; a1=1 ; m1=10 ; u=20*exp(-t*0.2)*cos(2*pi*t); % notice that the time is the other input variable in out function xdot= [x(2) ; -(g/a1)*cos(x(1))+u/(m1*a1^2)]; At this point we have set up a function which describes the system dynamics. Save this file with the name robot.m in your working folder (you can save it directly in your personal folders). In order to simulate our system, and actually get the system response, we have to use the ode23 function. The second parameter of the ode function is the time interval during which we want to obtain the system response. Say for example that we want to see the system states during 10 seconds. Then we define the simulation time span as [0 10]. The last parameter that the ode function requires is the initial conditions of the system. Say for example that the robotic arm is in position indicated by a pi/2rad angle and 0 rad/sec angular velocity. Then Y0 is [pi/2 ; 0]. The ode23 function will return two matrices, which in the help file are named TOUT and YOUT. The first matrix is in fact the time vector which contains all the time points between 0 and 10 at which the system state, which is YOUT, was measured. In our case since the system has 2 states then YOUT will be a matrix with 2 columns (one for each state) and the same number of lines as the TOUT vector. We can now write a program that will simulate our system. (this is a separate file that the file that you created for the robot dynamics) 2

function main clear all; % clears the workspace close all; % closes all open figures clc; % clears the command window % these three commands are not required for your program to work tint= [0 10] ; % defines the time interval [t0 tf], we will simulate % the system for 10 seconds x0= [pi/2 0]' ; % initial conditions [t,x]= ode23( robot, tint, x0); plot(t,x); % plots the system states versus time But this type of plot does not give much information to an untrained eye. To get a nicer visual result one can add the following to the main program a1=1; x1=cos(x(:,1))*a1; y1=sin(x(:,1))*a1; figure(3); for i=1:length(x1), figure(3); plot(0,0,'o',x1(i),y1(i),'o',[0 x1(i)],[0 y1(i)],'-r'); axis([-1.2 1.2-1.2 1.2]); pause(t(i+1)-t(i)); end The answers to the following questions should be turned in at the end of the class. Use the provided page at the end of this document. A. Explain, in the provided space on the last page, what is the effect of each of the code lines in the above program section. B. Make a simulation of the system considering 0 input (u(t)=0) and initial conditions given as [0 0] (which is: zero angle and zero angular velocity). Explain the behavior of the system. II. Simulation of dynamical systems using block diagrams in Matlab Simulink To simulate the dynamics of the same one link robot system one can also use the Simulink environment and the block diagram description of the system. Start by typing simulink in the Matlab command window. The Simulink library browser opens. Create a new simulink file. Start by inserting as many integrators as the number of states of the system. The simulink file will look like the one in Figure 1 (as the system has two states). 3

Figure 1 The output of the first integrator is x 1 and the output of the second integrator is x 2. Knowing that x 1 = x2, one can simply add the connection line between the input of the first integrator and the output of the second one (as presented in Figure 2) Figure 2 g 1 x x u a m a The input of the second integrator is given by the relation 2 = cos( 1) + 2 1 1 1. Note that it depends on the input signal u and the output of the first integrator. First we will group these two signals x 1, u in a vector of signals [ x1 u ]. For this you can use the Mux block which can be found in the signal routing library in Simulink (as per Figure 3). This new vector of signals will serve as input to a block which will have to calculate the value of ẋ 2 g 1 x x u a m a according to the equation 2 = cos( 1) + 2 1 1 1. You can find such a block in the user defined functions tab of the simulink library. You now obtain the schematic in Figure 4. 4

Figure 3 Figure 4 To introduce the function that the Fcn block has to perform you can double-click on the Fcn block and insert the appropriate function in the window that appeared. Figure 5 In this case the relation to be inserted is (-9.8/1)*cos(u(1))+(1/(10*1^2))*u(2). In this relation u(1) carries the information on x1(t) and u(2) carries the information on u(t). We now need to define our input signal u( t ). One can define this input signal in many different ways using a number of combinations of Simulink blocks. One of them is given in Figure 6, where the function block denoted Fcn1 performs the following calculation depending on its input 20*exp(-0.2*u(1))*cos(2*pi*u(1)). 5

Figure 6 This simulink schematic for simulating our robotic system is now complete. We only need to visualize the result. We thus insert in the schematic a Scope block which will present the two states. Figure 7 You can now run the simulation by hitting the play button in the menu. It will simulate the system behavior for 10 seconds. If you double-click on the scope block, a window will appear which will present the evolution of the two states of the system; just like the following line of Matlab code did. plot(t,x); % plots the system states versus time You can now save this data from Simulink and use it for plot in Matlab. If you hit the parameters button (second button) in the scope menu the following window will appear (which has 2 tabs). Figure 8 6

In the data history tab select the save data to workspace tick. In this case, after you run the simulation one more time, in the Matlab workspace will appear a data structure called ScopeData. To access the time vector you use the name ScopeData.time and to access the values of the states you use the name ScopeData.signals.values. If now you run the following code you will plot the result, which was presented in the Scope, in a Matlab figure. x=scopedata.signals.values; t=scopedata.time; plot(t,x); Make a simulation of the system considering 0 input (u(t)=0) and initial conditions given as [0 0] (which is: zero angle and zero angular velocity). To introduce the initial states in the simulink block diagram, double-click the two integrators and introduce in the appropriate field the values for the initial states. Having understood how the ode functions and simulink block diagrams can be used to simulate a system, given its differential equation dynamics, now you can work on the homework problems. 7

Name: A. Explain, in the provided space, what each of the lines of code in this program section is doing. (Comment the code.) function main tint= [0 10] ; % defines the time interval [t0 tf], we will simulate % the system for 10 seconds x0= [pi/2 0]' ; % initial conditions [t,x]= ode23( robot, tint, x0); plot(t,x); % plots the system states versus time a1=3; x1=cos(x(:,1))*a1; y1=sin(x(:,1))*a1; figure(3); for i=1:length(x1), figure(3); plot(0,0,'o',x1(i),y1(i),'o',[0 x1(i)],[0 y1(i)],'-r'); axis([-1.2 1.2-1.2 1.2]); pause(t(i+1)-t(i)); end B. Explain the behavior of the one link robotic system in response to 0 input (u(t)=0) and initial conditions given as [0 0] (which is: zero angle and zero angular velocity). 8