MATLAB Export
Stephanie Tsuei, 2014

This folder contains the files required to export controllers to Simulink
blocks and a couple examples for reference.

Required software (in addition to Tulip):
    - Matlab
    - Simulink
    - Stateflow
    - MPT Toolbox 3.0.x (http://people.ee.ethz.ch/~mpt/3/)

Provided files below:

	- Python files: tomatlab.py
    - Matlab files: get_input.m, load_tulip.m, load_continuous.m, cont_to_disc.m



USAGE

1) Run the converter after synthesis:

	import tomatlab
	...
	ctrl = synth.synthesize(...)               # returns a Mealy Machine
	tomatlab.export(ctrl, 'system.mat')        # exports .mat file

2) In MATLAB, make sure that these files are in the MATLAB path:
    - get_input.m
    - get_input_switched.m
    - load_tulip.m
    - load_continuous.m
    - cont_to_disc.m

3) In MATLAB, define the variables 'matfile' and 'timestep'. Run load_tulip.m. A
   new Simulink model containing the Mealy Machine should appear.


EXAMPLES

1) Discrete Example:

	discrete.py is a modified version of /examples/robot_planning/discrete.py
	that contains a line at the end for generating a Stateflow chart from the
	Mealy Machine "ctrl". After running discrete.py, running the file
    "load_discrete.m" opens up a Simulink model that contains the Tulip Mealy
    Machine, a random park signal generator, and output scopes.


2) Continuous Example:

    continuous.py is a modified version of
    /examples/robot_planning/continuous.py. Run load_robot.m after continuous.py
    in order to see a completed Simulink setup.


KNOWN ISSUES

Issues that may be fixed in the future are starred.

1*) Stateflow charts are nearly unreadable.

2*) Must discretize with use_all_horizon = False

3) Must discretize with conservative = True. This will not be supported because
   the MPT toolbox does not support non-convex regions.

4) domain must not be None in LtiSysDyn.

5*) If there are any env_actions or sys_actions, both must be there.

6*) No custom env_action and sys_action names passed into synthesize function.

7*) Can't handle having different discretization parameters for each mode. When
    exporting a .mat file for a switched system, make sure that `disc_params` is
    the same for all modes and pass one of those modes into tomatlab.export()
