33
1 © 2012 The MathWorks, Inc. Real Time Testing of PMSM Controller using xPC Target Turnkey solution August 08, 2012 Prasanna Deshpande Application Engineering MathWorks India

Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

1 © 2012 The MathWorks, Inc.

Real Time Testing of PMSM

Controller using xPC Target

Turnkey solution

August 08, 2012

Prasanna Deshpande

Application Engineering

MathWorks India

Page 2: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

3

What is real time testing – Rapid Prototyping

Wiring and

Signal Conditioning

xPC Target System Production Plant Hardware

Code

Generation Execution

• Host/Target

• Real-time

Page 3: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

4

What is real time testing – Hardware in the

loop simulation

Wiring and

Signal Conditioning

ECU or MicroController Real-time System

Execution

• Host/Target/Target

• Real-time

Code

Generation

Code

Generation

Page 4: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

6

– IO Driver in the form of Simulink library

– Interface the model with a real time kernel

– Execute the model with a specific sample time

– A scalable, flexible hardware platform – for expansion

– Robust hardware – should be able to sustain in plant – noisy

environment

Challenges or needs faced by the RP engineer

Page 5: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

7

Today’s Agenda

Converting simulation model to a real time application

– Configuring I/Os

– Choosing the right target hardware

– Preparing the model for code generation

– Build and Download

Interfacing with real time application

– MATLAB Scripts

– xPC target explorer

– Simulink external mode

– xPC target API

Converting a physical system model to real time

application for HIL simulation

Wrap-up

Page 6: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

8

Starting point: Simulation Model of PMSM

Controller

+ u y s1 s2

s3

Page 7: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

9

Today’s Agenda

Converting simulation model to a real time application

– Configuring I/Os

– Choosing the right target hardware

– Preparing the model for code generation

– Build and Download

Interfacing with real time application

– MATLAB Scripts

– xPC target explorer

– Simulink external mode

– xPC target API

Converting a physical system model to real time

application for HIL simulation

Wrap-up

Page 8: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

10

Converting the simulation model to a real time

application: Configuring I/Os

s1 s2

s3

PWM A

PWM B

PWM C

I B

I A

A

B

Index

Page 9: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

11

Choosing the right target hardware: Mobile

Real-Time Target Machine

Performance : – 2GHz Dual Core Intel processor

– 2GB RAM, 100GB HD

– Gigabit Ethernet

Expandable : 5 PCI Slots

Digital and Analog I/O, CAN, Serial, etc.

FPGA Expansion Card : – High-speed PWM and Quadrature generation and decoding

– High-frequency control loops

– Programmable with MathWorks HDL Coder

This is the xPC Target Turnkey Computer

Page 10: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

12

Hardware Detailed Block Diagram

Power

Electronics

PMSM

Motor

Encoder

PWM A

PWM B

PWM C

A

B

Index

I A

I B IO 101

AI Card

IO 313

FPGA Card

xPC Target Turnkey Mobile Machine

P

C

I

x86

CPU

Page 11: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

13

Converting the simulation model to real time

application: Preparing model for code

generation

Solver settings

Code Generation Settings

xPC target options

Hardware

Implementation

- Fixed step

- xPC target “tlc”

- Execution Options

- HW device type

Page 12: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

14

Host computer

with MATLAB

xPC Target Turnkey

computer

Ethernet or RS 232

1

2

3

An environment that allows the real-time execution of Simulink

models on a separate xPC Target Kernel compatible PC.

Simulink

Coder

Build the application and download to the

target hardware

Page 13: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

15

Today’s Agenda

Converting simulation model to a real time application

– Configuring I/Os

– Choosing the right target hardware

– Preparing the model for code generation

– Build and Download

Interfacing with real time application

– MATLAB Scripts

– xPC target explorer

– Simulink external mode

– xPC target API

Converting a physical system model to real time

application for HIL simulation

Wrap-up

Page 14: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

16

Interfacing with the real time application:

Logging data and tuning parameters

From standard MATLAB interface

Define signals to log

Add file scope without modifying the model

Define the parameters to tune

Connect and run

Tune parameters

Stop the application, retrieve data from target and

plot

Page 15: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

17

MATLAB Scripts Example – using the “tg” Object properties

>> tg = xpc; % Create xPC Target object

>> tg.load('mct_xpcClosedLoop'); % Load application

>> tg.start; % Start application

>> Amp=tg.getparamid('Signal Generator', 'Amplitude');

>> tg.setparam(Amp,2) % Change Amplitude value

ans =

parIndexVec: 2

OldValues: 0.5000

NewValues: 2

>> tg.stop; % Stop application

>> plot(tg.TimeLog,tg.OutputLog(:,[1 2])) % Plot data

Page 16: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

18

Parameters

Signals

Double-click

to edit

xPC Target Explorer – xpcexplr Example – tune parameters, monitor & plot signals

Page 17: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

19

Simulink External Mode Example – Simulink model is the interface to the target real-time application

External Model

Page 18: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

20

xPC Target APIs Example – Create & Edit Custom UIs

.NET, C, COM APIs

Drag-and-drop controls

Program callbacks with ease using

Intellisense

Drag and drop

controls

Graphical interface design

Define callbacks

and GUI behavior

Instant access to all

API objects

Page 19: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

21

3rd Party Solutions GUI/HMI Tools

OpenSim

Altia Design

VISUALCONNX

Page 20: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

22

Host Computer

with MATLAB

xPC Target Turnkey

Computer

Ethernet or RS 232

An Environment that provides interactive access between the

real-time application and the host computer

Allows live parameter tuning, control from the original Simulink

model and offline analysis support in MATLAB.

Host computer

with MATLAB

xPC Target Turnkey

computer

Ethernet or RS 232

Revisit: What is xPC Target?

Page 21: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

23

Host computer

with MATLAB

xPC Target Turnkey

computer

Ethernet or RS 232

3

An Environment that provides interactive access between the

real-time application and the host computer

Allows live parameter tuning, control from the original Simulink

model and offline analysis support in MATLAB.

1

2

4

2

Revisit: What is xPC Target?

Page 22: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

24

xPC Target Turnkey PC

Host computer

with MATLAB

xPC Target Turnkey

computer

Ethernet or RS 232

An Environment that provides numerous I/O device driver blocks

Blocks are easily configurable within the Simulink model and

communicate with actual hardware in real-time.

Revisit: What is xPC Target?

Page 23: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

25

xPC Target

Turnkey computer

An Environment that provides numerous I/O device driver blocks

Blocks are easily configurable within the Simulink model and

communicate with actual hardware in real-time.

Revisit: What is xPC Target?

Page 24: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

26

xPC Target Turnkey

Target Hardware partnership with Speedgoat

Hardware customized to fit your performance and I/O needs

Saves you time and hassle of acquiring, installing, configuring, and testing

Commercial Version : http://www.mathworks.com/products/xpctarget/supported-hardware

Academia Version : http://www.mathworks.com/academia/xpctarget-turnkey

Page 25: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

27

– IO Driver in the form of Simulink library

– Interface the model with a real time kernel

– Execute the model with a specific sample time

– A scalable, flexible hardware platform – for expansion

– Robust hardware – should be able to sustain in plant – noisy

environment

Challenges or needs faced by the RP engineer

Page 26: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

28

Today’s Agenda

Converting simulation model to a real time application

– Configuring I/Os

– Choosing the right target hardware

– Preparing the model for code generation

– Build and Download

Interfacing with real time application

– MATLAB Scripts

– xPC target explorer

– Simulink external mode

– xPC target API

Converting a physical system model to real time

application for HIL simulation

Wrap-up

Page 27: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

29

Must find combination of model fidelity

and solver settings that permits real-time

execution and delivers accurate results

Simulation

Execution

Processing

I/O and

Other Tasks

Idle

Safety Margin Affected by

step size

Step Size

Minimum Possible Step Size Smaller step sizes result in overrun

Execution Time Affected by solver choice,

# of iterations and model fidelity

Chosen Step Size

Trapezoidal

Rule

ode14x

explicit

Backward

Euler

Solver Choice

Maximum Possible Step Size

High Low

Model Fidelity

Many Few

# of Iterations

Large Small

Step Size

Larger step sizes result in poor accuracy and robustness

Affected by solver choice, # of nonlinear iterations, and model fidelity

Converting a physical system model to real

time application for HIL Simulation

Page 28: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

30

Steps For

Moving to

Real-Time

Simulation

Flowchart describes

steps engineers take

1. Obtain reference results

2. Check if real-time capable

3. Configure for fixed-step,

fixed cost simulation

4. Find settings that deliver

acceptable results and speed

5. Test on real time platform

6. Adjust if necessary

New results

match reference

results?

Acceptable

simulation

speed?

Executes

in real time with

accurate results?

N

Y

N

Y

Y N Success

N

Is the solver

taking too many

small steps?

2

Simulate with

fixed-step,

fixed-cost solver

3

Simulate on

real-time platform

5

Obtain reference results

and estimate step size

with variable-step solver

1

4

Adjust model

to make it

real-time capable

6

Decrease iterations

and/or increase

step size

Increase iterations

and/or decrease

step size

N

Y

N

Page 29: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

31

Configuring Local Solvers

In Simscape

Configure per physical network

– Choose solver and sample time

– Sample rates can be different

Must be integer multiple of

global sample time

Backward Euler

– Designed for robustness

– Tends to damp oscillations

Trapezoidal Rule

– Designed for accuracy

– Tends to capture oscillations

Controller

Simscape

Physical

Network

Simscape

Physical

Network

Local fixed-step

implicit solver #1 Fixed-step

explicit solver

Local fixed-step

implicit solver #2

Page 30: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

32

Today’s Agenda

Converting simulation model to a real time application

– Configuring I/Os

– Choosing the right target hardware

– Preparing the model for code generation

– Build and Download

Interfacing with real time application

– MATLAB Scripts

– xPC target explorer

– Simulink external mode

– xPC target API

Converting a physical system model to real time

application for HIL simulation

Wrap-up

Page 31: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

33

Training Services Exploit the full potential of MathWorks products

Flexible delivery options:

Public training available in several cities

Onsite training with standard or

customized courses

Web-based training with live, interactive

instructor-led courses

More than 30 course offerings:

Introductory and intermediate training on MATLAB, Simulink,

Stateflow, code generation, and Polyspace products

Specialized courses in control design, signal processing, parallel computing,

code generation, communications, financial analysis,

and other areas

www.mathworks.in/training

Page 32: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

34

Public Trainings in the next Few Months

Course Dates Location

Simulink for System and Algorithm Modeling 20 Aug 2012 – 21 Aug 2012 Bangalore

Embedded Coder for Production Code Generation 22 Aug 2012 – 24 Aug 2012 Bangalore

MATLAB Fundamentals 03 Sep 2012 – 05 Sep 2012 Bangalore

MATLAB Programming Techniques 06 Sep 2012 – 07 Sep 2012 Bangalore

MATLAB Fundamentals 24 Sep 2012 – 26 Sep 2012 Pune

Simulink for System and Algorithm Modeling 27 Sep 2012 – 28 Sep 2012 Pune

Statistical Methods in MATLAB 15 Oct 2012 – 16 Oct 2012 Bangalore

MATLAB Based Optimization Techniques 17 Oct 2012 Bangalore

Stateflow for Logic-Driven System Modeling 18 Oct 2012 – 19 Oct 2012 Bangalore

Email: [email protected] URL: http://www.mathworks.in/services/training Phone: 080-6632-6000

Page 33: Real Time Testing of PMSM Controller using xPC Target ...€¦ · –Choosing the right target hardware –Preparing the model for code generation –Build and Download Interfacing

35

MathWorks India Contact Details

URL: http://www.mathworks.in

E-mail: [email protected]

Technical Support: www.mathworks.in/myservicerequests

Tel: +91-80-6632 6000

Fax: +91-80-6632 6010

• MathWorks India Private Limited Salarpuria Windsor Building Third Floor, 'A' Wing No.3 Ulsoor Road Bangalore - 560042, Karnataka India

Thank You for Attending

Talk to Us – We are Happy to Support You