diff --git a/carla_environment.py b/carla_environment.py index 0d50303630ac1caed5a270784ae5590a1f59c0bc..fdf734d68e73b9633cd9b05835b95f30c5319a22 100644 --- a/carla_environment.py +++ b/carla_environment.py @@ -174,9 +174,9 @@ class World: if self.player is not None: pos = self.player.get_transform() vel = self.player.get_velocity() - return [pos.location.x, pos.location.y, vel.x, vel.y, pos.rotation.yaw] + return [pos.location.x, pos.location.y, vel.x, vel.y, (pos.rotation.yaw/180)] else: - return [0,0,0] + return [0,0,0,0,0] def spawn_player(self, transform): """ Add a vehicle to the world. """ @@ -188,10 +188,11 @@ class World: self.collision_sensor = CollisionSensor(self.world, self.player) self.obstacle_sensor = ObstacleSensor(self.world, self.player) - def spawn_on_sidewalk(self): - position = carla.Transform(carla.Location(x=-13, y=57.5, z=0.2), carla.Rotation(pitch=0.0, yaw=-180, roll=0.0)) + def spawn_on_sidewalk(self, with_obstacles=False): + position = carla.Transform(carla.Location(x=-13, y=58.5, z=0.2), carla.Rotation(pitch=0.0, yaw=-190, roll=0.0)) self.spawn_player(position) - self.spawn_actors(self.sidewalk_parking_cars_transforms()) + if with_obstacles: + self.spawn_actors(self.sidewalk_parking_cars_transforms()) def sidewalk_parking_cars_transforms(self): @@ -238,42 +239,33 @@ class World: return reward def reward(self, action): - target = carla.Transform(carla.Location(x=-25.534311, y=54.460903, z=0.112781), carla.Rotation(pitch=0.000000, yaw=-175.922913, roll=-6.221135)) - pos = self.player.get_transform() - pos_diff = math.sqrt((target.location.x - pos.location.x)**2 + (target.location.y - pos.location.y)**2) - rot_diff = (target.rotation.yaw - pos.rotation.yaw) - velocity = self.player.get_velocity() - v = math.sqrt((velocity.x)**2 + (velocity.y)**2) + x, y, vx, vy, yaw = self.observation() - r = ((-pos_diff / 10) + 1) / 5 + target = carla.Transform( \ + carla.Location(x=-25.534311, y=54.460903, z=0.112781), \ + carla.Rotation(pitch=0.000000, yaw=-175.922913, roll=-6.221135)) - if v < 0.01: - r -= 0.5 - if v > 15.0: - r -= 10 + pos_diff = math.sqrt((target.location.x - x)**2 + (target.location.y - y)**2) + rot_diff = ((target.rotation.yaw / 180) - yaw) + + v = math.sqrt((vx)**2 + (vy)**2) - at_final_position = False - if pos_diff < 1.8: - if self.was_big_reward == False: - r += 50 - self.was_big_reward = True - if abs(rot_diff) < 5 and v < 0.01: - at_final_position = True - else: - if self.was_big_reward == True: - self.was_big_reward = False - r -= 50 + r = -0.1 + r += -0.01 * pos_diff done = False - if at_final_position : - print("Success") - r += 100 + + if pos_diff < 1.5: done = True + r += 100 + if self.collision_sensor.collision is not None: - r -= 250 + r -= 100 + done = True + + if pos_diff > 15: done = True - if action == IDLE: - r -= 0.3 + r -= 100 return self.observation(), r, done, None class ActionSpace: