Skip to content

MakeHardwareStation() always triggers GitHub model download even with manually patched package_map #468

@UnderJollyRogers

Description

@UnderJollyRogers

Issue Description:

When using manipulation.station.MakeHardwareStation() with a custom Parser and a patched package_map to point to local model resources (e.g., inside a virtual environment), Drake still attempts to download model files from GitHub.

I am working in a virtual environment where I pre-installed all required models under:

$VIRTUAL_ENV/share/drake_models/

In order to avoid online fetching, I use a parser_preload_callback:

def prefinalize(parser):
    package_map = parser.package_map()
    if package_map.Contains("drake_models"):
        package_map.Remove("drake_models")
    package_map.Add("drake_models", models_dir)


station = builder.AddSystem(MakeHardwareStation(
    scenario,
    parser_preload_callback=prefinalize
))

Despite this setup, Drake still attempts to fetch packages online when calling MakeHardwareStation().

Workaround

I was able to bypass the issue by not using MakeHardwareStation() and instead building the plant manually. This method gives me full control over the Parser and package_map, avoiding the unwanted GitHub downloads:

venv = os.environ.get("VIRTUAL_ENV")
if not venv:
    raise RuntimeError("No VIRTUAL_ENV found. Activate your venv first.")

models_dir = os.path.join(venv, "share", "drake_models")
allegro_pkg_dir = os.path.join(models_dir, "allegro_hand_description")
allegro_urdf = os.path.join(allegro_pkg_dir, "urdf", "allegro_hand_description_left.urdf")

if not os.path.exists(allegro_urdf):
    raise FileNotFoundError(f"Can't find Allegro URDF at: {allegro_urdf}")

builder = DiagramBuilder()
plant, scene_graph = AddMultibodyPlantSceneGraph(builder, time_step=0.0)
meshcat = StartMeshcat()
MeshcatVisualizer.AddToBuilder(builder, scene_graph, meshcat)

parser = Parser(plant)
pm = parser.package_map()

# Forcefully remove and remap the 'drake_models' package to local
if pm.Contains("drake_models"):
    pm.Remove("drake_models")
pm.Add("drake_models", models_dir)

# Also add the sub-package if needed
if not pm.Contains("allegro_hand_description"):
    pm.Add("allegro_hand_description", allegro_pkg_dir)

instances = parser.AddModels(allegro_urdf)
plant.Finalize()

This manual setup works as expected and respects the local model paths. However, a similar result is currently not possible using MakeHardwareStation() due to its internal handling of model loading.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions