Sleipnir C++ API
|
See the C++ installation instructions.
A system with position and velocity states and an acceleration input is an example of a double integrator. We want to go from 0 m at rest to 10 m at rest in the minimum time while obeying the velocity limit (-1, 1) and the acceleration limit (-1, 1).
The model for our double integrator is ẍ = u where x is the vector [position; velocity] and u is the acceleration. The velocity constraints are -1 ≤ x(1) ≤ 1 and the acceleration constraints are -1 ≤ u ≤ 1.
First, we need to make a problem instance.
First, we need to make decision variables for our state and input.
By convention, we use capital letters for the variables to designate matrices.
Now, we need to apply dynamics constraints between timesteps.
Next, we'll apply the state and input constraints.
Next, we'll create a cost function for minimizing position error.
The cost function passed to Minimize() should produce a scalar output.
Now we can solve the problem.
The solver will find the decision variable values that minimize the cost function while satisfying the constraints.
You can obtain the solution by querying the values of the variables like so.
In retrospect, the solution here seems obvious: if you want to reach the desired position in the minimum time, you just apply positive max input to accelerate to the max speed, coast for a while, then apply negative max input to decelerate to a stop at the desired position. Optimization problems can get more complex than this though. In fact, we can use this same framework to design optimal trajectories for a drivetrain while satisfying dynamics constraints, avoiding obstacles, and driving through points of interest.