### NMPC with CasADi and Python – Part 3: State-space equations of a 2-DOF robot with SymPy or MATLAB

CasADi is a powerful open-source tool for nonlinear optimization. It can be used with MATLAB/Octave, Python, or C++, with the bulk of the available resources referencing the former two options. This post series is intended to show a possible method of developing a simulation for an example system controlled by Nonlinear Model Predictive Control (NMPC) using CasADi and Python.

In this post, we will look at determining the system equations of a robot with two degrees of freedom in stace-space form. These state-space equations can be used for simulation and for developing a nonlinear model predictive controller. For some transformation tasks, Python with SymPy will be utilized and an alternative using the MATLAB Symbolic Math Toolbox will be shown.

During the following, we are considering a robot with two links, two masses at the end of the links, and motors applying torque as control input at the joints. A diagram of the robot is shown below.

### NMPC with CasADi and Python – Part 2: Simulation of an uncontrolled system

CasADi is a powerful open-source tool for nonlinear optimization. It can be used with MATLAB/Octave, Python, or C++, with the bulk of the available resources referencing the former two options. This post series is intended to show a possible method of developing a simulation for an example system controlled by Nonlinear Model Predictive Control (NMPC) using CasADi and Python.

In this post, we will try to simulate an uncontrolled system with a forward Euler and a 4th order Runge-Kutta integration method. The latter can be the base for future closed-loop simulations.

### NMPC with CasADi and Python – Part 1: ODE and steady state

CasADi is a powerful open-source tool for nonlinear optimization. It can be used with MATLAB/Octave, Python, or C++, with the bulk of the available resources referencing the former two options. This post series is intended to show a possible method of developing a simulation for an example system controlled by Nonlinear Model Predictive Control (NMPC) using CasADi and Python.

In this post, a file describing the system equations and a script to determine a steady-state setpoint will be developed. This older post contains similar code for CasADi inside MATLAB.

### Linearize nonlinear state space equation in MATLAB at steady state setpoint

This post shows one way to linearize a nonlinear state equation $\dot{x} = f(x,u)$ at a steady state setpoint $(x_0, u_0)$ in MATLAB. It is assumed that a function ode.m exists in which the state equation is implemented:

function dx = ode(t, x, u)
% example ODE
dx1 = tan(x(4)) * x(2) + 2*u(2) - 1;
dx2 = x(1) - sin(x(2));
dx3 = 13 * x(4) + u(1) + 1;
dx4 = 2*x(1);

dx = [dx1; dx2; dx3; dx4];
end


### Calculate Levenshtein distance in MATLAB (words or characters) with Wagner–Fischer algorithm

This is a MATLAB implementation of the Wagner–Fischer algorithm.

### Convert dSPACE ControlDesk measurements to MATLAB/Simulink timeseries (updated)

• With this updated MATLAB script, multiple dSPACE ControlDesk measurements can be imported with a single execution
• The result is saved as a tscollection (collection of timeseries) and all signals are saved with their corresponding name
• Access imported data with Simulink ‘From Workspace’ block and, e.g., dsp_tscs{1}.my_signal

### Fix for Latex4CorelDraw with CorelDraw 2017

I was not able to make the official build of Latex4CorelDraw work with CorelDraw 2017 (and Windows 10). The ‘Latex’ Docker window was always empty. The solution was to recompile it with Visual Studio 2017 Community.

### Convert dSPACE ControlDesk measurement to MATLAB timeseries that can be used in Simulink

• dSPACE ControlDesk can export measurements to mdf4 files or mat files
• mat file exports can be converted to timeseries with this MATLAB script
• The timeseries can then be imported into Simulink with the ‘From Workspace’ blog
• Multiple signals can be imported at once

Example output:

>> import_dspace_mat_to_simulink_ts
--Imported dSPACE mat file
C:\Users\Nicolai\Nextcloud\foo.mat
into workspace variable dsp_ts
--Time: 0.000000 s to 42.399572 s, 423980 steps
--2 variables are in dsp_ts:
'In1' 'In1_1'

### Robust sync between Android phone and Linux computer

I already tried quite a few methods to reliably sync data (e.g. backups) between my Android phone and a Linux computer. Most were not good, some were horrible (MTP…). I just tried one that has proven to be the best, by far: installing an SSH server on the phone and then syncing with rsync. I

### Django DetailView with pagination for related objects

This is an example of a DetailView of a User that can have a paginated list of Purchases: from django.views.generic.detail import DetailView from django.core import paginator @method_decorator(staff_member_required(login_url=’user_login’), name=’dispatch’) class UserDetailView(DetailView): model = User template_name = “user_detail.html” purchases_paginate_by = 5 def get_context_data(self, **kwargs): context = super(UserDetailView, self).get_context_data(**kwargs) purchases_page = self.request.GET.get(“purchases_page”) purchases = self.object.get_purchases().filter() purchases_paginator = paginator.Paginator(purchases,

1 2 3