I am writing my thesis on a multi-agent MPC controller using the do_mpc library. In my setup, I have defined a time-varying parameter called sync_ref which represents the synchronization reference for each agent. This parameter needs to be dynamically updated at each time step based on the current states of neighboring agents to ensure proper synchronization. Specifically, sync_ref should be set to the x-position of the neighboring agents as defined by an adjacency matrix.
I tried using the following functions in the mpc controller, simulator and also in the simulation loop
mpc controller:
tvp_template = mpc.get_tvp_template()
def tvp_fun(t_ind):
return tvp_template
mpcs[i].set_tvp_fun(tvp_fun)
mpc simulator:
tvp_template = simulator.get_tvp_template()
def tvp_fun(t_now):
return tvp_template
simulator.set_tvp_fun(tvp_fun)tvp_template = mpc.get_tvp_template()def tvp_fun(t_ind):
return tvp_template
mpc.set_tvp_fun(tvp_fun)
Control loop:
tvp_template = mpcs[i].get_tvp_template()
tvp_template['sync_ref'] = ref_trajectories[i]['x']
def tvp_fun(t_ind):
return tvp_template
mpcs[i].set_tvp_fun(tvp_fun)
simulators[i].set_tvp_fun(tvp_fun)
How can I correctly update the sync_ref parameter within the control loop to reflect these changes at each time step? With the existing changes, I get various error.