Skip to content
Snippets Groups Projects
Commit 04fdca7c authored by Armin Co's avatar Armin Co
Browse files

Simplified reward function

Reduced the problem to just, drive to a position.
parent ba4d8e61
No related branches found
No related tags found
No related merge requests found
...@@ -174,9 +174,9 @@ class World: ...@@ -174,9 +174,9 @@ class World:
if self.player is not None: if self.player is not None:
pos = self.player.get_transform() pos = self.player.get_transform()
vel = self.player.get_velocity() 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: else:
return [0,0,0] return [0,0,0,0,0]
def spawn_player(self, transform): def spawn_player(self, transform):
""" Add a vehicle to the world. """ """ Add a vehicle to the world. """
...@@ -188,9 +188,10 @@ class World: ...@@ -188,9 +188,10 @@ class World:
self.collision_sensor = CollisionSensor(self.world, self.player) self.collision_sensor = CollisionSensor(self.world, self.player)
self.obstacle_sensor = ObstacleSensor(self.world, self.player) self.obstacle_sensor = ObstacleSensor(self.world, self.player)
def spawn_on_sidewalk(self): def spawn_on_sidewalk(self, with_obstacles=False):
position = carla.Transform(carla.Location(x=-13, y=57.5, z=0.2), carla.Rotation(pitch=0.0, yaw=-180, roll=0.0)) 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_player(position)
if with_obstacles:
self.spawn_actors(self.sidewalk_parking_cars_transforms()) self.spawn_actors(self.sidewalk_parking_cars_transforms())
...@@ -238,42 +239,33 @@ class World: ...@@ -238,42 +239,33 @@ class World:
return reward return reward
def reward(self, action): 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)) x, y, vx, vy, yaw = self.observation()
pos = self.player.get_transform()
pos_diff = math.sqrt((target.location.x - pos.location.x)**2 + (target.location.y - pos.location.y)**2) target = carla.Transform( \
rot_diff = (target.rotation.yaw - pos.rotation.yaw) carla.Location(x=-25.534311, y=54.460903, z=0.112781), \
velocity = self.player.get_velocity() carla.Rotation(pitch=0.000000, yaw=-175.922913, roll=-6.221135))
v = math.sqrt((velocity.x)**2 + (velocity.y)**2)
pos_diff = math.sqrt((target.location.x - x)**2 + (target.location.y - y)**2)
r = ((-pos_diff / 10) + 1) / 5 rot_diff = ((target.rotation.yaw / 180) - yaw)
if v < 0.01: v = math.sqrt((vx)**2 + (vy)**2)
r -= 0.5
if v > 15.0: r = -0.1
r -= 10 r += -0.01 * pos_diff
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
done = False done = False
if at_final_position :
print("Success") if pos_diff < 1.5:
r += 100
done = True done = True
r += 100
if self.collision_sensor.collision is not None: if self.collision_sensor.collision is not None:
r -= 250 r -= 100
done = True
if pos_diff > 15:
done = True done = True
if action == IDLE: r -= 100
r -= 0.3
return self.observation(), r, done, None return self.observation(), r, done, None
class ActionSpace: class ActionSpace:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment