diff --git a/.justfile b/.justfile index 333bf15..e5e3213 100644 --- a/.justfile +++ b/.justfile @@ -9,6 +9,10 @@ upload: --exclude='data/versioned_data/' \ . ial-jumper-ial-pangyg:/home/ial-pangyg/docker-workspace/projects/mini-nav/ +download: + rsync -avLh --progress --stats --itemize-changes \ + ial-jumper-ial-pangyg:/home/ial-pangyg/docker-workspace/projects/mini-nav/outputs . + sync-pkgs: export UV_PROJECT_ENVIRONMENT="/workspace/envs/mini-nav/" && uv sync --inexact diff --git a/devenv.nix b/devenv.nix index bc1d054..205adb8 100644 --- a/devenv.nix +++ b/devenv.nix @@ -19,7 +19,7 @@ in { ]; enterShell = '' - export UV_PROJECT_ENVIRONMENT=$HOME/local/share/mamba/envs/mini-nav/bin/ + export UV_PROJECT_ENVIRONMENT=$HOME/.local/share/mamba/envs/mini-nav/ eval "$(micromamba shell hook --shell bash)" micromamba activate mini-nav diff --git a/mini-nav/habitat/test.py b/mini-nav/habitat/test.py index 5c9c710..3f72b55 100644 --- a/mini-nav/habitat/test.py +++ b/mini-nav/habitat/test.py @@ -1,21 +1,57 @@ import habitat_sim +import numpy as np +import plotly.express as px + +# 配置场景 +scene_path = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" sim_cfg = habitat_sim.SimulatorConfiguration() -sim_cfg.scene_id = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" +sim_cfg.scene_id = scene_path +sim_cfg.enable_physics = False -color_sensor = habitat_sim.CameraSensorSpec() -color_sensor.uuid = "color_sensor" -color_sensor.sensor_type = habitat_sim.SensorType.COLOR -color_sensor.resolution = [480, 640] -color_sensor.position = [0.0, 1.5, 0.0] +# 配置 agent +agent_cfg = habitat_sim.agent.AgentConfiguration() +rgb_sensor_spec = habitat_sim.CameraSensorSpec() +rgb_sensor_spec.uuid = "color_sensor" +rgb_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR +rgb_sensor_spec.resolution = [256, 256] +rgb_sensor_spec.position = [0.0, 1.5, 0.0] -agent_cfg = habitat_sim.AgentConfiguration() -agent_cfg.sensor_specifications = [color_sensor] +agent_cfg.sensor_specifications = [rgb_sensor_spec] +# 创建 simulator 实例 cfg = habitat_sim.Configuration(sim_cfg, [agent_cfg]) sim = habitat_sim.Simulator(cfg) -obs = sim.get_sensor_observations() -print("obs keys:", obs.keys()) -rgb = obs["color_sensor"] -print(rgb.shape) +# 初始化 agent +agent = sim.initialize_agent(0) + +# 设置 agent 初始位置 +agent_state = habitat_sim.AgentState() +agent_state.position = np.array([0.0, 0.0, 0.0]) +agent.set_state(agent_state) + +state = agent.get_state() +print("位置:", state.position) +print("旋转四元数:", state.rotation) + +observations = sim.get_sensor_observations() +rgb_image = observations["color_sensor"] # numpy array +print("RGB shape:", rgb_image.shape) + + +# 假设 rgb_image 已经被定义(例如一个 numpy array 或 PIL Image) +fig = px.imshow(rgb_image) + +# 隐藏坐标轴(等同于 plt.axis("off")) +fig.update_xaxes(visible=False) +fig.update_yaxes(visible=False) + +# 去除多余的边距,使图片填满画布 +fig.update_layout( + margin=dict(l=0, r=0, t=0, b=0), + coloraxis_showscale=False, # 如果是灰度图或带colorbar,这行可以隐藏色条 +) + +# 输出成 PNG 图片 +fig.write_html("outputs/output.html")