Skip to content

Commit

Permalink
env.__str__(); reverted reward to old original: -2 + vel - angle
Browse files Browse the repository at this point in the history
  • Loading branch information
dizcza committed Oct 15, 2019
1 parent 32be9e4 commit 5aced07
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions gym_ultrasonic/envs/obstacle.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def set_position(self, position):
"""
self.position = np.array(position, dtype=np.float32)

def __str__(self):
return f"{self.__class__.__name__}({self.extra_repr()})"

def extra_repr(self):
return f"{self.width} x {self.height}"


class _Servo(Obstacle):
"""
Expand Down Expand Up @@ -133,6 +139,9 @@ def reset(self):
self.ccw = 1
self.angle = 0

def extra_repr(self):
return f"angle_range={self.angle_range}, angular_vel={self.angular_vel}"


class Robot(Obstacle):
"""
Expand Down Expand Up @@ -291,3 +300,6 @@ def reset(self, box):
self.position = box.sample()
self.angle = random.randint(0, 360)
self.servo.reset()

def extra_repr(self):
return f"{super().extra_repr()} with a {self.servo}"
7 changes: 6 additions & 1 deletion gym_ultrasonic/envs/ultrasonic_servo_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def reward(self, move_step, angle_turn, servo_turn):
"""
if self.robot.collision(self.obstacles):
return -1000, True
reward = move_step - 3 * abs(angle_turn)
reward = -2 + move_step - abs(angle_turn)
if servo_turn is not None:
reward -= abs(servo_turn)
return reward, False
Expand Down Expand Up @@ -214,3 +214,8 @@ def render(self, mode='human'):
self.servo_transform.set_rotation(math.radians(self.robot.servo.angle))
with_rgb = mode == 'rgb_array'
return self.viewer.render(return_rgb_array=with_rgb)

def __str__(self):
return f"{super().__str__()}:\nobservation_space={self.observation_space.low, self.observation_space.high};" \
f"\naction_space={self.action_space.low, self.action_space.high};" \
f"\n{self.robot}"

0 comments on commit 5aced07

Please sign in to comment.