Skip to content

Repository files navigation

AutoInsituXRD

Python Version Framework: Flask Hardware: Universal Robots

Automation Framework for Coordinated In-Situ X-Ray Diffraction (XRD) Experiments

AutoInsituXRD is a Python-based automation framework designed for fully coordinated in-situ X-ray diffraction (XRD) experiments. It seamlessly integrates UR5e robot motion, screw-driven sample loading, angle changer actuation, and Anton Paar XRD instrument control into a unified, high-throughput automation workflow and REST API.


📑 Table of Contents


✨ Key Features

1. End-to-End In-Situ XRD Workflow Orchestration

  • In-Situ XRD Instrument Control: Interfaces with Anton Paar XRDynamic / XRDrive 500 instrument APIs via robust HTTP requests.
  • UR5e Robotic Manipulation: Supports UR5e robot program execution using direct dashboard socket controls.
  • Automated Sample Loader: Manages screw automation mechanisms and linear rail hardware via TMCM and Arduino serial interfaces.
  • Angle Changer Actuation: Elevates the crucible during in-situ XRD runs to dynamically change the gripping point from a vertical to a horizontal orientation.

2. Unified Web & REST API Interface

  • Provides lightweight Flask-based web endpoints for sample loading, unloading, door handling, and core experiment execution.
  • Includes clean, modern frontend UI assets located under templates/ and static/ for a centralized browser-based control dashboard.

📦 Prerequisites

  • Python 3.9 or newer
  • Conda (strongly recommended) or an equivalent Python environment manager
  • Global hardware parameters configured inside config.py
  • Valid .urp robot program files loaded under robot_arm_ur5e/templates/ within your robot controller (teach pendant)

⚙️ Installation & Setup

1. Clone the repository:

git clone https://github.com/CederGroupHub/AutoInsituXRD.git
cd AutoInsituXRD

2. Create and activate the Conda environment:

conda env create -f cond_env.yaml
conda activate insituXRD

3. Configure your hardware profile: Open config.py and map your specific instrument deployment parameters:

  • ROBOT_HOST
  • SCREW_TMCM_PORT
  • SCREW_LINEAR_RAIL_PORT
  • ANGLE_CHANGER_PORT
  • XRD_BASE_URL

🚀 Usage

1. Launch the Sample Control Web Dashboard

python app.py
  • Spawns a Flask server listening on port 8000.
  • Access the browser UI directly at http://127.0.0.1:8000/.
  • Available API Endpoints:
  • POST /api/home — Return hardware components to home position
  • POST /api/load_sample — Trigger automated sample loading sequence
  • POST /api/unload_sample — Trigger automated sample unloading sequence
  • POST /api/door_open — Open XRD enclosure door (executes predefined .urp motion planning)
  • POST /api/door_close — Close XRD enclosure door (executes predefined .urp motion planning)

2. Integrate with AlabOS (Run Experiment REST API Server)

python main_restAPI.py
  • Spawns an infrastructure-ready Flask server on port 5000.
  • Core Experiment Control Endpoints:
  • POST /insituXRD/run_experiment — Initialize and run a new execution block
  • GET /insituXRD/status — Query active hardware and sequence status

💡 Example Request (Curl)

curl -X POST [http://127.0.0.1:5000/insituXRD/run_experiment](http://127.0.0.1:5000/insituXRD/run_experiment) \
  -H "Content-Type: application/json" \
  -d '{
    "experiment_name": "Adaptive_Run_001",
    "user_name": "researcher",
    "base_storage_path": "C:/Users/XRDynamic/AutoExperiments",
    "xrd_scan_mode": "adaptive",
    "crucible_index": 0
  }'

3. Direct Execution via Command Line

python main.py
  • Directly connects to the UR5e robot, angle changer, screw setup, and the XRD unit.
  • Programmatically executes the comprehensive, standalone run_full_sequence() workflow.
  • Generates runtime execution logs and stores them under Logger/.

📂 Project Structure

The repository is highly modularized and structured as follows:

AutoInsituXRD/
├── Adaptive_insituXRD/     # Anton Paar XRD API client and adaptive scan helper classes
├── AngleChanger/           # Arduino serial interface for the angle changer actuator
├── Logger/                 # Logging utilities and runtime log storage directory
├── robot_arm_ur5e/         # UR5e robot dashboard interface and program execution drivers
├── SampleLoader/           # Screw automation and linear rail sample handling drivers
├── static/                 # Frontend JavaScript and CSS assets for the web interface
├── templates/              # Flask HTML templates for the browser control panel
├── XRD_recipe_template/    # Reference JSON templates for defining XRD experimental recipes
│
├── app.py                  # Flask server hosting the sample loader/unloader UI & manual controls
├── main_restAPI.py         # Production REST API server for external orchestrator (AlabOS) integration
├── main.py                 # Core sequencing script running the native in-situ automation routine
├── config.py               # Central configuration file for hardware ports and system constants
└── cond_env.yaml           # Conda environment file specifying exact dependencies

About

Python library for handling automated in-situ heating XRD

Resources

Code of conduct

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages