ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

OpEn: Rust code generation of ROS packages for real-time nonconvex optimization

Dear fellow ROS developers,

We are glad to present OpEn (github): a code generation framework that allows the developer to formulate a parametric nonconvex optimization problem in Python (e.g., a nonlinear model predictive control or moving horizon estimation problem) and build a ROS package.

OpEn code generation framework

OpEn generates Rust code: Rust is a modern, fast, memory-safe systems programming language. It is ideal for embedded applications.

This is how it works:

Find more information here

Easy Installation

Installation is very easy. You first need to install Rust and clang. You can install OpEn using pip:

pip install opengen

It’s fast

It can be 1-2 orders of magnitude faster compared to sequential quadratic programming and interior point methods (reference 1 and 2)


Code example in Python

This is a short example to demonstrate that we can generate a

import opengen as og          # <---- OpEn
import casadi.casadi as cs    # symbolic math & differentiation

u = cs.SX.sym("u", 5)                # decision variable
p = cs.SX.sym("p", 2)                # parameter
phi = og.functions.rosenbrock(u, p)  # Rosenbrock function
c = cs.vertcat(1.5 * u[0] - u[1],
               cs.fmax(0.0, u[2] - u[3] + 0.1))
bounds = og.constraints.Ball2(None, 1.5)
problem = og.builder.Problem(u, p, phi) \   # minimize phi(u; p) wrt u
    .with_penalty_constraints(c)        \   # subject to: c(u; p) = 0
    .with_constraints(bounds)               #             u in bounds
meta = og.config.OptimizerMeta()                \
ros_config = og.config.RosConfiguration()       \   # ROS configuration
    .with_package_name("parametric_optimizer")  \   # package name
    .with_node_name("open_node")                \   # node name
    .with_rate(35)                                  # rate (in Hz)
build_config = og.config.BuildConfiguration()   \
    .with_build_directory("my_optimizers")      \
solver_config = og.config.SolverConfiguration()    \  # solver config
    .with_tolerance(1e-5)                          \
    .with_delta_tolerance(1e-4)                    \
builder = og.builder.OpEnOptimizerBuilder(problem, meta,
                                          build_config, solver_config)   # Build optimizer & ROS package

Note the line .with_ros(ros_config) - this will generate a ROS package (it contains a README file with instructions on how to use it and a launch file).


OpEn has been used in a number of real-life applications of robotics such as:

We hope you find this useful!

If so, here’s a few things you can do for OpEn:

~ Pantelis Sopasakis


Wow, this looks great!
It’s great to see more and more packages moving to Rust

Thanks for sharing Pantelis!

1 Like