Skip to content
Snippets Groups Projects
Commit 8455735a authored by hagrid67's avatar hagrid67
Browse files

remove save images to tmp-images in test-collision.ipynb

parent 4fea2b28
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Test Collisions
A visual test of a "rear-shunt" collision, to ensure that the agent does not get marked as collided permananently.
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
from IPython.core import display
display.display(display.HTML("<style>.container { width:95% !important; }</style>"))
```
%% Output
%% Cell type:code id: tags:
``` python
import PIL
from IPython import display
from ipycanvas import canvas
import time
```
%% Cell type:code id: tags:
``` python
from flatland.envs import malfunction_generators as malgen
from flatland.envs.agent_utils import EnvAgent
#from flatland.envs import sparse_rail_gen as spgen
from flatland.envs import rail_generators as rail_gen
from flatland.envs import agent_chains as ac
from flatland.envs.rail_env import RailEnv, RailEnvActions
from flatland.envs.persistence import RailEnvPersister
from flatland.utils.rendertools import RenderTool
from flatland.utils import env_edit_utils as eeu
from flatland.utils import jupyter_utils as ju
```
%% Cell type:code id: tags:
``` python
nAg=2
bUCF=False
bReverseStart=False
env, envModel = eeu.makeTestEnv(sName="merging_spurs", nAg=nAg, bUCF=bUCF)
oRT = RenderTool(env, show_debug=True)
oRT.render_env(show_rowcols=True, show_inactive_agents=True, show_observations=False)
oCan = canvas.Canvas(size=(600,300))
oCan.put_image_data(oRT.get_image())
print(f"UCF: {bUCF}")
display.display(oCan)
iPauseStep=10
iPauseLen = 5
for iStep in range(25):
if bReverseStart:
iAgentStart = max((nAg - 2 - iStep*2), 0)
else:
iAgentStart = 0
dActions = { i:int(RailEnvActions.MOVE_FORWARD) for i in range(iAgentStart, len(env.agents)) }
if (iStep >= iPauseStep) and (iStep < iPauseStep + iPauseLen):
dActions[0] = RailEnvActions.STOP_MOVING
#print(dActions)
env.step(dActions)
oRT.render_env(show_rowcols=True, show_inactive_agents=True, show_observations=False)
aImg = oRT.get_image()
pilImg = PIL.Image.fromarray(aImg)
oCan.put_image_data(aImg)
with open(f"tmp-images/img-{iStep:03d}.png", "wb") as fImg:
pilImg.save(fImg)
#with open(f"tmp-images/img-{iStep:03d}.png", "wb") as fImg:
# pilImg.save(fImg)
time.sleep(0.05)
```
%% Output
UCF: False
%% Cell type:code id: tags:
``` python
#!ffmpeg -i ./tmp-images/img-%03d.png -vcodec mpeg4 -filter:v "setpts=8.0*PTS" -y movie_nucf_stop.mp4
```
%% Cell type:code id: tags:
``` python
oEC = ju.EnvCanvas(env)
env.reset(regenerate_rail=False)
oEC.oRT.render_env()
```
%% Cell type:code id: tags:
``` python
oEC.show()
```
%% Output
%% Cell type:code id: tags:
``` python
oEC.step()
oEC.render()
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment