Skip to content

SonyCSLParis/OctoPlot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OctoPlot

Turn a 3D printer into a 2D plotter / drawing robot using OctoPrint, Sacred experiment tracking, MongoDB (GridFS), and a Dash web UI.

Make a drawing with Python or drag and drop a gcode file for CNC/Plotter

OctoPlot Interface

Adjust the Z position of the pen

Printer control

Collect videos from the printer controller

Collet data

Visualise database

database

Modify settinfs

settings


Key Capabilities (Current State)

  • Generate paths from built‑in Python examples or uploaded Python code stored in MongoDB
  • Convert paths to G-code with frame drawing & safety moves
  • Toggle between path preview and generated G-code preview
  • Printer bed size auto-sync (button fetches OctoPrint profile → updates formats.json max entry)
  • Upload & persist both G-code and Python files directly into MongoDB (no local FS dependency)
  • Create Sacred experiments only when G-code + matching timelapse pairs exist (duplicate experiments skipped)
  • Thumbnails (plot_image.png) + MP4 timelapse streaming with HTTP Range support (fast seek)
  • Fallback artifact/image retrieval from raw Mongo/GridFS when Incense loader unavailable
  • Recent experiments & DB stats panel
  • Dynamic line thickness control via env var PLOT_PATH_LINE_WIDTH (thinner default lines)
  • Frame & path scaling / auto orientation inside selected format constraints

Tech Stack

Layer Tools
UI Dash, Plotly, Dash Bootstrap Components
Backend / App Flask (inside Dash), Python 3.10+
Data / Experiments MongoDB + GridFS + Sacred + (Incense loader when present)
G-code / Path Custom utilities (utils.py), optional TextToGcode (ttgLib)
Printer Control OctoPrint REST API

Requirements

  • Python 3.10+ (3.8+ may work, project currently uses 3.10 semantics)
  • OctoPrint instance reachable (local Docker or Raspberry Pi)
  • MongoDB (local Docker compose provided)
  • (Optional) Incense for Sacred experiment artifact access (already included via git dependency in requirements.txt)
  • (Optional) TextToGcode / DrawingBot style assets for text/frame labeling

Python Dependencies

Install via:

pip install -r requirements.txt

requirements.txt already includes: dash, sacred, pymongo, numpy, matplotlib, dash-bootstrap-components, TextToGcode, tqdm, dotenv, kaleido, incense (git). No need to manually list them.


Environment Configuration

Create a .env file at project root (same dir as octoprint_dash_refactored.py). Example:

OCTOPRINT_URL=http://localhost:5055
OCTOPRINT_API_KEY=REPLACE_WITH_KEY
MONGO_URI=mongodb://admin:PASSWORD@localhost:27020/octoplot_data?authSource=admin
# Backward compatibility (either works):
MONOGO_URI=mongodb://admin:PASSWORD@localhost:27020/octoplot_data?authSource=admin
DEBUG=True

Notes:

  • Both MONGO_URI and the (typo) MONOGO_URI are accepted for resilience.
  • Set PLOT_PATH_LINE_WIDTH=0.6 (or another float) to globally thin plot strokes.
  • If using SSH tunnels: forward ports (see below) before launching.

Quick Start (Local Without Docker for Printer)

  1. Ensure OctoPrint running somewhere (Docker or Pi). Obtain API Key (Settings → API).
  2. Start MongoDB via compose (see next section) OR use an existing instance.
  3. Populate .env.
  4. (Optional) Create virtual environment:
    python -m venv .venv
    # Linux/macOS
    source .venv/bin/activate
    # Windows PowerShell
    .\.venv\Scripts\Activate.ps1
  5. Install deps: pip install -r requirements.txt
  6. Launch app:
    python octoprint_dash_refactored.py
  7. Open browser: http://localhost:8050
  8. Use Drawing page: select / upload code, generate path, toggle preview, create experiment.

Docker Services

MongoDB + Omniboard (compose)

Runs MongoDB for Sacred + (if configured) an Omniboard-like dashboard.

docker-compose -f docker-compose.mongo-omniboard.yml up -d

Cleanup / reset (e.g., to change admin password):

docker-compose -f docker-compose.mongo-omniboard.yml down
docker volume rm octoplot_mongo_data
docker-compose -f docker-compose.mongo-omniboard.yml up -d --remove-orphans

Connectivity test (adjust password):

mongosh "mongodb://admin:PASSWORD@localhost:27020/octoplot_data?authSource=admin"

OctoPrint (compose)

docker-compose -f docker-compose.octoprint.yml up -d

Then visit http://localhost:5055 for initial wizard: set bed size, camera, API key.

SSH Port Forward Example

If running remotely:

ssh -L 8055:localhost:8050 -L 5055:localhost:5000 user@REMOTE_HOST

Then open local http://localhost:8055 for the Dash UI (if app bound to 8050 on remote) and http://localhost:5055 for OctoPrint.


Core Workflows

1. Generating Paths

  • Choose a sample from test_codes/ or upload Python file → it’s stored in Mongo and appended to dropdown.
  • Execute: backend evaluates and stores X, Y, Z arrays in PlotData JSON.

2. Viewing & Toggling Preview

  • Button toggles between: Path (thin lines, hidden axes) and G-code (with printer frame if enabled).

3. Creating Experiments

  • Use Find File Matches → marks which G-code/timelapse pairs are READY.
  • Create experiment only allowed for new, complete pairs to avoid duplicates.
  • Artifacts stored: plot_image.png (thumbnail), timelapse.mp4 (streamable via Range).

4. Gallery

  • Thumbnails served from /image/png/<experiment_id>.
  • If Incense loader fails, raw Mongo fallback path streams stored PNG.
  • Clicking video icon fetches /video/mp4/<experiment_id> with partial content (seekable).

5. Bed Size Sync

  • Button calls OctoPrint profiles API → updates formats.json max format. Path scaling uses that boundary.

6. File Uploads

  • Python scripts & G-code uploaded via UI stored in uploaded_files collection (GridFS or BSON document depending on size).
  • Listed after built-in examples in dropdowns.

7. Line Thickness Control

Set before launch (example PowerShell):

$env:PLOT_PATH_LINE_WIDTH = '0.5'
python octoprint_dash_refactored.py

Formats & Scaling

formats.json defines named printable areas (e.g., A4, postcard, max). Path ingestion auto-rotates/orients to maximize scale (transpose check) and applies margin.

To add a new format manually:

{
  "A4": {"x_min":5, "x_max":205, "y_min":5, "y_max":292},
  "custom": {"x_min":10, "x_max":180, "y_min":10, "y_max":250},
  "max": {"x_min":0, "x_max":220, "y_min":0, "y_max":300}
}

Maintenance Cheatsheet

Task Command / Action
Start Mongo stack docker-compose -f docker-compose.mongo-omniboard.yml up -d
Reset Mongo (wipe) See cleanup commands above
Start OctoPrint docker-compose -f docker-compose.octoprint.yml up -d
Launch app python octoprint_dash_refactored.py
Change line width Set PLOT_PATH_LINE_WIDTH env var
Test DB connectivity mongosh connection string
Update bed size Click “Load Bed Size” button in UI
Remove duplicate experiments Automatically skipped (no manual action)

Troubleshooting

Symptom Cause Fix
“No loader” on image route Incense not available / loader failure Fallback now active; ensure image stored; reinstall incense if needed
Empty gallery thumbnail Missing plot_image.png artifact Re-run experiment creation or inspect GridFS entry
Cannot connect OctoPrint Wrong URL/API key Verify .env OCTOPRINT_URL & key, test via curl/Postman
Experiments not created Missing matching timelapse Ensure mp4 + gcode filenames align per matching rules
Thick lines Env var not set Set PLOT_PATH_LINE_WIDTH and restart
Mongo auth failure Wrong credentials / wiped volume Reset password or recreate volume (cleanup section)

Logs: run app in a terminal; enable DEBUG=True in .env for verbose output.


Roadmap / Future Ideas

  • Path simplification (Douglas–Peucker) toggle
  • Live line-width slider in UI
  • Webcam embedding from OctoPrint stream
  • Per-experiment deletion & artifact regeneration
  • Advanced pen pressure / multi-color management
  • Raspi-friendly lightweight distribution image

Developer Notes

SSH key (first-time Git):

ssh-keygen -t ed25519 -C "your_email@example.com"
cat ~/.ssh/id_ed25519.pub  # add to GitHub SSH keys

Branch workflow (example):

git clone <repo>
git checkout virtual

Virtual Environment Setup

python -m venv .venv
source .venv/bin/activate   # Linux/macOS
.# Windows PowerShell
.# .\.venv\Scripts\Activate.ps1
pip install -r requirements.txt

License

See LICENSE file.


Legacy Notes (Retained)

  • Older script octoprint_dash.py replaced by octoprint_dash_refactored.py.
  • Format management moved from Settings tab directly into Drawing page flows.

debug

  • plotly_get_chrome (environment-specific headless export issues) – consider using Kaleido (already in requirements) fully for static image export.

docker run hello-world
docker-compose -f docker-compose.octoprint.yml up -d
docker-compose -f docker-compose.mongo-omniboard.yml down
docker volume rm octoplot_mongo_data
docker-compose -f docker-compose.mongo-omniboard.yml up -d --remove-orphans

About

Web app to use 3D printer as a 2D plotter via OctoPrint

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published