# OCP Solver not being built correctly when infinity in bounds

Hi

I am currently trying to build an Optimal Control Problem (OCP) in Python using acados and am running into a problem with the solver generation.

The OCP is used to build an MPC algorithm for an inverted pendulum system.

The code itself is implemented as follows:

ocp = AcadosOcp()

# set model
model = pend_model()
ocp.model = model

Tf = 1.0
nx = model.x.size()[0]
nu = model.u.size()[0]
N = 20

# set dimensions
ocp.dims.N = N

# set cost
Q_mat = 2 * np.diag([1e3, 1e3, 1e-2, 1e-2])
R_mat = 2 * np.diag([1e-2])

ocp.cost.cost_type = 'EXTERNAL'
ocp.cost.cost_type_e = 'EXTERNAL'
ocp.model.cost_expr_ext_cost = model.x.T @ Q_mat @ model.x + model.u.T @ R_mat @ model.u
ocp.model.cost_expr_ext_cost_e = model.x.T @ Q_mat @ model.x

# Input constraints
umax = 23
ocp.constraints.lbu = np.array([-umax])
ocp.constraints.ubu = np.array([+umax])
ocp.constraints.idxbu = np.array([0])

# State Constraints
xmax = [inf, inf, 0.25, inf]
xmin = [-inf, -inf, -0.25, -inf]
ocp.constraints.lbx = np.array(xmin)
ocp.constraints.ubx = np.array(xmax)
ocp.constraints.idxbx = np.array([0, 1, 2, 3])

# Initial state constraint
ocp.constraints.x0 = np.array([np.pi, 0.0, 0.0, 0.0])

# set options
ocp.solver_options.qp_solver = 'PARTIAL_CONDENSING_HPIPM'
ocp.solver_options.hessian_approx = 'EXACT'
ocp.solver_options.integrator_type = 'IRK'
ocp.solver_options.print_level = 1
ocp.solver_options.nlp_solver_type = 'SQP'

# set prediction horizon
ocp.solver_options.tf = Tf

self.ocp = ocp
self.ocp_solver = AcadosOcpSolver(self.ocp, json_file='acados_ocp.json')

On further investigation, I noticed that the AcadosOCPSolver class did not generate a solver when I included my state constraints.

While trying to run the code this error message pops up

Error: Custom { kind: InvalidData, error: Error("invalid number", line: 46, column: 14) }
Traceback (most recent call last):
File "/home/s/pg22-pendulum/Real_Pendulum/OCP_Test.py", line 92, in <module>
main()
File "/home/s/pg22-pendulum/Real_Pendulum/OCP_Test.py", line 87, in main
solver = ctrl.build_ocp()
File "/home/s/pg22-pendulum/Real_Pendulum/OCP_Test.py", line 80, in build_ocp
self.ocp_solver = AcadosOcpSolver(self.ocp, json_file='acados_ocp.json')
File "/home/s/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py", line 937, in __init__
self.generate(acados_ocp, json_file=json_file, simulink_opts=simulink_opts, cmake_builder=cmake_builder)
File "/home/s/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py", line 856, in generate
ocp_render_templates(acados_ocp, json_file, cmake_builder=cmake_builder, simulink_opts=simulink_opts)
File "/home/s/acados_template/acados_template/acados_ocp_solver.py", line 743, in ocp_render_templates
render_template(tup[0], tup[1], output_dir, json_path)
File "/home/s/acados/interfaces/acados_template/acados_template/utils.py", line 241, in render_template
raise Exception(f'Rendering of {in_file} failed!\n\nAttempted to execute OS command:\n{os_cmd}\n\n')
Exception: Rendering of main.in.c failed!

I tried building the tera renderer natively using the latest git release and replaced the executable in the bin folder but this doesnâ€™t change the outcome
Any help would be greatly appreciated

Hi, have you tried to change the inf in your state constraints to a large number, e.g. 1e10? Refer to this post: Time varying constraints, reference etc with acados in matlab - #4 by FreyJo

Hello,

Yes, it works after I removed the inf. I think it is infinity by default and I donâ€™t have to specify the constraint unless itâ€™s thereâ€¦