mit-acl / gym-collision-avoidance

MIT License
242 stars 74 forks source link

How Can I Import Customized Map? #20

Closed jx2518 closed 10 months ago

jx2518 commented 11 months ago

Hi! Really sorry for the continuous questions! As I am exploring the project, I wanted to import customized maps. I do see that in the world_maps folder there are three maps, as well as Map.py which sets up a map. But then I realized that the Map class is only imported by collision_avoidance_env.py but CollisionAvoidanceEnv class isn't subsequently imported by any one of the experiment python files such as example.py and run_full_test_suite.py. Therefore, I wonder where I can edit the map, say importing 001.png? Thank you very much for your time!

mfe7 commented 11 months ago

Hi - no problem. I haven't tested the static map system extensively (or recently), but here are some thoughts.

The CollisionAvoidanceEnv class is somehow imported through the gym.make line in the experiment scripts (gym has a mechanism of registering environments to instantiate classes, but presumably one could simply instantiate the class directly).

In terms of specifying which map to use, I think the idea was to use an attribute in the config to tell the environment to use a static map, then something like env.set_static_map(".../map_filename.png") to tell the environment which map to use see here?

If I remember correctly, my logic for checking collisions with the static map was quite inefficient and slows down the environment a lot, but maybe this provides a starting point.

jx2518 commented 11 months ago

Thank you so much for the quick reply, and Yes I am able to import a new map! While I was editing the code there was a minor issue which lies on line 20 of Map.py. imresize() is deprecated in SciPy 1.0.0, and removed in 1.3.0; and I was able to work around chaning it to cv2: self.static_map = cv2.resize(src=self.static_map,dsize=dims,interpolation=cv2.INTER_NEAREST).

But there is a follow-up issue that I found out: figure 0 shows the paths agents take in the original map (no obstacle); they reach their destinations.

image

However, when I switched to 001.png as the map, the orange agent doesn't move, blue and green agent stops at some point before reaching their destinations. I suspect that they hit the wall and then stop. But the wall isn't shown in the gif file.

image

So, do you know how I can make the map visible in the gif file? Thank you very much for your help!

mfe7 commented 11 months ago

The gif is generated by combining a bunch of png files (one per timestep), so you would probably just need to add the map image to the background in this function

jx2518 commented 11 months ago

Gotcha! Thank you very much!