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

Post on 04-Jun-2018

244 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Introduction to Assignment 2 andDebuggerTSFS03 Lesson

Mahdi Morsali

Vehicular SystemsDepartment of Electrical EngineeringLinkoping University

April 03, 2017

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Example in Matlab

TSFS03 Lesson Mahdi Morsali April 03, 2017 13 / 15

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

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

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

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

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

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

Thanks for your attention

Mahdi Morsalimahdi.morsali@liu.se

www.liu.se

top related