Error on Jbu setting is not clear

Hi :wave:

I am using the python based formulation where I want to limit the sum of control inputs to a specific value. Naturally, I have applied Jbu like this :

Jbu = np.zeros((5,nu)) # matrix for assigning thrust constrain matrix to corresponding input variables
Jbu[0,0] = 1.0
Jbu[1,1] = 1.0
Jbu[2,2] = 1.0
Jbu[3,3] = 1.0
Jbu[4,:] = np.ones((nu,)) # setting the last row to 1.0 so that it makes sum of thrusts

However this produces an error that does not make sense to me because there is a non-zero element in each row.

[[1. 0. 0. 0.]                                                                                                                                                                                                     
 [0. 1. 0. 0.]                                                                                                                                                                                                     
 [0. 0. 1. 0.]                                                                                                                                                                                                     
 [0. 0. 0. 1.]                                                                                                                                                                                                     
 [1. 1. 1. 1.]]                                                                                                                                                                                                    
Traceback (most recent call last):                                                                                                                                                                                 
  File "main_build.py", line 63, in <module>                                                                                                                                                                       
    ocp.constraints.Jbu = Jbu                                                                                                                                                                                      
  File "/home/pmg/git/acados/interfaces/acados_template/acados_template/acados_ocp.py", line 1726, in Jbu                                                                                                          
    self.__idxbu = J_to_idx(Jbu)                                                                                                                                                                                   
  File "/home/pmg/git/acados/interfaces/acados_template/acados_template/utils.py", line 310, in J_to_idx                                                                                                           
    raise Exception('Invalid J matrix structure detected, ' \                                                                                                                                                      
Exception: Invalid J matrix structure detected, must contain one nonzero element per row. 

Would you please help me understand if this is a bug or if I am missing something here?
Thank you!

Hi,

the error is correct, the matrix must contain exactly one nonzero element per row.
If you want to implement a linear constraint that is not just a bound on u, you have to use C, D, see Python Interface β€” acados documentation

Thank you for your quick response. Only suggestion would be to reframe that error message as β€œβ€¦only one non-zero…”

1 Like

Just to clarify,
having a value other than 1 in the Jbu matrix is okay?

I have not tried it, sorry :frowning:

No, there can be only 1 and 0 values, I improved the corresponding error message now.