Title: Set of constraints raises Error · Issue #702 · python-control/python-control · GitHub
Open Graph Title: Set of constraints raises Error · Issue #702 · python-control/python-control
X Title: Set of constraints raises Error · Issue #702 · python-control/python-control
Description: I am using the python optimal control library to optimise the trajectory of a 2D rocket. Please find attached a minimum reproducible sample code of the optimisation process of the problem. Whenever I am trying to set constraints for only...
Open Graph Description: I am using the python optimal control library to optimise the trajectory of a 2D rocket. Please find attached a minimum reproducible sample code of the optimisation process of the problem. Whenever...
X Description: I am using the python optimal control library to optimise the trajectory of a 2D rocket. Please find attached a minimum reproducible sample code of the optimisation process of the problem. Whenever...
Opengraph URL: https://github.com/python-control/python-control/issues/702
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Set of constraints raises Error","articleBody":"I am using the python optimal control library to optimise the trajectory of a 2D rocket. Please find attached a minimum reproducible sample code of the optimisation process of the problem. Whenever I am trying to set constraints for only some of the states, I get the error described after the minimum reproducible example. Is there an appropriate way to define multiple separate constraints passed in the \"constraints= [..., ..., ...]\" argument of the solve.ocp() function? Also, instead of using range -np.inf to np.inf for state parameters that I do not want to bound, is there a value that makes the code ignore the specific state parameter constraints?\r\n\r\n```\r\nT_max_Single = 7607000/9\r\n\r\ng = 9.81 \r\nm = 114239.00\r\nk = 18.74\r\nI = 16071705.59\r\n\r\nimport numpy as np\r\nimport math\r\nimport control as ct\r\nimport control.optimal as opt\r\nimport matplotlib.pyplot as plt\r\nimport logging\r\nimport time\r\nimport os\r\nplt.style.use(\"default\")\r\nfrom IPython.display import display\r\nfrom colorama import *\r\nimport sympy as s\r\nfrom scipy.integrate import odeint\r\n\r\n\r\n#Definition of the states\r\ndef rocket_update(t, x, u, params):\r\n \r\n xpos = x[0] \r\n U = x[1] \r\n z = x[2] \r\n W = x[3] \r\n θ = x[4] \r\n q = x[5] \r\n \r\n T = u[0]\r\n a = u[1]\r\n\r\n # Return the derivative of the state\r\n dydt = np.array([U,\r\n T*np.cos(θ-a)/m, \r\n W,\r\n T*np.sin(θ-a)/m-g,\r\n q,\r\n T*k*np.sin(a)/I])\r\n \r\n return(dydt)\r\n\r\ndef rocket_output(t, x, u, params):\r\n return x # return (full state)\r\n\r\n\r\n\r\nTf = 8\r\n\r\n\r\n\r\n# Define the rocket movement dynamics as an input/output system\r\nrocket = ct.NonlinearIOSystem(\r\n rocket_update, rocket_output, states=6, name='rocket',\r\n inputs=(\"T\", \"α\"), outputs=(\"x\", \"U\", \"z\", \"W\", \"θ\", \"q\")) \r\n\r\n# Define the time horizon (and spacing) for the optimization\r\nhorizon = np.linspace(0, Tf, Tf, endpoint=True) #############IMPORTANT\r\n\r\n# Provide an intial guess (will be extended to entire horizon)\r\nbend_left = [T_max_Single, 0.01] # slight left veer #############IMPORTANT\r\n\r\n\r\n# Optimal Control Problem\r\nInitial_x = 0 #m\r\nFinal_x = 5 #m\r\n\r\nInitial_z = 0 #m\r\nFinal_z = 200 #m\r\n\r\nInitial_θ = np.pi/2 #m\r\nFinal_θ = np.pi/3 #m\r\n\r\nFinal_Thrust = T_max_Single\r\n\r\nx0 = [Initial_x, 0, Initial_z, 0, Initial_θ, 0]; u0 = [bend_left[0], bend_left[1]]\r\nxf = [Final_x, 0, Final_z, 0, Final_θ, 0]; uf = [Final_Thrust, 0]\r\n\r\n#T_max_Single\r\nMin_T = 1 * T_max_Single\r\nMax_T = 9 * T_max_Single\r\na_min = -20* np.pi/180\r\na_max = 20* np.pi/180\r\n\r\n# Approach 3: terminal constraints\r\n#\r\n# We can also remove the cost function on the state and replace it\r\n# with a terminal *constraint* on the state. If a solution is found,\r\n# it guarantees we get to exactly the final state.\r\n#\r\nprint(\"Initialisation of optimisation\") \r\n# print(\"Checkpoint_1\")\r\n\r\n# Input cost and terminal constraints\r\nR = np.diag([0, 0]) # minimize applied inputs\r\ncost3 = opt.quadratic_cost(rocket, np.zeros((6,6)), R, u0=uf)\r\n\r\ncon1 = [ opt.input_range_constraint(rocket, [Min_T, a_min], [Max_T, a_max]) ]\r\n\r\nterminal = [ opt.state_range_constraint(rocket, [Final_x, -np.inf, Final_z, -np.inf, -np.inf, -np.inf],\r\n [Final_x, np.inf, Final_z, np.inf, np.inf, np.inf]) ]\r\n\r\n\r\n# Reset logging to its default values\r\nlogging.basicConfig(\r\n level=logging.DEBUG, filename=\"./steering-terminal_constraint.log\",\r\n filemode='w', force=True)\r\n\r\n# Compute the optimal control\r\nstart_time = time.process_time()\r\nresult3 = opt.solve_ocp(\r\n rocket, horizon, x0, cost3, con1, \r\n terminal_constraints=terminal, initial_guess=bend_left, log=False, method=\"trust-constr\",\r\n options={'eps': 0.01})\r\n\r\nprint(\"* Total time = %5g seconds\\n\" % (time.process_time() - start_time))\r\n```\r\n\r\nError:\r\n\r\n```\r\n/opt/anaconda3/lib/python3.8/site-packages/scipy/optimize/_constraints.py:386: OptimizeWarning: At least one constraint is unbounded above and below. Such constraints are ignored.\r\n warn(\"At least one constraint is unbounded above and below. Such \"\r\n/opt/anaconda3/lib/python3.8/site-packages/scipy/optimize/_constraints.py:432: OptimizeWarning: Equality and inequality constraints are specified in the same element of the constraint list. For efficient use with this method, equality and inequality constraints should be specified in separate elements of the constraint list. \r\n warn(\"Equality and inequality constraints are specified in the same \"\r\n```","author":{"url":"https://github.com/ThomasGiavasopoulos","@type":"Person","name":"ThomasGiavasopoulos"},"datePublished":"2022-02-18T14:35:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/702/python-control/issues/702"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4585584c-9392-8d6e-e515-40ee9819c621 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E4FA:90CEE:1276F3E:1A7E789:697A3792 |
| html-safe-nonce | 30a36da4b18b62f00021e6238d37a01db11ab9e5172eba02229144f825fb5a8d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNEZBOjkwQ0VFOjEyNzZGM0U6MUE3RTc4OTo2OTdBMzc5MiIsInZpc2l0b3JfaWQiOiI4MjE5NDM4OTkzODUwOTA2NTE0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7e7be2ca4e28940875557340098734096b0cafe1825f95b3c3564f0ef0d77507 |
| hovercard-subject-tag | issue:1143173764 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-control/python-control/702/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7b9d654270f6bb914053b12aa60ecdd3d52e95000996cb2193348fce2fb51f56/python-control/python-control/issues/702 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7b9d654270f6bb914053b12aa60ecdd3d52e95000996cb2193348fce2fb51f56/python-control/python-control/issues/702 |
| og:image:alt | I am using the python optimal control library to optimise the trajectory of a 2D rocket. Please find attached a minimum reproducible sample code of the optimisation process of the problem. Whenever... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ThomasGiavasopoulos |
| hostname | github.com |
| expected-hostname | github.com |
| None | af6de804ceb83ad30bb9b348cdeaccaa30cdcb566762d5e74e21e2bad88885d0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-control/python-control git https://github.com/python-control/python-control.git |
| octolytics-dimension-user_id | 2285872 |
| octolytics-dimension-user_login | python-control |
| octolytics-dimension-repository_id | 22791752 |
| octolytics-dimension-repository_nwo | python-control/python-control |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 22791752 |
| octolytics-dimension-repository_network_root_nwo | python-control/python-control |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2d980605f0959039ddebcbcf522b072508302977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width