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 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
Installation is very easy. You first need to install Rust and clang. You can install OpEn using pip:
pip install opengen
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 - u, cs.fmax(0.0, u - u + 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() \ .with_optimizer_name("rosenbrock") 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") \ .with_ros(ros_config) solver_config = og.config.SolverConfiguration() \ # solver config .with_tolerance(1e-5) \ .with_delta_tolerance(1e-4) \ .with_penalty_weight_update_factor(5) builder = og.builder.OpEnOptimizerBuilder(problem, meta, build_config, solver_config) builder.build() # 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:
- embedded nonlinear model predictive control for obstacle avoidance on a ground vehicle: that was the first application of the algorithm (there have been lots of developments sice)
fast nonlinear model predictive control on a micro aerial vehicle: runs NMPC at 20Hz, but can go even faster if necessary
- tutorial: an auto-generated ROS package for Husky: this is a step-by-step guide to building your own model predictive controller to navigate a Husky unmanned ground vehicle
We hope you find this useful!
If so, here’s a few things you can do for OpEn:
- Give us a on github
- with us on Discord!
- Submit a feature request or report ( read first)
- Submit a pull request on github ( read first)