Esempio n. 1
0
def main():
    args = get_onoff_args('backend ipopt')
    sys = QuadRotor()
    N = 40
    dimx, dimu = sys.nx, sys.nu
    cost = QuadCost(N, sys.nx, sys.nu)
    t0 = 0.0
    tf = 5.0
    prob = TrajOptProblem(sys, N, t0, tf, gradmode=True)
    prob.xbd = [-1e20 * np.ones(sys.nx), 1e20 * np.ones(sys.nx)]
    prob.ubd = [0 * np.ones(sys.nu), 4 * np.ones(sys.nu)]
    prob.x0bd = [np.zeros(sys.nx), np.zeros(sys.nx)]
    prob.xfbd = [np.zeros(sys.nx), np.zeros(sys.nx)]
    prob.xfbd[0][:3] = 5
    prob.xfbd[1][:3] = 5
    if False:
        prob.add_obj(cost)
    else:
        lqr = LqrObj(R=np.ones(4))
        prob.add_lqr_obj(lqr)
    prob.pre_process()
    # construct a solver for the problem
    cfg = OptConfig(args.backend, print_level=5)
    slv = OptSolver(prob, cfg)
    guessx = np.zeros(prob.nx)
    straightx = np.reshape(guessx[:N * dimx], (N, dimx))
    for i in range(3):
        straightx[:, i] = np.linspace(0, prob.xfbd[0][i], N)
    guessx[N * dimx:-1] = np.random.random(N * dimu)
    rst = slv.solve_guess(guessx)
    print(rst.flag)
    if rst.flag == 1:
        # parse the solution
        sol = prob.parse_sol(rst.sol.copy())
        show_sol(sol)
Esempio n. 2
0
def main():
    args = get_onoff_args('oned', 'pen', 'lqr', 'linear', 'orderone',
                          'backend ipopt')
    if args.oned:
        testOneD(args)
    if args.pen:
        testPen(args)
    if args.linear:
        testLinear(args)
    if args.orderone:
        testOrderOne(args)
Esempio n. 3
0
def main():
    args = get_onoff_args('cartpole', 'lqr', 'backend ipopt')
    if args.cartpole:
        gradmode(args)
Esempio n. 4
0
def main():
    args = get_onoff_args('one', 'two', 'oneleg')
    if args.one:
        testOne()
    if args.oneleg:
        testOneLeg()
Esempio n. 5
0
def main():
    args = get_onoff_args('grad', 'pen', 'lqr', 'backend ipopt')
    if args.grad:
        gradmode(args)
    if args.pen:
        penMode(args)
Esempio n. 6
0
def main():
    args = get_onoff_args('linear', 'ad', 'pen', 'fd')
    if args.linear:
        test_linear(args.ad)
    if args.pen:
        test_pendulum(args.ad, args.fd)