Skip to content

Commit ce2d55c

Browse files
committed
fix(moveit-demo): address PR review comments
Scripts: - Add container auto-detection (CONTAINER_NAME env or grep for moveit_medkit_demo / moveit_medkit_demo_nvidia) in all docker exec scripts (inject-*, restore-normal) - Guard pick_place_loop against overlapping goals (goal_in_flight flag) - Use zip() instead of index-based iteration in joint_state_callback - Remove unused Optional import from manipulation_monitor - Add comment to bare except in pick_place_loop Config: - Rename task-constructor → pick-place-loop, mtc-pick-place → pick-place-node in panda_manifest.yaml to match actual demo node - Restrict CORS origins from wildcard to localhost:8080/3000 Packaging: - Add missing exec_depend entries in package.xml (rclpy, action_msgs, sensor_msgs, moveit_msgs, ros2_medkit_msgs) - Pin ros2_medkit clone to configurable ARG ROS2_MEDKIT_REF in Dockerfile - Remove rosdep || true fallback to fail on missing dependencies run-demo.sh: - Skip X11/xhost setup in headless mode or when DISPLAY is unset - Add --gazebo flag to usage help text - Fix image size estimate in output message Docs: - Update README to reflect Gazebo as default simulation mode - Rename entity hierarchy entries to match updated manifest
1 parent 4b4945c commit ce2d55c

12 files changed

Lines changed: 90 additions & 34 deletions

demos/moveit_pick_place/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ RUN apt-get update && apt-get install -y \
3232
sqlite3 libsqlite3-dev git curl \
3333
&& rm -rf /var/lib/apt/lists/*
3434

35-
# Clone ros2_medkit from GitHub
35+
# Clone ros2_medkit from GitHub (pinned to a specific ref for reproducibility)
36+
ARG ROS2_MEDKIT_REF=main
3637
WORKDIR ${COLCON_WS}/src
37-
RUN git clone --depth 1 https://github.com/selfpatch/ros2_medkit.git && \
38+
RUN git clone --depth 1 --branch ${ROS2_MEDKIT_REF} https://github.com/selfpatch/ros2_medkit.git && \
3839
mv ros2_medkit/src/ros2_medkit_gateway \
3940
ros2_medkit/src/ros2_medkit_msgs \
4041
ros2_medkit/src/ros2_medkit_serialization \
@@ -53,7 +54,7 @@ COPY scripts/ ${COLCON_WS}/src/moveit_medkit_demo/scripts/
5354
WORKDIR ${COLCON_WS}
5455
RUN bash -c "source /opt/ros/jazzy/setup.bash && \
5556
rosdep update && \
56-
rosdep install --from-paths src --ignore-src -r -y || true" && \
57+
rosdep install --from-paths src --ignore-src -r -y" && \
5758
bash -c "source /opt/ros/jazzy/setup.bash && \
5859
colcon build --symlink-install --cmake-args -DBUILD_TESTING=OFF"
5960

demos/moveit_pick_place/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ That's it! The script will:
4646
### 2. Available Options
4747

4848
```bash
49-
./run-demo.sh # Default: CPU, fake hardware, daemon mode
50-
./run-demo.sh --gazebo # Gazebo Harmonic physics simulation
51-
./run-demo.sh --gazebo --nvidia # Gazebo + GPU acceleration
52-
./run-demo.sh --nvidia # GPU acceleration (fake hardware)
49+
./run-demo.sh # Default: Gazebo simulation, daemon mode
50+
./run-demo.sh --fake # Fake hardware (mock controllers, no physics)
51+
./run-demo.sh --nvidia # Gazebo + GPU acceleration
52+
./run-demo.sh --fake --nvidia # Fake hardware + GPU acceleration
5353
./run-demo.sh --headless # No GUI (CI/server)
5454
./run-demo.sh --attached # Foreground with logs
5555
./run-demo.sh --no-cache # Rebuild without cache
5656
./run-demo.sh --update # Pull latest images first
5757
```
5858

5959
**Simulation modes:**
60-
- **Default (fake hardware)**Mock controllers echo commanded positions instantly. Fast startup (~10s), works headless, no physics. Good for diagnostics testing.
61-
- **Gazebo (`--gazebo`)**Gazebo Harmonic physics simulation with `gz_ros2_control`. Realistic dynamics, 3D world view. Slower startup (~30s), needs X11 or `--headless`. Recommended with `--nvidia` for GPU acceleration.
60+
- **Default (Gazebo)**Gazebo Harmonic physics simulation with `gz_ros2_control`. Realistic dynamics, 3D world view. Slower startup (~30s), needs X11 or `--headless`. Recommended with `--nvidia` for GPU acceleration.
61+
- **Fake hardware (`--fake`)**Mock controllers echo commanded positions instantly. Fast startup (~10s), works headless, no physics. Good for diagnostics testing.
6262

6363
### 3. Moving the Arm
6464

@@ -141,8 +141,8 @@ Areas
141141
│ Components
142142
│ ├── moveit-planning — OMPL planning pipeline
143143
│ │ Apps: move-group
144-
│ └── task-constructor — Pick-and-place coordinator
145-
│ Apps: mtc-pick-place
144+
│ └── pick-place-loop — Pick-and-place demo node
145+
│ Apps: pick-place-node
146146
147147
├── diagnostics/ — ros2_medkit gateway and fault management
148148
│ Components

demos/moveit_pick_place/config/medkit_params.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ diagnostics:
1111
refresh_interval_ms: 10000 # 10 seconds (default), reduces log spam
1212

1313
cors:
14-
allowed_origins: ["*"]
14+
# Restrict origins to localhost by default; add explicit origins
15+
# (e.g., "http://your-ui-host:3000") for cross-host access.
16+
allowed_origins: ["http://localhost:8080", "http://localhost:3000"]
1517
allowed_methods: ["GET", "PUT", "POST", "DELETE", "OPTIONS"]
1618
allowed_headers: ["Content-Type", "Accept"]
1719
allow_credentials: false

demos/moveit_pick_place/config/panda_manifest.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ components:
5757
description: "MoveIt 2 motion planning pipeline (OMPL)"
5858
area: planning
5959

60-
- id: task-constructor
61-
name: "Task Constructor"
60+
- id: pick-place-loop
61+
name: "Pick-and-Place Loop"
6262
type: "controller"
63-
description: "MoveIt Task Constructor pick-and-place coordinator"
63+
description: "Custom pick_place_loop.py pick-and-place demo node"
6464
area: planning
6565

6666
- id: gateway
@@ -135,10 +135,10 @@ apps:
135135
node_name: move_group
136136
namespace: /
137137

138-
- id: mtc-pick-place
138+
- id: pick-place-node
139139
name: "Pick-and-Place Loop"
140140
category: "application"
141-
is_located_on: task-constructor
141+
is_located_on: pick-place-loop
142142
description: "Continuous pick-and-place task executor"
143143
depends_on:
144144
- move-group
@@ -196,7 +196,7 @@ functions:
196196
category: "manipulation"
197197
description: "Pick objects and place them at target positions"
198198
hosted_by:
199-
- mtc-pick-place
199+
- pick-place-node
200200
- move-group
201201
- panda-arm-controller
202202
- panda-hand-controller

demos/moveit_pick_place/inject-collision.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ fi
2424

2525
# Add a sphere right in the arm's working area via /apply_planning_scene service
2626
echo "Adding surprise obstacle (sphere) to planning scene..."
27-
docker exec moveit_medkit_demo bash -c "
27+
28+
# Auto-detect running demo container (supports CPU and NVIDIA profiles)
29+
CONTAINER="${CONTAINER_NAME:-$(docker ps --format '{{.Names}}' | grep -E '^moveit_medkit_demo(_nvidia)?$' | head -n1)}"
30+
if [ -z "${CONTAINER}" ]; then
31+
echo "❌ Could not find a running MoveIt demo container."
32+
echo " Start the demo first, or set CONTAINER_NAME explicitly."
33+
exit 1
34+
fi
35+
36+
docker exec "${CONTAINER}" bash -c "
2837
source /opt/ros/jazzy/setup.bash && \
2938
source /root/demo_ws/install/setup.bash && \
3039
python3 -c \"

demos/moveit_pick_place/inject-grasp-failure.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ fi
2828

2929
# Move the target cylinder far away from the robot via /apply_planning_scene service
3030
echo "Moving target object to unreachable position (5.0, 5.0, 0.1)..."
31-
docker exec moveit_medkit_demo bash -c "
31+
32+
# Auto-detect running demo container (supports CPU and NVIDIA profiles)
33+
CONTAINER="${CONTAINER_NAME:-$(docker ps --format '{{.Names}}' | grep -E '^moveit_medkit_demo(_nvidia)?$' | head -n1)}"
34+
if [ -z "${CONTAINER}" ]; then
35+
echo "❌ Could not find a running MoveIt demo container."
36+
echo " Start the demo first, or set CONTAINER_NAME explicitly."
37+
exit 1
38+
fi
39+
40+
docker exec "${CONTAINER}" bash -c "
3241
source /opt/ros/jazzy/setup.bash && \
3342
source /root/demo_ws/install/setup.bash && \
3443
python3 -c \"

demos/moveit_pick_place/inject-planning-failure.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ fi
2424

2525
# Add a large wall via /apply_planning_scene service (reliable)
2626
echo "Adding collision wall to planning scene..."
27-
docker exec moveit_medkit_demo bash -c "
27+
28+
# Auto-detect running demo container (supports CPU and NVIDIA profiles)
29+
CONTAINER="${CONTAINER_NAME:-$(docker ps --format '{{.Names}}' | grep -E '^moveit_medkit_demo(_nvidia)?$' | head -n1)}"
30+
if [ -z "${CONTAINER}" ]; then
31+
echo "❌ Could not find a running MoveIt demo container."
32+
echo " Start the demo first, or set CONTAINER_NAME explicitly."
33+
exit 1
34+
fi
35+
36+
docker exec "${CONTAINER}" bash -c "
2837
source /opt/ros/jazzy/setup.bash && \
2938
source /root/demo_ws/install/setup.bash && \
3039
python3 -c \"

demos/moveit_pick_place/package.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<buildtool_depend>ament_cmake</buildtool_depend>
1111

1212
<exec_depend>ros2launch</exec_depend>
13+
<exec_depend>rclpy</exec_depend>
14+
<exec_depend>action_msgs</exec_depend>
15+
<exec_depend>sensor_msgs</exec_depend>
16+
<exec_depend>moveit_msgs</exec_depend>
17+
<exec_depend>ros2_medkit_msgs</exec_depend>
1318
<exec_depend>moveit_ros_planning_interface</exec_depend>
1419
<exec_depend>moveit_resources_panda_moveit_config</exec_depend>
1520
<exec_depend>moveit_resources_panda_description</exec_depend>

demos/moveit_pick_place/restore-normal.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ fi
2424
# 1. Remove injected collision objects via /apply_planning_scene service
2525
# Using service call (not topic pub) for reliable planning scene updates
2626
echo "Removing injected collision objects..."
27-
docker exec moveit_medkit_demo bash -c "
27+
28+
# Auto-detect running demo container (supports CPU and NVIDIA profiles)
29+
CONTAINER="${CONTAINER_NAME:-$(docker ps --format '{{.Names}}' | grep -E '^moveit_medkit_demo(_nvidia)?$' | head -n1)}"
30+
if [ -z "${CONTAINER}" ]; then
31+
echo "❌ Could not find a running MoveIt demo container."
32+
echo " Start the demo first, or set CONTAINER_NAME explicitly."
33+
exit 1
34+
fi
35+
36+
docker exec "${CONTAINER}" bash -c "
2837
source /opt/ros/jazzy/setup.bash && \
2938
source /root/demo_ws/install/setup.bash && \
3039
python3 -c \"

demos/moveit_pick_place/run-demo.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ if ! command -v docker &> /dev/null; then
1515
exit 1
1616
fi
1717

18-
# Setup X11 forwarding for RViz GUI
19-
echo "Setting up X11 forwarding..."
20-
xhost +local:docker 2>/dev/null || {
21-
echo " Warning: xhost failed. GUI may not work."
22-
echo " Install with: sudo apt install x11-xserver-utils"
23-
}
18+
# Setup X11 forwarding for RViz GUI (skip in headless mode or when no display)
19+
if [[ "${HEADLESS:-false}" != "true" ]] && [[ -n "${DISPLAY:-}" ]]; then
20+
echo "Setting up X11 forwarding..."
21+
xhost +local:docker 2>/dev/null || {
22+
echo " Warning: xhost failed. GUI may not work."
23+
echo " Install with: sudo apt install x11-xserver-utils"
24+
}
25+
fi
2426

2527
# Cleanup function
2628
cleanup() {
2729
echo ""
2830
echo "Cleaning up..."
29-
xhost -local:docker 2>/dev/null || true
31+
if [[ "${HEADLESS:-false}" != "true" ]] && [[ -n "${DISPLAY:-}" ]]; then
32+
xhost -local:docker 2>/dev/null || true
33+
fi
3034
echo "Done!"
3135
}
3236
trap cleanup EXIT
@@ -44,6 +48,7 @@ usage() {
4448
echo ""
4549
echo "Options:"
4650
echo " --nvidia Use NVIDIA GPU acceleration"
51+
echo " --gazebo Run in Gazebo simulation mode (default)"
4752
echo " --fake Use fake hardware (mock controllers, no physics)"
4853
echo " --no-cache Build Docker images without cache"
4954
echo " --headless Run without GUI (default: GUI enabled)"
@@ -53,6 +58,7 @@ usage() {
5358
echo ""
5459
echo "Examples:"
5560
echo " $0 # Daemon mode with Gazebo (default)"
61+
echo " $0 --gazebo # Gazebo simulation mode (default)"
5662
echo " $0 --attached # Foreground with logs"
5763
echo " $0 --headless # Headless mode (no GUI)"
5864
echo " $0 --fake # Fake hardware (no physics sim)"
@@ -126,7 +132,7 @@ echo "Run mode: $([ "$DETACH_MODE" = "true" ] && echo "daemon (background)" || e
126132

127133
# Build and run
128134
echo " Building and starting demo..."
129-
echo " (First run takes ~15-20 min, downloading ~5-6GB image)"
135+
echo " (First run takes ~15-20 min, downloading ~7GB image)"
130136
echo ""
131137
echo "🌐 REST API available at: http://localhost:8080/api/v1/"
132138
echo "🌐 Web UI available at: http://localhost:3000/"

0 commit comments

Comments
 (0)