1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| def _compute_actions(self, traj_data, curr_time, goal_time): start_index = curr_time end_index = curr_time + self.len_traj_pred * self.waypoint_spacing + 1 yaw = traj_data["yaw"][start_index:end_index:self.waypoint_spacing] positions = traj_data["position"][start_index:end_index:self.waypoint_spacing] goal_pos = traj_data["position"][min(goal_time, len(traj_data["position"]) - 1)]
if len(yaw.shape) == 2: yaw = yaw.squeeze(1)
if yaw.shape != (self.len_traj_pred + 1,): const_len = self.len_traj_pred + 1 - yaw.shape[0] yaw = np.concatenate([yaw, np.repeat(yaw[-1], const_len)]) positions = np.concatenate([positions, np.repeat(positions[-1][None], const_len, axis=0)], axis=0)
assert yaw.shape == (self.len_traj_pred + 1,), f"{yaw.shape} and {(self.len_traj_pred + 1,)} should be equal" assert positions.shape == (self.len_traj_pred + 1, 2), f"{positions.shape} and {(self.len_traj_pred + 1, 2)} should be equal"
waypoints = to_local_coords(positions, positions[0], yaw[0]) goal_pos = to_local_coords(goal_pos, positions[0], yaw[0])
assert waypoints.shape == (self.len_traj_pred + 1, 2), f"{waypoints.shape} and {(self.len_traj_pred + 1, 2)} should be equal"
if self.learn_angle: yaw = yaw[1:] - yaw[0] actions = np.concatenate([waypoints[1:], yaw[:, None]], axis=-1) else: actions = waypoints[1:] if self.normalize: actions[:, :2] /= self.data_config["metric_waypoint_spacing"] * self.waypoint_spacing goal_pos /= self.data_config["metric_waypoint_spacing"] * self.waypoint_spacing
assert actions.shape == (self.len_traj_pred, self.num_action_params), f"{actions.shape} and {(self.len_traj_pred, self.num_action_params)} should be equal"
return actions, goal_pos
def _compute_actions(self, traj_data, curr_time, goal_time): start_index = curr_time end_index = curr_time + self.len_traj_pred * self.waypoint_spacing + 1
yaw = np.array(traj_data["yaw"][start_index:end_index:self.waypoint_spacing], dtype=np.float32).flatten() positions = np.array(traj_data["position"][start_index:end_index:self.waypoint_spacing], dtype=np.float32) goal_pos = np.array(traj_data["position"][min(goal_time, len(traj_data["position"]) - 1)], dtype=np.float32)
if yaw.shape[0] != self.len_traj_pred + 1: const_len = self.len_traj_pred + 1 - yaw.shape[0] yaw = np.concatenate([yaw, np.repeat(yaw[-1], const_len)]) positions = np.concatenate([positions, np.repeat(positions[-1][None], const_len, axis=0)], axis=0)
yaw = yaw.astype(np.float32) positions = positions.astype(np.float32)
waypoints = to_local_coords(positions, positions[0], float(yaw[0])) goal_pos = to_local_coords(goal_pos, positions[0], float(yaw[0]))
if self.learn_angle: yaw_delta = (yaw[1:] - yaw[0]).astype(np.float32) actions = np.concatenate([waypoints[1:], yaw_delta[:, None]], axis=-1) else: actions = waypoints[1:]
if self.normalize: actions[:, :2] /= self.data_config["metric_waypoint_spacing"] * self.waypoint_spacing goal_pos /= self.data_config["metric_waypoint_spacing"] * self.waypoint_spacing
actions = np.asarray(actions, dtype=np.float32) goal_pos = np.asarray(goal_pos, dtype=np.float32)
return actions, goal_pos
|