Skip to content
Snippets Groups Projects
Commit 9f6c91ef authored by tuhe's avatar tuhe
Browse files

Solutions for week 4 and 5

parent 254abc81
No related branches found
No related tags found
No related merge requests found
Showing
with 32 additions and 0 deletions
f_euler = dmodel.f(x, u, k=0)
\ No newline at end of file
f_euler_derivative, _ = dmodel.f_jacobian(x, u)
\ No newline at end of file
next_x, cost, terminated, _, metadata = env.step([u])
\ No newline at end of file
x_dot = model.f([1, 2], [0], t=0)
\ No newline at end of file
x_dot_numpy = model.f([1, 2], [0], t=0)
\ No newline at end of file
e = self.target - x
# if self.e_prior == 0 and self.I == 0:
# self.e_prior = e
self.I = self.I + e * self.dt
u = self.Kp * e + self.Ki * self.I + self.Kd * (e - self.e_prior)/self.dt
self.e_prior = e
\ No newline at end of file
u = pid.pi(x_cur[0])
\ No newline at end of file
self.pid_angle = PID(dt=env.discrete_model.dt, Kp=1.0, Ki=0, Kd=0, target=0)
self.pid_velocity = PID(dt=env.discrete_model.dt, Kp=1.5, Ki=0, Kd=0, target=v_target)
\ No newline at end of file
xx = x[5] + x[3] if self.use_both_x5_x3 else x[5]
u = np.asarray([self.pid_angle.pi(xx), self.pid_velocity.pi(x[0])])
\ No newline at end of file
self.pid = PID(dt=dt, Kp=Kp, Ki=Ki, Kd=Kd, target=target)
\ No newline at end of file
u = self.pid.pi(x[0])
\ No newline at end of file
alt_adj = self.pid_alt.pi( -(np.abs(x[0])- x[1]) )
ang_adj = self.pid_ang.pi( -((.25 * np.pi) * (x[0] + x[2]) - x[4]) )
\ No newline at end of file
u = self.pid.pi(x[0])
u = np.clip(u, self.env.action_space.low, self.env.action_space.high)
\ No newline at end of file
agent = PIDPendulumAgent(env, dt=env.dt, Kp=12, Ki=0, Kd=2, target_angle=0)
\ No newline at end of file
agent = PIDPendulumAgent(env, dt=env.dt, Kp=12, Ki=2, Kd=2, target_angle=np.pi/6)
\ No newline at end of file
guess = {k: solutions[i - 1]['fun'][k] for k in ['t0', 'tF', 'x', 'u'] }
\ No newline at end of file
x_interp = xs[:, k] + tau * fs[:, k] + (tau ** 2 / (2 * hk)) * (fs[:, k + 1] - fs[:, k])
\ No newline at end of file
z, z0, z_lb, z_ub = z + xs[k], z0 + list(guess['x'](tk).flat), z_lb + x_low, z_ub + x_high
z, z0, z_lb, z_ub = z + us[k], z0 + list(guess['u'](tk).flat), z_lb + u_low, z_ub + u_high
\ No newline at end of file
z, z0, z_lb, z_ub = z+[t0], z0+[guess['t0']], z_lb+[model.t0_bound().low[0]], z_ub+[model.t0_bound().high[0]]
z, z0, z_lb, z_ub = z+[tF], z0+[guess['tF']], z_lb+[model.tF_bound().low[0]], z_ub+[model.tF_bound().high[0]]
\ No newline at end of file
fs.append(model.sym_f(x=xs[k], u=us[k], t=ts[k]))
cs.append(cost.sym_c(x=xs[k], u=us[k], t=ts[k]))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment