コード例 #1
0
class state_finder:
    def __init__(self):
        self.my_heli = Helicopter()
        self.my_contr = Controller()
        self.ENV_ID = "CustomEnv-v0"
        # ENV_ID = "CartPole-v0"
        self.env = gym.make(self.ENV_ID)
        self.env.current_states = self.env.reset()

    def get_action(self,
                   current_states,
                   sl_action=[1, 10, 10, 5, 5, 1, 1, 2, 2, 1, 1, 1, 1]):
        action = self.my_contr.Controller_model(current_states,
                                                self.env.dt * self.env.counter,
                                                sl_action)
        return action
コード例 #2
0
ファイル: try_PID.py プロジェクト: MKamyab1991/ppo_RL
# pid_ped = PID(-1, -1, -0.5, setpoint=0)
for i in range((len(k_bin))):
    for j in range((len(i_bin))):
        kk = k_bin[i]
        ii = i_bin[j]
        # pid_lon = PID(kk, ii, 0, setpoint=-1.08e-01)
        pid_lon = PID(0.2, 0.2, 0.01, setpoint=0)  # controls q, theta
        print(kk, ii)
        my_env.current_states = my_env.reset()
        done = False
        while not done:
            # Yd, Ydotd, Ydotdotd, Y, Ydot = my_contr.Yposition(my_env.dt * my_env.counter, my_env.current_states)
            # ctrl = [float(deltacol), float(deltalat), float(deltalon), float(deltaped)]

            sl_ctrl = my_contr.Controller_model(my_env.current_states,
                                                my_env.dt * my_env.counter,
                                                action=sl_action)
            # print('slaction      ', ['%.2e' % elem for elem in sl_ctrl])
            # sl_ctrl[0] = float(pid_col(Y[2]))
            # sl_ctrl[1] = float(pid_lat(Y[1]))
            # sl_ctrl[2] = float(pid_lon(my_env.current_states[7]))
            # sl_ctrl[2] = float(pid_lon(Y[0]))
            # sl_ctrl[3] = float(pid_ped(Y[3]))
            # print('upaction      ', ['%.2e' % elem for elem in sl_ctrl])
            states, b, done, _ = my_env.step(sl_ctrl)
            # constant_dict = {
            #     "u": 1.,
            #     "v": 1.,
            #     "w": 1.,
            #     "p": 1.,
            #     "q": 0.,