This project for the Medical Robotics course BME714 implements an image-guided procedure for robotic surgical navigation. Using a Niryo Ned 2 robot, an onboard camera, and ArUco markers, the system automatically identifies a target anatomy (simulated by a phantom head) and aligns a surgical tool (cannula) along a planned trajectory from an entry point to an internal tumor.
This project simulates the workflow of clinical systems that use CT or MRI-derived coordinates to guide precise tool alignment by computing and chaining transformations between the robot, camera, marker, and patient frames.
The goal is to program the robot to:
- Calibrate the camera to estimate the pose of a phantom head using ArUco markers.
- Compute the transformation chain linking the robot, camera, marker, and patient.
- Calculate a trajectory vector from a defined entry point to a target tumor.
- Execute a precise movement to align the end-effector with this trajectory, maintaining a safe pre-insertion offset.
The robot successfully detected the phantom, computed the necessary kinematics, and aligned itself with the entry-to-tumor vector.
The robot starts in an observation pose, searching for the ArUco marker on the phantom.

The robot aligns its end-effector with the calculated trajectory, stopping at the safe pre-insertion offset.

| Coordinate | Planned (m) | Executed (m) | Difference (m) |
|---|---|---|---|
| X | -0.013 | -0.015 | 0.002 |
| Y | -0.029 | -0.031 | 0.002 |
| Z | 0.205 | 0.200 | 0.005 |
The minor discrepancies (2-5mm) are attributed to camera measurement noise, mechanical tolerances, and calibration limits.
-
Camera Calibration: Intrinsic parameters (
mtx.npy,dist.npy) are loaded to correct lens distortion. -
Pose Estimation: OpenCV's
solvePnPcomputes the marker pose ($T_{CM}$ ) relative to the camera. -
Kinematic Chaining:
-
Forward Kinematics: Computes the camera frame relative to the world frame (
$T_{WC}$ ) using robot joint angles ($T_{1-5}$ ) and fixed camera offsets. -
World-to-Marker:
$T_{WM} = T_{WC} \times T_{CM}$ -
World-to-Patient:
$T_{WP} = T_{WM} \times T_{MP}$ (where$T_{MP}$ is a fixed offset).
-
Forward Kinematics: Computes the camera frame relative to the world frame (
-
Trajectory Planning:
- Anatomical targets (Entry Point & Tumor) are transformed from Patient frame to World frame.
- An approach vector
$\vec{x}_{new}$ is normalized from Entry$\to$ Tumor. - A rotation matrix
$R_{new}$ is generated to align the end-effector's x-axis with$\vec{x}_{new}$ .
-
Execution: A pre-insertion offset (
$d_{offset} = 5cm$ ) is applied to calculate the final target pose, which is sent to the robot controller.
- Niryo Ned 2 Robot
- Phantom head with ArUco marker (Dict 4x4_250)
- Calibrated Camera
- Python 3.x
- PyNiryo
- OpenCV (
opencv-python,opencv-contrib-python) - NumPy
- Matplotlib
pip install pyniryo numpy opencv-python opencv-contrib-python matplotlib