-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtemplate_simulator.py
More file actions
71 lines (57 loc) · 1.97 KB
/
Copy pathtemplate_simulator.py
File metadata and controls
71 lines (57 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# This file is part of do-mpc
#
# do-mpc: An environment for the easy, modular and efficient implementation of
# robust nonlinear model predictive control
#
# Copyright (c) 2014-2019 Sergio Lucia, Alexandru Tatulea-Codrean
# TU Dortmund. All rights reserved
#
# do-mpc is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3
# of the License, or (at your option) any later version.
#
# do-mpc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with do-mpc. If not, see <http://www.gnu.org/licenses/>.
import numpy as np
from casadi import *
from casadi.tools import *
import pdb
import sys
import os
rel_do_mpc_path = os.path.join('..','..')
sys.path.append(rel_do_mpc_path)
import do_mpc
def template_simulator(model):
"""
--------------------------------------------------------------------------
template_simulator: tuning parameters
--------------------------------------------------------------------------
"""
simulator = do_mpc.simulator.Simulator(model)
params_simulator = {
# Note: cvode doesn't support DAE systems.
'integration_tool': 'idas',
'abstol': 1e-8,
'reltol': 1e-8,
't_step': 0.04
}
simulator.set_param(**params_simulator)
p_num = simulator.get_p_template()
p_num['m1'] = 0.2
p_num['m2'] = 0.2
def p_fun(t_now):
return p_num
simulator.set_p_fun(p_fun)
tvp_template = simulator.get_tvp_template()
def tvp_fun(t_ind):
return tvp_template
simulator.set_tvp_fun(tvp_fun)
simulator.setup()
return simulator