Skip to content

ElMapacheDelOeste/CartPoleMTKTrajectoryOptim.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CartPoleMTKTrajectoryOptim.jl

Example of 1D and 2D cart-pole trajectory optimization problem using ModelingToolkit.jl for the physics.

Installation

This package requires Multibody.jl and therefore JuliaSimCompiler.jl. The installation is as described here : https://help.juliahub.com/juliasim/dev/gettingstarted/juliahubregistry/.

Usage

  1. cart_pole_1D_trajectory_optimization.jl : implementation of the problem presented here by Matthew Kelly https://epubs.siam.org/doi/epdf/10.1137/16M1062569
  2. cart_pole_2D_trajectory_optimization.jl : implementation of the same system but adding a revolute around the x-axis and a rail in y-axis with an actuator to have an example dealing with 2 inputs.

Difficulties faced

  1. The usage of InfiniteOpt.jl has been tried but it didn't seem to comply with this problem like discussed here : infiniteopt/InfiniteOpt.jl#363. It has been decided to write manually the transcription of the collocation method.

  2. To improve the performance, it is import to use the sparsity of the jacobian of the constraints as the problem builds up quickly with the number of segments used for the collocation method.

    a. It has been tried to use AutoSparseForwardDiff() as a backend method but this didn't work due to the dynamics function (x_dot = f(x,u,p,t)) being generated by JuliaSimCompiler.

    b. It has been decided to use the AutoForwardDiff() backend and to manually build the sparsity pattern of the jacobian of the constraints. This is done in the function get_cons_jac_prototype. This function is then passed to the OptimizationProblem constructor with the argument "cons_jac_prototype". This works fine for the 1D problem but doesn't with the 2D problem. It seems that the sparsity pattern provided with "cons_jac_prototype" is not forced to be used to define the jacobian whereas it it used to define the number of non-zero elements in the jacobian. Some zeros are added as values into the jacobian which leads to a different number of non zero elements in the jacobian than the one provided in the sparsity pattern. ERROR: AssertionError: length(j) == length(nnz) this error is thrown in nlp.jl at l291.

About

Example of 1D and 2D cart-pole trajectory optimization problem using ModelingToolkit.jl for the physics.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages