A ROS 2-based intelligent color sorting system powered by the Franka Emika Panda robotic arm. This project integrates OpenCV computer vision, MoveIt 2 motion planning, and Gazebo simulation to create an autonomous pick-and-place system that detects and sorts colored objects with precision.
-
ποΈ Color Detection: Real-time OpenCV-based vision system for Red, Green, and Blue objects.
-
π§ Motion Planning: Advanced trajectory planning using MoveIt 2.
-
β‘ Autonomous Operation: Complete pick-and-place automation with gripper control.
-
π Dynamic Target Selection: Switch between colors without restarting the system.
-
π₯οΈ Visual Feedback: Integrated RViz visualization for motion planning and execution.
-
π¦ Dev Container Ready: Pre-configured VS Code Dev Container environment with GUI and GPU acceleration support for instant deployment.
-
Setting up a complete ROS 2 robotic system from scratch.
-
Integrating computer vision with robotic manipulation.
-
Motion planning and execution with MoveIt 2.
-
Using PyMoveIt2 for high-level Python control.
-
Building modular ROS 2 packages.
-
Dev Container containerization for robotics applications.
Get up and running in minutes with our pre-built Dev Container! This method eliminates dependency conflicts, provides a consistent environment, and automatically mounts your code so you can edit locally while running in Docker.
-
Docker installed on your system.
-
Visual Studio Code installed.
-
Dev Containers extension installed in VS Code.
-
X11 display server (for GUI applications like RViz and Gazebo).
-
Clone the repository to your local machine:
git clone https://github.com/Programiz-007/Vision-Guided-Robotic-Pick-and-Place-Using-ROS-2-and-OpenCV.git cd Vision-Guided-Robotic-Pick-and-Place-Using-ROS-2-and-OpenCV -
Open the folder in VS Code:
code .
-
Allow Docker to access your local X11 display (run this in your host terminal):
xhost +local:root -
In VS Code, press
Ctrl+Shift+P(orCmd+Shift+Pon Mac). -
Type and select Dev Containers: Reopen in Container.
-
VS Code will build the ROS 2 Humble image, install all MoveIt and OpenCV dependencies, and mount your workspace. (This may take a few minutes the first time).
Once the container is running, open the integrated terminal in VS Code (Ctrl+ `) and build the project:
cd /root/panda_ws
colcon build --symlink-install
source install/setup.bash
π You're now ready to run the project! Skip to the Running the Project section.
If you prefer not to use Docker, follow this setup guide for a local Ubuntu 22.04 installation.
-
Follow the official guide to install ROS 2 Humble Desktop.
-
Install build tools and MoveIt 2:
sudo apt update sudo apt install -y python3-rosdep python3-colcon-common-extensions python3-pip \ ros-humble-moveit ros-humble-moveit-common ros-humble-moveit-ros-move-group \ ros-humble-moveit-ros-planning ros-humble-moveit-ros-planning-interface \ ros-humble-moveit-visual-tools ros-humble-moveit-configs-utils \ ros-humble-moveit-setup-assistant ros-humble-ros2-control ros-humble-ros2-controllers \ ros-humble-gazebo-ros2-control ros-humble-ros-gz ros-humble-cv-bridge \ ros-humble-image-transport ros-humble-rqt-image-view -
Install Python requirements:
pip3 install --no-cache-dir opencv-python==4.10.0.84 numpy==1.24.4 transforms3d
mkdir -p ~/panda_ws/src
cd ~/panda_ws/src
git clone https://github.com/Programiz-007/Vision-Guided-Robotic-Pick-and-Place-Using-ROS-2-and-OpenCV.git .
cd ~/panda_ws
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --skip-keys=opencv_python -r -y
colcon build --symlink-install
source install/setup.bash
Open two terminal windows (if using Dev Containers, you can split the VS Code terminal).
source ~/panda_ws/install/setup.bash
ros2 launch panda_bringup pick_and_place.launch.py
Wait for Gazebo, RViz, and MoveIt to fully initialize.
source ~/panda_ws/install/setup.bash
ros2 run pymoveit2 pick_and_place.py --ros-args -p target_color:=R
Change colors by stopping (Ctrl+C) and rerunning with a different parameter:
-
For Green objects:
ros2 run pymoveit2 pick_and_place.py --ros-args -p target_color:=G -
For Blue objects:
ros2 run pymoveit2 pick_and_place.py --ros-args -p target_color:=B
src/
βββ .devcontainer/ # VS Code Docker environment config
βββ panda_description/ # Robot URDF, meshes, visuals
βββ panda_controller/ # Joint/gripper controllers
βββ panda_moveit/ # MoveIt 2 configuration
βββ panda_vision/ # OpenCV color detection
βββ panda_bringup/ # Launch files for full system
βββ pymoveit2/ # Python MoveIt 2 interface
βββ examples/
βββ pick_and_place.py # Main logic
| Package | Description | Key Files |
|---|---|---|
| panda_description | Robot model and visualization | panda.urdf.xacro, meshes |
| panda_controller | Controller configurations | panda_controllers.yaml |
| panda_moveit | Motion planning setup | MoveIt configs, SRDF |
| panda_vision | Computer vision system | color_detector.py |
| panda_bringup | System launcher | pick_and_place.launch.py |
| pymoveit2 | High-level control | pick_and_place.py |
Camera Feed β Color Detection β Object Localization
β
Motion Planning (MoveIt 2)
β
Trajectory Execution
β
Pick Object β Move to Bin β Place
- Vision System continuously monitors the workspace.
- Color detector identifies target color and computes 3D position.
- PyMoveIt2 receives object coordinates.
- MoveIt 2 plans collision-free trajectory.
- Robot controller executes motion.
- Gripper closes to grasp object.
- Motion planner computes path to sorting bin.
- Robot moves to designated area.
- Gripper opens to release object.
- System returns to home position and repeats.
Error: Cannot connect to display or RViz shows a black screen.
Solution: Ensure you ran xhost +local:root on your host machine before launching the Dev Container.
Error: Unable to plan or No valid plan found
Solutions:
-
Check if all controllers are active:
ros2 control list_controllers -
Ensure the Gazebo physics engine is not paused.
Solutions:
-
Check if the Gazebo camera plugin loaded:
ros2 topic list | grep camera -
Test the raw feed:
ros2 run rqt_image_view rqt_image_view -
If lighting in Gazebo is too dark/bright, adjust HSV thresholds in
panda_vision/color_detector.py.
This project is licensed under the MIT License.
Third-party code: pymoveit2 by Andrej Orsula is vendored in pymoveit2/ with its own license.