def reset(self): # camera dronesim.installcamera([0,-15,180], 110, 63, 0.01, 500) # state related property position_hunter = [0.0, 0.0, 10.0] # x, y, z orientation_hunter = [0.0, 0.0, 0.0] # roll, pitch, taw #the position of target is generated randomly and should not exceed the vision range of hunter position_target = (np.array([10.0, 0.0, 10.0]) + np.random.normal(0, 5)).tolist() # x, y, z orientation_target = [0.0, 0.0, 0.0] # roll, pitch, yaw self.roll_target, self.pitch_target, self.yaw_target, self.thrust_target = 0, 0, 0, 0 absolute_x, absolute_y, target_in_front = dronesim.projection(position_hunter, orientation_hunter, position_target, float(self.width), float(self.height)) distance = np.linalg.norm(np.array(position_hunter) - np.array(position_target)) # invalid initialization while (not target_in_front or absolute_x > self.max_absolute_x or absolute_x < self.min_absolute_x or absolute_y > self.max_absolute_y or absolute_y < self.min_absolute_y or distance > self.max_initial_distance or distance < self.min_initial_distance): position_target = (np.array([10.0, 0.0, 10.0]) + np.random.normal(0, 5)).tolist() absolute_x, absolute_y, target_in_front = dronesim.projection(position_hunter, orientation_hunter, position_target, float(self.width), float(self.height)) distance = np.linalg.norm(np.array(position_hunter) - np.array(position_target)) dronesim.siminit(np.squeeze(np.asarray(position_hunter)),np.squeeze(np.asarray(orientation_hunter)), \ np.squeeze(np.asarray(position_target)),np.squeeze(np.asarray(orientation_target)), 20, 5) self.init_pos_target = position_target self.previous_distance = distance self.state = self.get_state() self.iteration = 0 self.episodes = 0 return self.state
def reset(self): # camera dronesim.installcamera([0, -15, 180], 110, 63, 0.01, 500) # state related property position_hunter = [0.0, 0.0, 10.0] # x, y, z orientation_hunter = [0.0, 0.0, 0.0] # roll, pitch, taw # position_hunter = np.matrix([44.41015975 -3.96066086 7.88967305]) # orientation_hunter = np.matrix([-11.276222823141545, 8.627114153116235, 27.256829024182572]) # position_target = np.matrix([17.49014858 -5.98676401 21.02755752]) #the position of target is generated randomly and should not exceed the vision range of hunter position_target = (np.array([10.0, 0.0, 10.0]) + np.random.normal(0, 5)).tolist() # x, y, z orientation_target = [0.0, 0.0, 0.0] # roll, pitch, yaw self.roll_target, self.pitch_target, self.yaw_target, self.thrust_target = 0, 0, 0, 0 # print('error c') # print('lala: ', position_hunter, orientation_hunter, position_target, self.width, self.height) absolute_x, absolute_y, target_in_front = dronesim.projection( position_hunter, orientation_hunter, position_target, float(self.width), float(self.height)) # print('position: ', position_hunter) # print('error e') # print('pos_hunter: ', position_hunter) # print('pos_target: ', position_target) distance = np.linalg.norm( np.array(position_hunter) - np.array(position_target)) # invalid initialization # print('error d') while (not target_in_front or absolute_x > self.max_absolute_x or absolute_x < self.min_absolute_x or absolute_y > self.max_absolute_y or absolute_y < self.min_absolute_y or distance > self.max_initial_distance or distance < self.min_initial_distance): position_target = (np.array([10.0, 0.0, 10.0]) + np.random.normal(0, 5)).tolist() absolute_x, absolute_y, target_in_front = dronesim.projection( position_hunter, orientation_hunter, position_target, float(self.width), float(self.height)) distance = np.linalg.norm( np.array(position_hunter) - np.array(position_target)) # print(position_hunter, orientation_hunter, position_target) # position_hunter = np.matrix([38.5, 26.8, 30.3]) # orientation_hunter = np.matrix([20.5,12.9,84.9]) # position_target = np.matrix([16.4,8.8,39.9]) # print('error a') dronesim.siminit(np.squeeze(np.asarray(position_hunter)),np.squeeze(np.asarray(orientation_hunter)), \ np.squeeze(np.asarray(position_target)),np.squeeze(np.asarray(orientation_target)), 20, 5) # print('error b') self.previous_distance = distance self.state = self.get_state() self.iteration = 0 self.episodes = 0 return self.state
def reset(self): # state related property position_hunter = np.matrix([0.0, 0.0, 10.0]) # x, y, z orientation_hunter = np.matrix([0.0, 0.0, 0.0]) # roll, pitch, taw #the position of target is generated randomly and should not exceed the vision range of hunter position_target = np.matrix([10.0, 0.0, 10.0]) + np.random.normal( 0, 5) # x, y, z orientation_target = np.matrix([0.0, 0.0, 0.0]) # roll, pitch, yaw (absolute_x, absolute_y), _ = projection(position_target, position_hunter, orientation_hunter, w=float(self.width), h=float(self.height)) print('x,y: ', absolute_x, absolute_y) distance = np.linalg.norm(position_hunter - position_target) # invalid initialization while (absolute_x > self.max_absolute_x or absolute_x < self.min_absolute_x or absolute_y > self.max_absolute_y or absolute_y < self.min_absolute_y or distance > self.max_initial_distance or distance < self.min_initial_distance): position_target = np.matrix([10.0, 0.0, 10.0]) + np.random.normal( 0, 5) (absolute_x, absolute_y), _ = projection(position_target, position_hunter, orientation_hunter, w=float(self.width), h=float(self.height)) distance = np.linalg.norm(position_hunter - position_target) dronesim.siminit(np.squeeze(np.asarray(position_hunter)),np.squeeze(np.asarray(orientation_hunter)), \ np.squeeze(np.asarray(position_target)),np.squeeze(np.asarray(orientation_target)), 20, 10) self.previous_distance = distance self.state = self.get_state() self.iteration = 0 self.episodes = 0 return self.state