introduction to assignment 2 and debugger - tsfs03 lesson · introduction to assignment 2 and...

53
Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering Link¨ oping University April 03, 2017

Upload: duongthu

Post on 04-Jun-2018

243 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Introduction to Assignment 2 andDebuggerTSFS03 Lesson

Mahdi Morsali

Vehicular SystemsDepartment of Electrical EngineeringLinkoping University

April 03, 2017

Page 2: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

1 Hand-in 2 Introduction2 DDP Algorithm Example3 Implementation4 Debugging in Matlab5 Summary

Page 3: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

1 Hand-in 2 Introduction2 DDP Algorithm Example3 Implementation4 Debugging in Matlab5 Summary

Page 4: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Hand-in 2 Introduction

For a known drive cycle, how to optimally operate the electricmotor/combustion engine?

• Two hybrid architectures: parallel and series.

• Model the vehicles following the quasi-static approach.

• Solve the problem with Deterministic Dynamic Programming.

Hand-in Goals:

• Acquire knowledge and experience with DDP.

• Acquire knowledge about the properties and differences betweenparallel and series architectures.

TSFS03 Lesson Mahdi Morsali April 03, 2017 3 / 15

Page 5: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Hand-in 2 Introduction

For a known drive cycle, how to optimally operate the electricmotor/combustion engine?

• Two hybrid architectures: parallel and series.

• Model the vehicles following the quasi-static approach.

• Solve the problem with Deterministic Dynamic Programming.

Hand-in Goals:

• Acquire knowledge and experience with DDP.

• Acquire knowledge about the properties and differences betweenparallel and series architectures.

TSFS03 Lesson Mahdi Morsali April 03, 2017 3 / 15

Page 6: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Hand-in 2 Introduction

For a known drive cycle, how to optimally operate the electricmotor/combustion engine?

• Two hybrid architectures: parallel and series.

• Model the vehicles following the quasi-static approach.

• Solve the problem with Deterministic Dynamic Programming.

Hand-in Goals:

• Acquire knowledge and experience with DDP.

• Acquire knowledge about the properties and differences betweenparallel and series architectures.

TSFS03 Lesson Mahdi Morsali April 03, 2017 3 / 15

Page 7: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Hand-in 2 Introduction

For a known drive cycle, how to optimally operate the electricmotor/combustion engine?

• Two hybrid architectures: parallel and series.

• Model the vehicles following the quasi-static approach.

• Solve the problem with Deterministic Dynamic Programming.

Hand-in Goals:

• Acquire knowledge and experience with DDP.

• Acquire knowledge about the properties and differences betweenparallel and series architectures.

TSFS03 Lesson Mahdi Morsali April 03, 2017 3 / 15

Page 8: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Hand-in 2 Introduction

For a known drive cycle, how to optimally operate the electricmotor/combustion engine?

• Two hybrid architectures: parallel and series.

• Model the vehicles following the quasi-static approach.

• Solve the problem with Deterministic Dynamic Programming.

Hand-in Goals:

• Acquire knowledge and experience with DDP.

• Acquire knowledge about the properties and differences betweenparallel and series architectures.

TSFS03 Lesson Mahdi Morsali April 03, 2017 3 / 15

Page 9: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Hand-in 2 Introduction

For a known drive cycle, how to optimally operate the electricmotor/combustion engine?

• Two hybrid architectures: parallel and series.

• Model the vehicles following the quasi-static approach.

• Solve the problem with Deterministic Dynamic Programming.

Hand-in Goals:

• Acquire knowledge and experience with DDP.

• Acquire knowledge about the properties and differences betweenparallel and series architectures.

TSFS03 Lesson Mahdi Morsali April 03, 2017 3 / 15

Page 10: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

1 Hand-in 2 Introduction2 DDP Algorithm Example3 Implementation4 Debugging in Matlab5 Summary

Page 11: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

DDP Example

Graphical illustration of the solution procedure

0 1 2

1

2

3

2

1

0

x JN(xN)

tNN − 1

tbta

k =

TSFS03 Lesson Mahdi Morsali April 03, 2017 5 / 15

Page 12: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

DDP Example

Graphical illustration of the solution procedure

0 1 2

1

2

3

2

1

0

0

2

4

2x JN(xN)

tNN − 1

tbta

k =

TSFS03 Lesson Mahdi Morsali April 03, 2017 5 / 15

Page 13: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

DDP Example

Graphical illustration of the solution procedure

2

1

2

0

2

4

0 1 2

1

2

3

2

1

0

x

k =

ta tb

N − 1 tN

JN(xN)

TSFS03 Lesson Mahdi Morsali April 03, 2017 5 / 15

Page 14: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

DDP Example

Graphical illustration of the solution procedure

2

1

0

2

0

2

4

0 1 2

1

2

3

2

1

0

x

k =

ta tb

N − 1 N t

JN(xN)

TSFS03 Lesson Mahdi Morsali April 03, 2017 5 / 15

Page 15: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

DDP Example

Graphical illustration of the solution procedure

2

1

0

1

2

0

2

4

0 1 2

1

2

3

2

1

0

N

x

k =

ta tb

t

JN(xN)

N − 1

TSFS03 Lesson Mahdi Morsali April 03, 2017 5 / 15

Page 16: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

DDP Example

Graphical illustration of the solution procedure

2

1

0

1

2

2

0

2

0 1 2

1

2

3

2

1

0

x

k =

ta tb

N − 1 tN

JN(xN)

TSFS03 Lesson Mahdi Morsali April 03, 2017 5 / 15

Page 17: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

DDP Example

Graphical illustration of the solution procedure

2

1

0

1

2

3

2

0

0 1 2

1

2

3

2

1

0

x

k =

ta tb

N − 1 N t

JN(xN)

TSFS03 Lesson Mahdi Morsali April 03, 2017 5 / 15

Page 18: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

DDP Example

Graphical illustration of the solution procedure

2

3

2

1

2

0

1

0 1 N2

1

2

3

2

1

0

0

2

4

x

k =

ta tb

N − 1 t

JN(xN)

TSFS03 Lesson Mahdi Morsali April 03, 2017 5 / 15

Page 19: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

DDP Example

Graphical illustration of the solution procedure

2

3

2

1

2

0

1

0 1 N2

1

2

3

2

1

0

0

2

4

x

k =

ta tb

N − 1 t

JN(xN)

Matrix formulation benefits:

Each iteration compute all arcs using a vector/matrix

TSFS03 Lesson Mahdi Morsali April 03, 2017 5 / 15

Page 20: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

1 Hand-in 2 Introduction2 DDP Algorithm Example3 Implementation4 Debugging in Matlab5 Summary

Page 21: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Algorithm Implementation

Generic DDP functions:

• dynProg1D.m – Solves a dynamic programming problem in onevariable

• dynProg2D.m – Solves a dynamic programming problem in twovariables

Problem specific scripts and functions that you need to complete:

• testHybrids.m – Template for setting up the problem

• parallelHybrid.m – Template for the parallel hybrid vehicle

• seriesHybrid.m – Template for the series hybrid vehicle

TSFS03 Lesson Mahdi Morsali April 03, 2017 7 / 15

Page 22: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Algorithm Implementation

Generic DDP functions:

• dynProg1D.m – Solves a dynamic programming problem in onevariable

• dynProg2D.m – Solves a dynamic programming problem in twovariables

Problem specific scripts and functions that you need to complete:

• testHybrids.m – Template for setting up the problem

• parallelHybrid.m – Template for the parallel hybrid vehicle

• seriesHybrid.m – Template for the series hybrid vehicle

TSFS03 Lesson Mahdi Morsali April 03, 2017 7 / 15

Page 23: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 24: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 25: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 26: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 27: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 28: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 29: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 30: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 31: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 32: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 33: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 34: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

How to compute Arc CostsQuasi-static approach (backward power flow)

costVector = parallelHybrid(t vec,SOC start,SOC final)

• Calculate the whole bundle of arcs in one step.

• Add boundary and constraint checks.

• Be careful with: v = 0, Gear = 0 and sign convention.

Useful MATLAB commands:

• Computing time: tic, toc

• Create matrices: zeros, ones

• Modify matrices: meshgrid, repmat

• Element-wise operations: ./ or .*

• Logical indexing: m f(m f<0)

• Trick: P = T · ω · ηsign(T )

TSFS03 Lesson Mahdi Morsali April 03, 2017 8 / 15

Page 35: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Send parameters to parallelHybrid.mThe driving cycle used is set in testHybrids.m and is used inparallelHybrid.m. Two solutions to access T z, V z, and G z

1. Take the variables as inputs to dynProg1D and use them in thecall for parallelHybrid.m

2. Use global variables.

testHybrids.m:

global V_z

load EUDC_MAN

parallelHybrid.m:

global V_z

V z is available

Easier solution since the scripts are prepared to use global variables.

First global variable definition, then assign value.

Be cautious to not overwrite variables → Read only variables.

TSFS03 Lesson Mahdi Morsali April 03, 2017 9 / 15

Page 36: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Send parameters to parallelHybrid.mThe driving cycle used is set in testHybrids.m and is used inparallelHybrid.m. Two solutions to access T z, V z, and G z

1. Take the variables as inputs to dynProg1D and use them in thecall for parallelHybrid.m

2. Use global variables.

testHybrids.m:

global V_z

load EUDC_MAN

parallelHybrid.m:

global V_z

V z is available

Easier solution since the scripts are prepared to use global variables.

First global variable definition, then assign value.

Be cautious to not overwrite variables → Read only variables.

TSFS03 Lesson Mahdi Morsali April 03, 2017 9 / 15

Page 37: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Send parameters to parallelHybrid.mThe driving cycle used is set in testHybrids.m and is used inparallelHybrid.m. Two solutions to access T z, V z, and G z

1. Take the variables as inputs to dynProg1D and use them in thecall for parallelHybrid.m

2. Use global variables.

testHybrids.m:

global V_z

load EUDC_MAN

parallelHybrid.m:

global V_z

V z is available

Easier solution since the scripts are prepared to use global variables.

First global variable definition, then assign value.

Be cautious to not overwrite variables → Read only variables.

TSFS03 Lesson Mahdi Morsali April 03, 2017 9 / 15

Page 38: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Send parameters to parallelHybrid.mThe driving cycle used is set in testHybrids.m and is used inparallelHybrid.m. Two solutions to access T z, V z, and G z

1. Take the variables as inputs to dynProg1D and use them in thecall for parallelHybrid.m

2. Use global variables.

testHybrids.m:

global V_z

load EUDC_MAN

parallelHybrid.m:

global V_z

V z is available

Easier solution since the scripts are prepared to use global variables.

First global variable definition, then assign value.

Be cautious to not overwrite variables → Read only variables.

TSFS03 Lesson Mahdi Morsali April 03, 2017 9 / 15

Page 39: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Send parameters to parallelHybrid.mThe driving cycle used is set in testHybrids.m and is used inparallelHybrid.m. Two solutions to access T z, V z, and G z

1. Take the variables as inputs to dynProg1D and use them in thecall for parallelHybrid.m

2. Use global variables.

testHybrids.m:

global V_z

load EUDC_MAN

parallelHybrid.m:

global V_z

V z is available

Easier solution since the scripts are prepared to use global variables.

First global variable definition, then assign value.

Be cautious to not overwrite variables → Read only variables.

TSFS03 Lesson Mahdi Morsali April 03, 2017 9 / 15

Page 40: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Send parameters to parallelHybrid.mThe driving cycle used is set in testHybrids.m and is used inparallelHybrid.m. Two solutions to access T z, V z, and G z

1. Take the variables as inputs to dynProg1D and use them in thecall for parallelHybrid.m

2. Use global variables.

testHybrids.m:

global V_z

load EUDC_MAN

parallelHybrid.m:

global V_z

V z is available

Easier solution since the scripts are prepared to use global variables.

First global variable definition, then assign value.

Be cautious to not overwrite variables → Read only variables.

TSFS03 Lesson Mahdi Morsali April 03, 2017 9 / 15

Page 41: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Solution Postprocess

How to retrieve the solution after calculating the cost to go matrixis not trivial.

Helpful things to check:

• Start with the parallel hybrid.

• Check what are the outputs from dynProg1D.m anddynProg2D.m

• How are the costs stored in the DDP algorithm?

• How is the optimal path stored in the DDP algorithm?

TSFS03 Lesson Mahdi Morsali April 03, 2017 10 / 15

Page 42: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Solution Postprocess

How to retrieve the solution after calculating the cost to go matrixis not trivial.

Helpful things to check:

• Start with the parallel hybrid.

• Check what are the outputs from dynProg1D.m anddynProg2D.m

• How are the costs stored in the DDP algorithm?

• How is the optimal path stored in the DDP algorithm?

TSFS03 Lesson Mahdi Morsali April 03, 2017 10 / 15

Page 43: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

1 Hand-in 2 Introduction2 DDP Algorithm Example3 Implementation4 Debugging in Matlab5 Summary

Page 44: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Debugging

• Is used to identify faults in the code

• It is possible to find and use the values of parameters andvariables inside functions (that use local workspace).

Matlab debugger

• Mouse click to the left in a m-file to add a debugger point.Possible to add conditional debugger point by right click (e.g.stop at a wanted index in a for loop).

• F10: Step forward (one line)

• F11: Step inside called function

• F5: Continue till next debugger point or till the end

TSFS03 Lesson Mahdi Morsali April 03, 2017 12 / 15

Page 45: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Debugging

• Is used to identify faults in the code

• It is possible to find and use the values of parameters andvariables inside functions (that use local workspace).

Matlab debugger

• Mouse click to the left in a m-file to add a debugger point.Possible to add conditional debugger point by right click (e.g.stop at a wanted index in a for loop).

• F10: Step forward (one line)

• F11: Step inside called function

• F5: Continue till next debugger point or till the end

TSFS03 Lesson Mahdi Morsali April 03, 2017 12 / 15

Page 46: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Example in Matlab

TSFS03 Lesson Mahdi Morsali April 03, 2017 13 / 15

Page 47: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

1 Hand-in 2 Introduction2 DDP Algorithm Example3 Implementation4 Debugging in Matlab5 Summary

Page 48: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Summary

• Understand how DDP works and how returns the solution.

• Implement your hybrid models in paper first.

• Use your notes to implement your code with the giventemplates.

• Make use of the debugging tool to polish your code.

• Answer the questions and discuss your results in the Hand-inreport.

TSFS03 Lesson Mahdi Morsali April 03, 2017 15 / 15

Page 49: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Summary

• Understand how DDP works and how returns the solution.

• Implement your hybrid models in paper first.

• Use your notes to implement your code with the giventemplates.

• Make use of the debugging tool to polish your code.

• Answer the questions and discuss your results in the Hand-inreport.

TSFS03 Lesson Mahdi Morsali April 03, 2017 15 / 15

Page 50: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Summary

• Understand how DDP works and how returns the solution.

• Implement your hybrid models in paper first.

• Use your notes to implement your code with the giventemplates.

• Make use of the debugging tool to polish your code.

• Answer the questions and discuss your results in the Hand-inreport.

TSFS03 Lesson Mahdi Morsali April 03, 2017 15 / 15

Page 51: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Summary

• Understand how DDP works and how returns the solution.

• Implement your hybrid models in paper first.

• Use your notes to implement your code with the giventemplates.

• Make use of the debugging tool to polish your code.

• Answer the questions and discuss your results in the Hand-inreport.

TSFS03 Lesson Mahdi Morsali April 03, 2017 15 / 15

Page 52: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Summary

• Understand how DDP works and how returns the solution.

• Implement your hybrid models in paper first.

• Use your notes to implement your code with the giventemplates.

• Make use of the debugging tool to polish your code.

• Answer the questions and discuss your results in the Hand-inreport.

TSFS03 Lesson Mahdi Morsali April 03, 2017 15 / 15

Page 53: Introduction to Assignment 2 and Debugger - TSFS03 Lesson · Introduction to Assignment 2 and Debugger TSFS03 Lesson Mahdi Morsali Vehicular Systems Department of Electrical Engineering

Thanks for your attention

Mahdi [email protected]

www.liu.se