fix(env): environment setup correctly and pass habitat test

This commit is contained in:
2026-03-18 21:07:39 +08:00
parent 5885702bed
commit 2985b68f9a
3 changed files with 53 additions and 13 deletions

View File

@@ -9,6 +9,10 @@ upload:
--exclude='data/versioned_data/' \ --exclude='data/versioned_data/' \
. ial-jumper-ial-pangyg:/home/ial-pangyg/docker-workspace/projects/mini-nav/ . 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: sync-pkgs:
export UV_PROJECT_ENVIRONMENT="/workspace/envs/mini-nav/" && uv sync --inexact export UV_PROJECT_ENVIRONMENT="/workspace/envs/mini-nav/" && uv sync --inexact

View File

@@ -19,7 +19,7 @@ in {
]; ];
enterShell = '' 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)" eval "$(micromamba shell hook --shell bash)"
micromamba activate mini-nav micromamba activate mini-nav

View File

@@ -1,21 +1,57 @@
import habitat_sim 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 = 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() # 配置 agent
color_sensor.uuid = "color_sensor" agent_cfg = habitat_sim.agent.AgentConfiguration()
color_sensor.sensor_type = habitat_sim.SensorType.COLOR rgb_sensor_spec = habitat_sim.CameraSensorSpec()
color_sensor.resolution = [480, 640] rgb_sensor_spec.uuid = "color_sensor"
color_sensor.position = [0.0, 1.5, 0.0] 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 = [rgb_sensor_spec]
agent_cfg.sensor_specifications = [color_sensor]
# 创建 simulator 实例
cfg = habitat_sim.Configuration(sim_cfg, [agent_cfg]) cfg = habitat_sim.Configuration(sim_cfg, [agent_cfg])
sim = habitat_sim.Simulator(cfg) sim = habitat_sim.Simulator(cfg)
obs = sim.get_sensor_observations() # 初始化 agent
print("obs keys:", obs.keys()) agent = sim.initialize_agent(0)
rgb = obs["color_sensor"]
print(rgb.shape) # 设置 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")