pyMPC
pyMPC copied to clipboard
Runtime change of matrices A and B
Hello,
I am using this repo to control a race car around a track. I've been debugging like crazy, yet the solver always outputs the steering angle as zero. I linearize the dynamics at each time step, so i have to change the matrices A and B at every time step. How can i do it with the given API?
Hello Bruno, unfortunately this software does not support dynamic update of the matrices A/B to date. It is something I'd like implement, but have no time at the moment! It should not be that hard, just very boring and error-prone to code! If you look at the inner of pyMPC, you could for instance repeat certain operation that are in _compute_QP_matrices (lines 534-550) inside update_QP_matrices.
IOtherwise, you could construct a new pyMPC object at each time step and use it just for that time step. That would be inefficient and maybe not good for real-time, but still better than nothing!
I may also code time-varying MPC in cvxpy soon (that will be slower, but easier to code). I'll keep you posted!
Cheers, Marco
Hello,
I do this to dynamically change A and B:
def calculate_steering_angle(self,state,uMPC, Xref): mpc.compute_QP_matrices() y = np.array([state.x,state.y,state.yaw,state.v,state.delta,state.yaw_rate,state.slip_angle]) self.general_mpc.update(y,uMPC,xref=Xref) # update with measurement and solves uMPC, info = self.general_mpc.output(return_x_seq=True) # MPC step (u_k value)
return uMPC[0]
There must be an overwrite somewhere.
Thanks for the reply, i will try to debug this.
De: Marco Forgione [email protected] Enviado: quinta-feira, 28 de janeiro de 2021 14:29 Para: forgi86/pyMPC [email protected] Cc: Bruno Pinto [email protected]; Author [email protected] Assunto: Re: [forgi86/pyMPC] Runtime change of matrices A and B (#2)
Hello Bruno, unfortunately this software does not support dynamic update of the matrices A/B to date. It is something I'd like implement, but have no time at the moment! It should not be that hard, just very boring and error-prone to code! If you look at the inner of pyMPC, you could for instance repeat certain operation that are in _compute_QP_matrices (lines 534-550) inside update_QP_matrices.
IOtherwise, you could construct a new pyMPC object at each time step and use it just for that time step. That would be inefficient and maybe not good for real-time, but still better than nothing!
I may also code time-varying MPC in cvxpy soon (that will be slower, but easier to code). I'll keep you posted!
Cheers, Marco
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/forgi86/pyMPC/issues/2#issuecomment-769096877, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALULS62T74VKG7C4AQLHLSDS4FYE5ANCNFSM4WXAFYSA.
Hello Bruno, I am not 100% sure, but I think your code does not call the MPCController.solve() method (which internally calls the solve method of the OSQP problem).
In my original code, solve() is called by update(), but you do not see any call to update() or directly to solve() in your snippet! Note that the MPCController.output() method does not solve the problem, it just returns the output (which should be previosuly computed and stored by solve())
Cheers, Marco