Skip to content

Commit

Permalink
* Small corrections for command trajectories, #61
Browse files Browse the repository at this point in the history
  • Loading branch information
MBaranskiEBC committed Jul 26, 2019
1 parent b6c35bf commit f26d5fc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 263 deletions.
24 changes: 12 additions & 12 deletions pyDMPC/ControlFramework/Init.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,58 +65,58 @@
# Subsystems
sys_id.append(0)
name.append("Heater")
model_type.append("Modelica")
model_type.append("Scikit")
ups_neigh.append(1)
downs_neigh.append(None)
par_neigh.append(None)
input_names.append(["coolerTemperature.T"])
input_variables.append([r"variation.table[1,2]"])
inputs.append(range(280,325,5))
inputs.append([i for i in range(280,325,5)])
output_names.append(["supplyAirTemperature.T"])
set_points.append([303])
state_var_names.append(["heaterInitials[1].y"])
model_state_var_names.append(["mas1.k"])
start.append(0.)
stop.append(3600)
incr.append(10.)
opt_time.append(0)
samp_time.append(10)
opt_time.append(600)
samp_time.append(60)
lib_paths.append(glob_lib_paths)
res_path.append(glob_res_path + "\\" + name_wkdir)
dym_path.append(glob_dym_path)
mod_path.append('ModelicaModels.SubsystemModels.DetailedModels.Heater')
mod_path.append(f'{glob_res_path}\\heater')
command_names.append(["valveHeater"])
command_variables.append(["decisionVariables.table[1,2]"])
commands.append([[i] for i in range(0,105,5)])
commands.append([[0,0], [10,10], [30,30], [60,60], [80,80], [100,100]])
traj_points.append([])
traj_var.append([])
cost_fac.append([0.5, 0.0, 1.0])

sys_id.append(1)
name.append("Cooler")
model_type.append("Modelica")
model_type.append("Scikit")
ups_neigh.append(None)
downs_neigh.append([0])
par_neigh.append(None)
input_names.append(["preHeaterTemperature.T"])
input_variables.append([r"variation.table[1,2]"])
inputs.append(range(280,325,5))
inputs.append([i for i in range(280,325,5)])
output_names.append(["supplyAirTemperature.T"])
set_points.append([303])
state_var_names.append(["coolerInitials[1].y"])
model_state_var_names.append(["hex.ele[1].mas.T"])
start.append(0.)
stop.append(3600.)
incr.append(10.)
opt_time.append(0)
samp_time.append(10)
opt_time.append(600)
samp_time.append(60)
lib_paths.append(glob_lib_paths)
res_path.append(glob_res_path + "\\" + name_wkdir)
dym_path.append(glob_dym_path)
mod_path.append(r'ModelicaModels.SubsystemModels.DetailedModels.Cooler')
mod_path.append(f'{glob_res_path}\\cooler')
command_names.append(["valveCooler"])
command_variables.append(["decisionVariables.table[1,2]"])
commands.append([[i] for i in range(0,105,5)])
commands.append([[0,0], [10,10], [30,30], [60,60], [80,80], [100,100]])
traj_points.append([])
traj_var.append([])
cost_fac.append([0.5, 1.0, 0])
9 changes: 6 additions & 3 deletions pyDMPC/ControlFramework/Modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,13 @@ def load_mod(self):
def write_inputs(self):
import numpy as np

commands = [com*np.ones(60) for com in self.states.commands]
inputs = [inp*np.ones(60) for inp in self.states.inputs]
commands_1 = self.states.commands[0]*np.ones(10)
commands_2 = self.states.commands[1]*np.ones(50)
commands = commands_1.tolist() + commands_2.tolist()
inputs = self.states.inputs[0]*np.ones(60)
inputs = inputs.tolist()

inputs = np.stack((commands + inputs), axis=1)
inputs = np.stack(([commands] + [inputs]), axis=1)

self.scal_inputs = self.scaler.transform(inputs)

Expand Down
14 changes: 8 additions & 6 deletions pyDMPC/ControlFramework/Subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,32 +273,32 @@ def find_nearest(self, a, a0):
import numpy as np
"Element in nd array `a` closest to the scalar value `a0`"
idx = np.abs(a - a0).argmin()
return a.flat[idx]

return idx

def interp(self, iter_real):
import scipy.interpolate
import numpy as np

if iter_real == "iter" and self.coup_vars_rec != []:
inp = self.coup_vars_rec
else:
inp = self.model.states.inputs

#print(f"{self.name}: {inp}")
idx = self.find_nearest(np.asarray(self.inputs), inp[0])

if self.command_send != []:
if (type(self.command_send) is scipy.interpolate.interpolate.interp1d):
self.fin_command = self.command_send(inp[0])
else:
self.fin_command = self.command_send[self.find_nearest(self.command_send, inp[0])]
self.fin_command = self.command_send[idx]

if self.coup_vars_send != []:
if type(self.coup_vars_send) is scipy.interpolate.interpolate.interp1d:
self.fin_coup_vars = self.coup_vars_send(inp[0])
else:
self.fin_coup_vars = self.coup_vars_send[self.find_nearest(self.command_send, inp[0])]
self.fin_coup_vars = self.coup_vars_send[idx]

#print(f"{self.name}: {self.fin_command}")
#time.sleep(2)

def get_inputs(self):

Expand Down Expand Up @@ -329,6 +329,8 @@ def send_commands(self):

if (cur_time - self.last_write) > self.model.times.samp_time:
self.last_write = cur_time

print(self.fin_command[0])

if self.model.states.command_names is not None:
for nam in self.model.states.command_names:
Expand Down
Loading

0 comments on commit f26d5fc

Please sign in to comment.