mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-03-31 01:35:31 +08:00
chore(dev): update environment and tooling configuration
This commit is contained in:
21
.envrc
21
.envrc
@@ -2,11 +2,18 @@
|
|||||||
|
|
||||||
export DIRENV_WARN_TIMEOUT=20s
|
export DIRENV_WARN_TIMEOUT=20s
|
||||||
|
|
||||||
eval "$(devenv direnvrc)"
|
# 尝试加载 devenv 的 direnv 配置
|
||||||
|
if command -v devenv >/dev/null 2>&1; then
|
||||||
|
# 如果存在 devenv
|
||||||
|
eval "$(devenv direnvrc)"
|
||||||
|
|
||||||
# `use devenv` supports the same options as the `devenv shell` command.
|
# `use devenv` 支持和 `devenv shell` 相同的选项
|
||||||
#
|
# 示例:use devenv --quiet --impure --option services.postgres.enable:bool true
|
||||||
# To silence all output, use `--quiet`.
|
use devenv
|
||||||
#
|
else
|
||||||
# Example usage: use devenv --quiet --impure --option services.postgres.enable:bool true
|
# 如果不存在 devenv,则加载自己的 fallback 配置
|
||||||
use devenv
|
echo "devenv not found, loading fallback configuration..."
|
||||||
|
|
||||||
|
export UV_PROJECT_ENVIRONMENT="/workspace/envs/mini-nav"
|
||||||
|
export MY_DEV_ENV=1
|
||||||
|
fi
|
||||||
|
|||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -227,3 +227,8 @@ devenv.local.yaml
|
|||||||
|
|
||||||
# pre-commit
|
# pre-commit
|
||||||
.pre-commit-config.yaml
|
.pre-commit-config.yaml
|
||||||
|
|
||||||
|
# syncthing
|
||||||
|
.stversions/
|
||||||
|
.stfolder/
|
||||||
|
.backup/
|
||||||
|
|||||||
32
.justfile
32
.justfile
@@ -14,8 +14,40 @@ download:
|
|||||||
ial-jumper-ial-pangyg:/home/ial-pangyg/docker-workspace/projects/mini-nav/outputs .
|
ial-jumper-ial-pangyg:/home/ial-pangyg/docker-workspace/projects/mini-nav/outputs .
|
||||||
|
|
||||||
sync-pkgs:
|
sync-pkgs:
|
||||||
|
# micromamba env create -f ./environment.yml
|
||||||
export UV_PROJECT_ENVIRONMENT="/workspace/envs/mini-nav/" && uv sync --inexact
|
export UV_PROJECT_ENVIRONMENT="/workspace/envs/mini-nav/" && uv sync --inexact
|
||||||
|
|
||||||
sync-data:
|
sync-data:
|
||||||
python -m habitat_sim.utils.datasets_download --uids habitat_test_scenes --data-path data/
|
python -m habitat_sim.utils.datasets_download --uids habitat_test_scenes --data-path data/
|
||||||
python -m habitat_sim.utils.datasets_download --uids habitat_example_objects --data-path data/
|
python -m habitat_sim.utils.datasets_download --uids habitat_example_objects --data-path data/
|
||||||
|
|
||||||
|
ssh:
|
||||||
|
ssh \
|
||||||
|
-L 127.0.0.1:22001:127.0.0.1:22000 \
|
||||||
|
-R 127.0.0.1:22001:127.0.0.1:22000 \
|
||||||
|
-L 127.0.0.1:8385:127.0.0.1:8384 \
|
||||||
|
-L 127.0.0.1:2718:172.30.0.2:2718 \
|
||||||
|
ial-gpu_workstation_1
|
||||||
|
|
||||||
|
docker:
|
||||||
|
docker exec -it docker-ial-pangyg bash
|
||||||
|
|
||||||
|
marimo:
|
||||||
|
export UV_PROJECT_ENVIRONMENT="/workspace/envs/mini-nav/" \
|
||||||
|
&& uv run marimo edit ./mini-nav/habitat/test.py --host 0.0.0.0 --port 2718
|
||||||
|
|
||||||
|
add +packages:
|
||||||
|
uv add {{ packages }} --no-sync
|
||||||
|
just sync-pkgs
|
||||||
|
|
||||||
|
remove +packages:
|
||||||
|
uv remove {{ packages }} --no-sync
|
||||||
|
just sync-pkgs
|
||||||
|
|
||||||
|
add-dev +packages:
|
||||||
|
uv add {{ packages }} --group dev --no-sync
|
||||||
|
just sync-pkgs
|
||||||
|
|
||||||
|
remove-dev +packages:
|
||||||
|
uv remove {{ packages }} --group dev --no-sync
|
||||||
|
just sync-pkgs
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ name: mini-nav
|
|||||||
channels:
|
channels:
|
||||||
- pytorch
|
- pytorch
|
||||||
- nvidia
|
- nvidia
|
||||||
- conda-forge
|
|
||||||
- aihabitat-nightly
|
- aihabitat-nightly
|
||||||
|
- conda-forge
|
||||||
dependencies:
|
dependencies:
|
||||||
- python=3.10
|
- python=3.10
|
||||||
- pip
|
- pip
|
||||||
@@ -15,5 +15,4 @@ dependencies:
|
|||||||
# Toolsets
|
# Toolsets
|
||||||
- uv
|
- uv
|
||||||
- just
|
- just
|
||||||
- git
|
- nodejs
|
||||||
- git-lfs
|
|
||||||
|
|||||||
@@ -1,57 +1,159 @@
|
|||||||
import habitat_sim
|
import marimo
|
||||||
import numpy as np
|
|
||||||
import plotly.express as px
|
|
||||||
|
|
||||||
# 配置场景
|
__generated_with = "0.21.1"
|
||||||
scene_path = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb"
|
app = marimo.App()
|
||||||
|
|
||||||
sim_cfg = habitat_sim.SimulatorConfiguration()
|
|
||||||
sim_cfg.scene_id = scene_path
|
|
||||||
sim_cfg.enable_physics = False
|
|
||||||
|
|
||||||
# 配置 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.sensor_specifications = [rgb_sensor_spec]
|
|
||||||
|
|
||||||
# 创建 simulator 实例
|
|
||||||
cfg = habitat_sim.Configuration(sim_cfg, [agent_cfg])
|
|
||||||
sim = habitat_sim.Simulator(cfg)
|
|
||||||
|
|
||||||
# 初始化 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)
|
@app.cell
|
||||||
fig = px.imshow(rgb_image)
|
def _():
|
||||||
|
import habitat_sim
|
||||||
|
from habitat_sim import ShortestPath
|
||||||
|
import numpy as np
|
||||||
|
import plotly.express as px
|
||||||
|
from matplotlib import pyplot as plt
|
||||||
|
|
||||||
# 隐藏坐标轴(等同于 plt.axis("off"))
|
return ShortestPath, habitat_sim, np, plt
|
||||||
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 图片
|
@app.cell
|
||||||
fig.write_html("outputs/output.html")
|
def _(habitat_sim):
|
||||||
|
# 配置场景
|
||||||
|
scene_path = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb"
|
||||||
|
|
||||||
|
sim_cfg = habitat_sim.SimulatorConfiguration()
|
||||||
|
sim_cfg.scene_id = scene_path
|
||||||
|
sim_cfg.enable_physics = False
|
||||||
|
return (sim_cfg,)
|
||||||
|
|
||||||
|
|
||||||
|
@app.cell
|
||||||
|
def _(habitat_sim, sim_cfg):
|
||||||
|
# 配置 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.sensor_specifications = [rgb_sensor_spec]
|
||||||
|
|
||||||
|
# 创建 simulator 实例
|
||||||
|
cfg = habitat_sim.Configuration(sim_cfg, [agent_cfg])
|
||||||
|
sim = habitat_sim.Simulator(cfg)
|
||||||
|
return (sim,)
|
||||||
|
|
||||||
|
|
||||||
|
@app.cell
|
||||||
|
def _(habitat_sim, plt, sim):
|
||||||
|
# 初始化 agent
|
||||||
|
agent = sim.initialize_agent(0)
|
||||||
|
|
||||||
|
# 设置 agent 初始位置:使用可导航点,而不是写死 [0,0,0]
|
||||||
|
agent_state = habitat_sim.AgentState()
|
||||||
|
agent_state.position = sim.pathfinder.get_random_navigable_point()
|
||||||
|
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"]
|
||||||
|
print("RGB shape:", rgb_image.shape)
|
||||||
|
print("RGB min/max:", rgb_image[..., :3].min(), rgb_image[..., :3].max())
|
||||||
|
|
||||||
|
|
||||||
|
plt.imshow(rgb_image)
|
||||||
|
plt.axis("off")
|
||||||
|
plt.show()
|
||||||
|
return (agent,)
|
||||||
|
|
||||||
|
|
||||||
|
@app.cell
|
||||||
|
def _(agent, plt, sim):
|
||||||
|
action_names = list(agent.agent_config.action_space.keys())
|
||||||
|
print("可用动作:", action_names)
|
||||||
|
|
||||||
|
# 进行一步移动
|
||||||
|
sim.step("move_forward")
|
||||||
|
|
||||||
|
import random
|
||||||
|
6
|
||||||
|
for i in range(5):
|
||||||
|
action = random.choice(action_names)
|
||||||
|
obs = sim.step(action)
|
||||||
|
rgb = obs["color_sensor"]
|
||||||
|
plt.imshow(rgb)
|
||||||
|
plt.axis("off")
|
||||||
|
plt.show()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@app.cell
|
||||||
|
def _(sim):
|
||||||
|
pathfinder = sim.pathfinder
|
||||||
|
print("NavMesh是否加载:", pathfinder.is_loaded)
|
||||||
|
print("可导航面积:", pathfinder.navigable_area)
|
||||||
|
print("场景边界:", pathfinder.get_bounds())
|
||||||
|
|
||||||
|
# 获取随机可导航点
|
||||||
|
rand_point = pathfinder.get_random_navigable_point()
|
||||||
|
print("随机可导航点:", rand_point)
|
||||||
|
return (pathfinder,)
|
||||||
|
|
||||||
|
|
||||||
|
@app.cell
|
||||||
|
def _(ShortestPath, pathfinder):
|
||||||
|
start = pathfinder.get_random_navigable_point()
|
||||||
|
end = pathfinder.get_random_navigable_point()
|
||||||
|
|
||||||
|
path = ShortestPath()
|
||||||
|
path.requested_start = start
|
||||||
|
path.requested_end = end
|
||||||
|
|
||||||
|
found = pathfinder.find_path(path)
|
||||||
|
print("是否找到路径:", found)
|
||||||
|
print("路径点:", path.points)
|
||||||
|
print("路径长度:", path.geodesic_distance)
|
||||||
|
return path, start
|
||||||
|
|
||||||
|
|
||||||
|
@app.cell
|
||||||
|
def _(path, pathfinder, plt, sim, start):
|
||||||
|
from habitat.utils.visualizations import maps
|
||||||
|
|
||||||
|
top_down_map = maps.get_topdown_map(
|
||||||
|
pathfinder, height=start[1], meters_per_pixel=0.05
|
||||||
|
)
|
||||||
|
|
||||||
|
# 绘制路径
|
||||||
|
trajectory = [
|
||||||
|
maps.to_grid(p[2], p[0], top_down_map.shape, pathfinder=sim.pathfinder)
|
||||||
|
for p in path.points
|
||||||
|
]
|
||||||
|
maps.draw_path(top_down_map, trajectory)
|
||||||
|
|
||||||
|
plt.imshow(top_down_map)
|
||||||
|
plt.axis("off")
|
||||||
|
plt.show()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@app.cell
|
||||||
|
def _(habitat_sim, np):
|
||||||
|
# 高级控制:连续动作和滑动碰撞
|
||||||
|
|
||||||
|
vel_control = habitat_sim.physics.VelocityControl()
|
||||||
|
vel_control.controlling_lin_vel = True
|
||||||
|
vel_control.lin_vel_is_local = True
|
||||||
|
vel_control.controlling_ang_vel = True
|
||||||
|
|
||||||
|
# 设置线速度和角速度
|
||||||
|
vel_control.linear_velocity = np.array([0, 0, -1.0]) # forward
|
||||||
|
vel_control.angular_velocity = np.array([0, 0.1, 0]) # rotation
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run()
|
||||||
|
|||||||
@@ -5,12 +5,17 @@ description = "Add your description here"
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"altair>=6.0.0",
|
||||||
"dash>=3.4.0",
|
"dash>=3.4.0",
|
||||||
"dash-ag-grid>=33.3.3",
|
"dash-ag-grid>=33.3.3",
|
||||||
"dash-mantine-components>=2.5.1",
|
"dash-mantine-components>=2.5.1",
|
||||||
"datasets>=4.5.0",
|
"datasets>=4.5.0",
|
||||||
|
"habitat-baselines>=0.3.320250127",
|
||||||
|
"habitat-lab>=0.3.320250127",
|
||||||
"httpx[socks]>=0.28.1",
|
"httpx[socks]>=0.28.1",
|
||||||
"lancedb>=0.27.1",
|
"lancedb>=0.27.1",
|
||||||
|
"marimo>=0.21.1",
|
||||||
|
"matplotlib>=3.10.8",
|
||||||
"polars[database,numpy,pandas,pydantic]>=1.37.1",
|
"polars[database,numpy,pandas,pydantic]>=1.37.1",
|
||||||
"pyarrow>=23.0.0",
|
"pyarrow>=23.0.0",
|
||||||
"pydantic>=2.12.5",
|
"pydantic>=2.12.5",
|
||||||
@@ -25,6 +30,10 @@ dev = [
|
|||||||
"pip>=26.0.1",
|
"pip>=26.0.1",
|
||||||
"pytest>=9.0.2",
|
"pytest>=9.0.2",
|
||||||
"pytest-mpi>=0.6",
|
"pytest-mpi>=0.6",
|
||||||
|
"python-lsp-server>=1.14.0",
|
||||||
|
"ruff>=0.15.7",
|
||||||
|
"ty>=0.0.24",
|
||||||
|
"websockets>=16.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.ty.environment]
|
[tool.ty.environment]
|
||||||
|
|||||||
Reference in New Issue
Block a user