/PrintGuard

Real-Time Error Detection for 3D Printing PrintGuard Device on operation

Primary LanguageJupyter Notebook

PrintGuard

Real-Time Error Detection for 3D Printing

PrintGuard Device on operation

PrintGuard Web Interface

PrintGuard is a device designed to prevent plastic waste from failed 3D prints by using artificial intelligence and a camera to detect failures during printing.

It uses a raspberry Pi as a working device, combined with a camera and a relay (electrically operated switch) to collect and stop any 3D printer (Prusa, Ultimaker or others).

Via a web interface on your local network, you can view and manage the product in real time. Ideal for positioning your camera correctly, managing the relay trigger threshold or remotely shutting down your 3d printer.

Table of contents

Requirements

Libraries

  • Python == 3.9 (Has not been tested for more recent versions)
  • RPi.GPIO >= 0.7.1 : A module to control Raspberry Pi GPIO channels
  • tensorflow == 2.16.1 : Python interface for machine learning and artificial intelligence.
  • opencv-python-headless >= 4.9.0.80 : Open Computer Vision Library
  • Flask >= 3.0.3 : Micro web framework written in Python

The complete list is in requirements.txt

Components

  • 1 Raspberry Pi
  • 1 230V Power Relays
  • 1 USB webcam (preferably with autofocus)
  • 1 RGB LED
  • 1 button
  • 3 resistors of 220 Ohms and 1 of 1 kOhm
  • Some electrical wires
  • a fan (if the system is in a box)

Install

Hardware Installation

Connect the components as shown below:

Electronic circuit

  • RGB LED:
    • Red: GPIO Pin 19
    • Green: GPIO Pin 13
    • Blue: GPIO Pin 26
    • A 220 Ohm resistor between each GPIO and each RGB pin
  • Button:
    • One leg to GPIO Pin 6
    • The other leg to the ground by a 1 kOhm resistor.
  • Relay:
    • GPIO Pin 4 .

Software Installation

  1. Install Raspbian or any other Debian-based operating system:

We recommend using the Raspberry Pi Imager provided by the official Raspberry project to easily create a bootable SD card for your Raspberry. You need to be able to connect to the operating system to perform the following installation steps (for example, via ssh on your local network)

  1. Install Git and clone the repository:

Connect to your raspberry with an administrator account and clone the repository in your personal directory:

sudo apt install git git-lfs
git clone https://github.com/cc-ca/projet-impression-3d.git
  1. Make Setup:

Go to the repository directory and start the setup script:

cd projet-impression-3d
make setup

This installs all the necessary dependencies in a virtual environment and creates a systemd service to start the program automatically when the raspberry pi is booted. You will be asked for your user password and to accept the installation of the missing dependencies.

  1. First launch of the programme:

You can start the program immediately using the systemd service or the make run option (developer-oriented) :

# Using Systemd service
sudo systemctl start 3dprinter_error_detector.service
systemctl status 3dprinter_error_detector.service

Or

# Using Makefile
make run

Otherwise the program will run automatically the next time the raspberry pi is started.

sudo systemctl reboot # or poweroff

If you do not want this behaviour, simply disable it with this command.

sudo systemctl disable 3dprinter_error_detector.service
systemctl status 3dprinter_error_detector.service

Usage

The system is operated using the button, and the situation is indicated by a colour code on the RGB LED :

  • Blue indicates that the system is waiting for the user (paused).
  • Yellow indicates a problem. (The camera is probably not connected properly)
  • Green or Red indicates that the system is running and returns the last prediction made by the machine learning model (green = OK, red = an error has been detected).

You can refer to the diagram below to understand all the interactions:

State-transition diagram

We also provide a web interface available at this address http://<ip_raspberry>:5000/ to get image feedback from the camera (useful for positioning it), modify the trigger threshold and perform an emergency stop.

Structure

The structure of the project is as follows :

  • 3d-printer-error-detector: This folder contains all the code and the Makefile for the 3D printer error detector project.
  • ai-notebooks: This folder contains the notebooks used to train the AI model and make predictions.

3d-printer-error-detector is structured as follows:

  • api.py: This file contains the API endpoints for the web interface.
  • button_listener.py: This file handles the button events and controls the system state.
  • color.py: This file defines the color codes used by the RGB LED and the switch between them.
  • gpio_setup.py: This file sets up the GPIO pins for the components.
  • main.py: This file is the entry point of the application and starts the Flask server.
  • model_evaluation.py: This file contains functions for evaluating the machine learning model.
  • settings.py: This file contains the configuration settings for the application and the global variables for the different threads.
  • tools.py: This file contains utility functions to capture images and transform them to be used with the model.
  • model.h5: This file contains the weights and structure of the AI model.
  • templates: This folder contains the HTML templates for the web pages.
  • static: This folder contains static files such as CSS stylesheets and JavaScript files.