PSOPT / psopt

PSOPT Optimal Control Software
GNU Lesser General Public License v2.1
193 stars 75 forks source link

Workspace for rk4_propagate #53

Closed TimKrause2 closed 3 months ago

TimKrause2 commented 3 months ago

I want to pass user data to the callbacks, especially 'dae'. I found in the documentation that you could set user_data in the problem somewhere in the setup of the problem and then access the problem and the user_data through the workspace. However, I'm calling rk4_propagate outside of a callback and I need a workspace to pass to it. In the example code the workspace is set to NULL. I tried instantiating a workspace and passing that but the program crashed when the workspace was destroyed. What is the best way to pass user data to the rk4_propagate function?

vmbecerra commented 3 months ago

Hello Timothy,

Unfortunately, although I intended to remove the rk4_propagate in the last release, I forgot to do so, and that function is no longer working. None of the '*_propagate' function work at present and I do not recommend that you try to use them. I will remove them in the next release.

I suggest an alternative approach to solve (or 'propagate') the dynamic equations for a user-supplied input. This can be done by solving an optimal control problem whose objective function is to minimise the integral of the square of the difference between the control and the user-supplied control.

Assuming that no state-dependent constraints become active with the user-supplied input, and that the user-supplied input satisfies the input constraints, the solution to this optimal control problem will be the states that result from providing the user-supplied input to the system dynamics, and the optimal controls will be essentially identical to the user-supplied controls.

You can download from the following link a modified version of the "user.cxx" example code, where the above trick is done.

https://web.tresorit.com/l/DzxZO#6OamhHi_ifIJISEwT1e-QQ

I have used as 'user-supplied' input the actual optimal control, so that the resulting states should be equal to the optimal states (and you will see that they are).

What you need to do is save the attached file in the src/examples/user folder (you may want to make a backup of the original user.cxx function).

Then, from the terminal, you have to cd to the 'build/examples/user' folder and send the following command:

make user

This will update the executable, which you can run to generate the results.

I hope this is useful.

Best wishes,

Victor Becerra

TimKrause2 commented 3 months ago

Thanks for the technique.

TimKrause2 commented 3 months ago

twoburn.cxx will have to be re-written to reflect this new method.

vmbecerra commented 3 months ago

Yes, I will look into it - thanks for realising the need to update twoburn.cxx