Exemplo n.º 1
0
    def __init__(self, data_folder, config_file, play):
        self.render_filename = None
        self.mass = None
        self.inertia_tensor = None
        self.rotors = []
        self.wing = None

        # initialize constant value
        self.gravity = np.array([0, 0, 9.8])
        self.dt_mean = 0.01
        self.dt_std = 0.005
        self.total_iter = 2000

        # parse xml config file
        self.parse_config_file(data_folder + config_file)

        # construct rendering environment
        from mujoco_rendering_env import mujoco_env
        self.render_env = mujoco_env.MujocoEnv(model_path=data_folder +
                                               self.render_filename)
        self.render_intervel = int(1.0 / 50.0 / self.dt_mean)

        # self.render_env._get_viewer()

        # integral term
        self.I_dt = self.dt_mean
        self.I_error = None

        # mass property
        self.real_mass = self.mass
        self.real_inertia_tensor = self.inertia_tensor.copy()

        # train or play
        self.play = play

        # construct action space

        # construct observation space
        ob = self.get_observation_vector()
        ob_low = np.ones(len(ob)) * (-np.finfo(np.float32).max)
        ob_high = np.ones(len(ob)) * (np.finfo(np.float32).max)
        self.observation_space = spaces.Box(ob_low, ob_high, dtype=np.float32)
Exemplo n.º 2
0
    def __init__(self, data_folder, config_file, play):
        self.render_filename = None
        self.mass = None
        self.inertia_tensor = None
        self.rotors = []
        self.wing = None

        # initialize constant value
        self.gravity = np.array([0, 0, 9.8])
        self.dt_mean = 0.01
        self.dt_std = 0.005
        self.total_iter = 2000

        # parse xml config file
        self.parse_config_file(data_folder + config_file)

        # construct rendering environment
        if play:
            from mujoco_rendering_env import mujoco_env
            self.render_env = mujoco_env.MujocoEnv(model_path=data_folder +
                                                   self.render_filename)
        else:
            self.render_env = None
        self.render_intervel = int(1.0 / 50.0 / self.dt_mean)

        # self.render_env._get_viewer()

        # noise related
        self.noisy_body = True
        self.noisy_sensor = True
        self.state_noise_std = np.array([
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.005, 0.005, 0.005, 0.0005, 0.0005,
            0.0005
        ])
        self.noisy_rotor = False
        self.noisy_aerodynamics = True
        self.simulate_delay = True
        self.delay = 0.04
        self.delay_mean = 0.04
        self.delay_std = 0.01
        self.noisy_dt = True
        self.constrain_motor_output = True
        self.motor_constrain_clip = 0.4
        self.real_rotors = []
        for i in range(len(self.rotors)):
            self.real_rotors.append(
                Rotor(self.rotors[i].position, self.rotors[i].direction,
                      self.rotors[i].clockwise, self.rotors[i].torque_coef))

        # integral term
        self.I_dt = self.dt_mean
        self.I_error = None

        # mass property
        self.real_mass = self.mass
        self.real_inertia_tensor = self.inertia_tensor.copy()

        # initialize rigid body
        self.rigid_body = rigid_body.RigidBody(
            mass=self.mass, inertia_body=self.inertia_tensor)
        self.state = None

        # train or play
        self.play = play

        # training variables
        self.seed()
        self.iter = None
        self.epoch = 0
        self.timesofar = None
        self.target = np.zeros(4)
        self.state_his = None
        self.I_error = np.zeros(4)

        # construct action space
        self.max_thrust = 7.0
        action_low = np.ones(len(self.rotors)) * -1.0 * self.max_thrust / 2.0
        action_high = np.ones(len(self.rotors)) * self.max_thrust / 2.0
        self.action_space = spaces.Box(action_low,
                                       action_high,
                                       dtype=np.float32)

        # construct observation space
        ob = self.get_observation_vector()
        ob_low = np.ones(len(ob)) * (-np.finfo(np.float32).max)
        ob_high = np.ones(len(ob)) * (np.finfo(np.float32).max)
        self.observation_space = spaces.Box(ob_low, ob_high, dtype=np.float32)