X[:, 0] = np.mat(x0).T
U = np.mat(np.zeros((arm.NU, T - 1)))

for t in range(T - 1):
    U[:, t] = du
# U[:,T/2:] = -2 * U[:,T/2:]
# U = np.mat(np.random.random_sample((arm.NU, T-1))/5)
# U[:,10:] = -2 * U[:,10:]

for t in xrange(1, T):
    X[:, t] = arm.dynamics(X[:, t - 1], U[:, t - 1])
    mus[:, t], Sigmas[:, :, t] = ekf_update(
        arm.dynamics, lambda x: arm.observe(s, x=x), Q, R, mus[:, t - 1], Sigmas[:, :, t - 1], U[:, t - 1], None
    )  # NOTE No obs

arm.draw_trajectory(X, mus, Sigmas)

Bel_bar = np.mat(np.zeros((arm.NB, T)))
for t in xrange(T):
    Bel_bar[:, t] = np.vstack((X[:, t], cov2vec(Sigmas[:, :, t])))

rho_bel = 0.2
rho_u = 0.3
N_iter = 1
goal_bel = np.copy(Bel_bar[:, -1])
goal_bel[arm.NX :] = 0

opt_bels, opt_ctrls, opt_vals = scp_solver_beliefs(
    s, Bel_bar.copy(), U, Q, R, rho_bel, rho_u, goal_bel, N_iter, arm.NX, method="shooting"
)
Example #2
0
U = np.mat(np.zeros((arm.NU, T-1)))

for t in range(T-1):
	U[:,t] = du
#U[:,T/2:] = -2 * U[:,T/2:]
#U = np.mat(np.random.random_sample((arm.NU, T-1))/5) 
#U[:,10:] = -2 * U[:,10:]

for t in xrange(1,T):
    X[:,t] = arm.dynamics(X[:,t-1], U[:, t-1])
    mus[:,t], Sigmas[:,:,t] = ekf_update(arm.dynamics,
                                         lambda x: arm.observe(s, x=x),
                                         Q, R, mus[:,t-1], Sigmas[:,:,t-1],
                                         U[:,t-1], None) #NOTE No obs

arm.draw_trajectory(X, mus, Sigmas)

drawRobot = X
getch = _Getch._Getch()
t = 0 
while True:
	c = getch()
	print c
	if c == 'x':
		break;
	elif ord(c) == 3 or ord(c) == 4:
		exit(0)
	elif c == 'n':
		print 'drawRobot = X'
		drawRobot = X
	elif c == 'm':
Example #3
0
for t in range(T - 1):
    U[:, t] = du
#U[:,T/2:] = -2 * U[:,T/2:]
#U = np.mat(np.random.random_sample((arm.NU, T-1))/5)
#U[:,10:] = -2 * U[:,10:]

for t in xrange(1, T):
    X[:, t] = arm.dynamics(X[:, t - 1], U[:, t - 1])
    mus[:,
        t], Sigmas[:, :,
                   t] = ekf_update(arm.dynamics, lambda x: arm.observe(s, x=x),
                                   Q, R, mus[:, t - 1], Sigmas[:, :, t - 1],
                                   U[:, t - 1], None)  #NOTE No obs

arm.draw_trajectory(X, mus, Sigmas)

drawRobot = X
getch = _Getch._Getch()
t = 0
while True:
    c = getch()
    print c
    if c == 'x':
        break
    elif ord(c) == 3 or ord(c) == 4:
        exit(0)
    elif c == 'n':
        print 'drawRobot = X'
        drawRobot = X
    elif c == 'm':
du = numpy.array([0.0] * arm.NU)
du = numpy.array([0.0, 0.1, -0.02, -0.05, 0.04, 0.02, 0.1])
du = numpy.mat(du)
#U_bar = np.mat(np.random.random_sample((car.NU, T-1)))/5

T = 20
X = numpy.mat(numpy.zeros((arm.NX, T)))
U = numpy.mat(numpy.zeros((arm.NU, T - 1)))
U = numpy.mat(numpy.random.random_sample((arm.NU, T - 1)) / 10)
U[:, 10:] = -2 * U[:, 10:]

for t in range(T - 1):
    #U[:,t] = du.T
    X[:, t + 1] = arm.dynamics(X[:, t], U[:, t])

arm.draw_trajectory(X)

rho_x = 0.1
rho_u = 0.1
N_iter = 5
print X
X_copy = X.copy()
U_copy = U.copy()

cost_t_fns = []
for t in range(T - 1):
    arm_pos = arm.traj_pos(X[:, t])
    cost_t_fns.append(lambda x, u, pos=arm_pos.copy(): cost_t(x, u, pos))

fcost = lambda x, pos=X[:, T - 1].copy(), bot=arm: final_cost(x, pos, bot)
Example #5
0
for t in range(T - 1):
    U[:, t] = du
#U[:,T/2:] = -2 * U[:,T/2:]
#U = np.mat(np.random.random_sample((arm.NU, T-1))/5)
#U[:,10:] = -2 * U[:,10:]

for t in xrange(1, T):
    X[:, t] = arm.dynamics(X[:, t - 1], U[:, t - 1])
    mus[:,
        t], Sigmas[:, :,
                   t] = ekf_update(arm.dynamics, lambda x: arm.observe(s, x=x),
                                   Q, R, mus[:, t - 1], Sigmas[:, :, t - 1],
                                   U[:, t - 1], None)  #NOTE No obs

arm.draw_trajectory(X, mus, Sigmas)

Bel_bar = np.mat(np.zeros((arm.NB, T)))
for t in xrange(T):
    Bel_bar[:, t] = np.vstack((X[:, t], cov2vec(Sigmas[:, :, t])))

rho_bel = 0.2
rho_u = 0.3
N_iter = 1
goal_bel = np.copy(Bel_bar[:, -1])
goal_bel[arm.NX:] = 0

opt_bels, opt_ctrls, opt_vals = scp_solver_beliefs(s, Bel_bar.copy(), U,\
               Q, R, rho_bel, rho_u, goal_bel, N_iter, arm.NX, method='shooting')

opt_mus = np.mat(np.zeros((arm.NX, T)))
Example #6
0
du = numpy.array([0.0, 0.1, -0.02, -0.05, 0.04, 0.02, 0.1])
du = numpy.mat(du)
#U_bar = np.mat(np.random.random_sample((car.NU, T-1)))/5


T = 20
X = numpy.mat(numpy.zeros((arm.NX, T)))
U = numpy.mat(numpy.zeros((arm.NU, T-1)))
U = numpy.mat(numpy.random.random_sample((arm.NU, T-1))/5) 
U[:,10:] = -2 * U[:,10:]

for t in range(T-1):
	#U[:,t] = du.T
	X[:,t+1] = arm.dynamics(X[:,t], U[:,t])

arm.draw_trajectory(X)

rho_x = 0.1
rho_u = 1.0
N_iter = 4
print X
X_copy = X.copy()
U_copy = U.copy()
opt_states, opt_ctrls, opt_vals = scp_solver_states(arm, X_copy, U_copy, rho_x, rho_u,\
                                             N_iter, method='shooting')

arm.draw_trajectory(opt_states, color=numpy.array((0.0,1.0,0.0)))

drawRobot = opt_states
getch = _Getch._Getch()
t = 0