duckietown / gym-duckietown

Self-driving car simulator for the Duckietown universe
http://duckietown.org
Other
45 stars 16 forks source link

Dynamic obstacles “leave an invisible static obstacle” at their starting pose #216

Open kaland313 opened 4 years ago

kaland313 commented 4 years ago

Incorrect behaviour

When running gym-duckietown with dynamic obstacles (duckiebots), the episode terminates when the ego-robot moves to the starting pose of an obstacle duckiebot, even though the later one moved away.

On the animation below, the robot moving diagonally is the ego-robot, and the other moving robot is a dynamic obstacle, an NPC duckiebot. The episode was terminated when the ego-robot reached the starting pose of the NPC-robot.

collision-issue-demo

Reproducing the incorrect behaviour

Run the following script on the latest version of gym-duckietown from the daffy or daffy-aido4 branches.

import time
import numpy as np
from gym_duckietown.simulator import Simulator

env = Simulator(map_name="loop_dyn_duckiebots", domain_rand=False)

env.user_tile_start = [0, 0]
env.start_pose = [[env.road_tile_size * 1.33, 0, env.road_tile_size * 4.75], -np.pi*0.2]

env.reset()
env.render('top_down')
time.sleep(1)

done = False
while not done:
    _, _, done, _ = env.step(np.array([0.25, 0.25]))
    env.render('top_down')

Or run the following script (in the same version):

import time
import numpy as np
from gym_duckietown.simulator import Simulator

env = Simulator(map_name="loop_empty", domain_rand=False)

env.user_tile_start = [0, 0]
env.start_pose = [[env.road_tile_size * 5, 0, env.road_tile_size * 1.33], np.pi]

obstacles = [{'kind': 'duckiebot',
              'pos': [3.5, 1.33],
              'rotate': 180,
              'height': 0.12,
              'static': False}]
env._load_objects({'objects': obstacles})

env.reset()
env.render('top_down')
time.sleep(1)

done = False
while not done:
    _, _, done, _ = env.step(np.array([1, 1]))
    env.render('top_down')

Cause of the incorrect behaviour

Centres, corners, etc. of dynamic obstacles are added to the list of collidable objects when the objects are loaded. Dynamic duckiebots than move away from their starting pose, but their initial centres, corners, etc. remain in the corresponding collidable object lists, which are used for collision checking. See: https://github.com/duckietown/gym-duckietown/blob/1c0919157f2e70b8c143b5e711b23d0cf5a76ab8/src/gym_duckietown/simulator.py#L751-L757 and: https://github.com/duckietown/gym-duckietown/blob/1c0919157f2e70b8c143b5e711b23d0cf5a76ab8/src/gym_duckietown/simulator.py#L1198-L1227