OpenMDAO Dymos: How to run kinematic optimization with initial and final state values that depend on design variables?

174 views Asked by At

Free Body Diagram

The image above shows the kinematic optimization problem statement that I'm trying to implement. The initial and final state values are directly proportional to design variables.

And the following are the boundary constraints for the final joint positions:

0 <= xB <= 0.6*lo + d

0 <= yB <= 0.9*b

1

There are 1 answers

0
Rob Falck On

I believe this solves the problem without the need for integration, only relying on the geometric constraints of the system. Setting the constants d, b, and L0 to the appropriate values should let you find your particular solution.

import openmdao.api as om
import numpy as np

d = 1.0
b = 1.0
L0 = 1.0

p = om.Problem()

exec_1 = om.ExecComp('beta = arccos(0.5 * b - d_ab * sin(theta) / d_bc)')

exec_2 = om.ExecComp(['x_c = d_ab * cos(theta) + d_bc * cos(beta)',
                      'x_b = d_ab * cos(theta)',
                      'y_b = d_ab * sin(theta)'])

p.model.add_subsystem('exec_1', exec_1,
                      promotes_inputs=['b', 'd_ab', 'theta', 'd_bc'],
                      promotes_outputs=['beta'])

p.model.add_subsystem('exec_2', exec_2,
                      promotes_inputs=['d_ab', 'theta', 'd_bc', 'beta'],
                      promotes_outputs=['x_c', 'x_b', 'y_b'])

p.model.add_design_var('theta', lower=np.radians(45), upper=np.radians(360))
p.model.add_design_var('d_ab', lower=0.05, upper=0.9)
p.model.add_design_var('d_bc', lower=0.05)

p.model.add_constraint('x_b', lower=0.0, upper=d + 0.6 * L0)
p.model.add_constraint('y_b', lower=0.0, upper=0.9 * b)
p.model.add_constraint('x_c', equals=d + 0.6 * L0)
p.model.add_objective('beta', scaler=-1)

p.driver = om.pyOptSparseDriver(optimizer='IPOPT')
p.driver.opt_settings['print_level'] = 5

# p.driver = om.ScipyOptimizeDriver()

p.setup()

p.set_val('theta', np.pi/4)

p.run_driver()

Which gives

Optimization Problem -- Optimization using pyOpt_sparse
================================================================================
    Objective Function: _objfunc

    Solution: 
--------------------------------------------------------------------------------
    Total Time:                    0.0620
       User Objective Time :       0.0077
       User Sensitivity Time :     0.0216
       Interface Time :            0.0105
       Opt Solver Time:            0.0221
    Calls to Objective Function :       9
    Calls to Sens Function :            9


   Objectives
      Index  Name                   Value
          0  exec_1.beta    -1.268661E+00

   Variables (c - continuous, i - integer, d - discrete)
      Index  Name      Type      Lower Bound            Value      Upper Bound     Status
          0  theta_0      c     7.853982E-01     9.733898E-01     6.283185E+00           
          1  d_ab_0       c     5.000000E-02     9.000000E-01     9.000000E-01          u
          2  d_bc_0       c     5.000000E-02     3.675735E+00     1.000000E+30           

   Constraints (i - inequality, e - equality)
      Index  Name       Type          Lower           Value           Upper    Status  Lagrange Multiplier (N/A)
          0  exec_2.x_c    e   1.600000E+00    1.600000E+00    1.600000E+00              9.00000E+100
          1  exec_2.x_b    i   0.000000E+00    5.062501E-01    1.600000E+00              9.00000E+100
          2  exec_2.y_b    i   0.000000E+00    7.441175E-01    9.000000E-01              9.00000E+100