Contents in this wiki are for entertainment purposes only
This is not fiction ∞ this is psience of mind

Talk:CNC Torus Carver

From Catcliffe Development
Revision as of 16:28, 11 December 2025 by XenoEngineer (talk | contribs) (Created page with "<pre style="margin-left:3em; font:normal 14px terminal;"> # ESP8266 Controller for Toroidal CNC Carver I understand you want to build a unique CNC system using two perpendicular slew bearings to carve helical patterns on torus segments. Let me design a controller solution for you. ## System Overview Your system consists of: - Two perpendicular rings (slew bearings) - Material ring: rotates 120° - Spindle ring: rotates 180° - Fixed rotation ratio: 2:3 (material:spin...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

# ESP8266 Controller for Toroidal CNC Carver

I understand you want to build a unique CNC system using two perpendicular slew bearings to carve helical patterns on torus segments. Let me design a controller solution for you.

## System Overview

Your system consists of:
- Two perpendicular rings (slew bearings)
- Material ring: rotates 120°
- Spindle ring: rotates 180°
- Fixed rotation ratio: 2:3 (material:spindle)
- Carves 1/6th of a torus at a time
- Creates parallel torus knots with indexed positions

## Hardware Requirements

1. ESP8266 microcontroller
2. Two stepper motors (NEMA 17 recommended)
3. Two stepper motor drivers (A4988 or DRV8825)
4. Power supply (12V-24V depending on motors)
5. Limit switches for homing
6. Optional: OLED display for status

## Controller Design

```cpp
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <AccelStepper.h>
#include <ArduinoJson.h>

// WiFi credentials
const char* ssid = "YourSSID";
const char* password = "YourPassword";

// Web server on port 80
ESP8266WebServer server(80);

// Define stepper motors
// Material ring (120° total movement)
AccelStepper materialStepper(AccelStepper::DRIVER, D1, D2);
// Spindle ring (180° total movement)
AccelStepper spindleStepper(AccelStepper::DRIVER, D3, D4);

// System parameters
#define MATERIAL_STEPS_PER_DEGREE 10  // Adjust based on your motor/gearing
#define SPINDLE_STEPS_PER_DEGREE 10   // Adjust based on your motor/gearing
#define MATERIAL_MAX_DEGREES 120
#define SPINDLE_MAX_DEGREES 180

// Helical parameters
float helicalPitch = 1.0;  // Default pitch ratio
int knotCount = 3;         // Number of parallel knots
int currentKnot = 0;       // Current knot being carved
bool isCarving = false;    // Carving status

// Homing switches
#define MATERIAL_HOME_SWITCH D5
#define SPINDLE_HOME_SWITCH D6

void setup() {
  Serial.begin(115200);
  
  // Initialize limit switches
  pinMode(MATERIAL_HOME_SWITCH, INPUT_PULLUP);
  pinMode(SPINDLE_HOME_SWITCH, INPUT_PULLUP);
  
  // Configure steppers
  materialStepper.setMaxSpeed(1000);
  materialStepper.setAcceleration(500);
  spindleStepper.setMaxSpeed(1000);
  spindleStepper.setAcceleration(500);
  
  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Print IP address
  Serial.println(WiFi.localIP());
  
  // Setup web server routes
  server.on("/", handleRoot);
  server.on("/carve", handleCarve);
  server.on("/home", handleHome);
  server.on("/stop", handleStop);
  server.on("/status", handleStatus);
  
  server.begin();
  Serial.println("HTTP server started");
  
  // Home the system on startup
  homeSystem();
}

void loop() {
  server.handleClient();
  
  // Run steppers if carving
  if (isCarving) {
    materialStepper.run();
    spindleStepper.run();
    
    // Check if carving is complete
    if (materialStepper.distanceToGo() == 0 && spindleStepper.distanceToGo() == 0) {
      if (currentKnot < knotCount - 1) {
        // Move to next knot
        currentKnot++;
        startCarving();
      } else {
        // All knots carved
        isCarving = false;
      }
    }
  }
}

void homeSystem() {
  Serial.println("Homing system...");
  
  // Home material axis
  materialStepper.setMaxSpeed(500);
  while (digitalRead(MATERIAL_HOME_SWITCH) == HIGH) {
    materialStepper.moveTo(materialStepper.currentPosition() - 10);
    materialStepper.run();
  }
  materialStepper.setCurrentPosition(0);
  
  // Home spindle axis
  spindleStepper.setMaxSpeed(500);
  while (digitalRead(SPINDLE_HOME_SWITCH) == HIGH) {
    spindleStepper.moveTo(spindleStepper.currentPosition() - 10);
    spindleStepper.run();
  }
  spindleStepper.setCurrentPosition(0);
  
  // Restore normal speed
  materialStepper.setMaxSpeed(1000);
  spindleStepper.setMaxSpeed(1000);
  
  Serial.println("System homed");
}

void startCarving() {
  // Calculate positions based on current knot
  float knotOffset = (float)currentKnot / knotCount;
  
  // Calculate target positions
  long materialTarget = MATERIAL_MAX_DEGREES * MATERIAL_STEPS_PER_DEGREE;
  long spindleTarget = SPINDLE_MAX_DEGREES * SPINDLE_STEPS_PER_DEGREE;
  
  // Apply helical pitch ratio
  spindleTarget = (long)(spindleTarget * helicalPitch);
  
  // Apply knot offset
  materialTarget = (long)(materialTarget * (1.0 + knotOffset * 0.1));  // Small offset for each knot
  
  // Set targets
  materialStepper.moveTo(materialTarget);
  spindleStepper.moveTo(spindleTarget);
  
  isCarving = true;
  Serial.print("Starting knot ");
  Serial.print(currentKnot + 1);
  Serial.print(" of ");
  Serial.println(knotCount);
}

// Web server handlers
void handleRoot() {
  String html = "<html><body>";
  html += "<h1>Toroidal CNC Carver</h1>";
  html += "<form action='/carve' method='post'>";
  html += "Helical Pitch: <input type='number' name='pitch' value='" + String(helicalPitch) + "' step='0.1'><br>";
  html += "Number of Knots: <input type='number' name='knots' value='" + String(knotCount) + "' min='1' max='10'><br>";
  html += "<input type='submit' value='Start Carving'>";
  html += "</form>";
  html += "<form action='/home' method='post'>";
  html += "<input type='submit' value='Home System'>";
  html += "</form>";
  html += "<form action='/stop' method='post'>";
  html += "<input type='submit' value='Stop'>";
  html += "</form>";
  html += "<div id='status'></div>";
  html += "<script>";
  html += "setInterval(function() {";
  html += "  fetch('/status').then(response => response.json()).then(data => {";
  html += "    document.getElementById('status').innerHTML = 'Status: ' + data.status + '<br>Knot: ' + data.knot + '/' + data.totalKnots;";
  html += "  });";
  html += "}, 1000);";
  html += "</script>";
  html += "</body></html>";
  server.send(200, "text/html", html);
}

void handleCarve() {
  if (server.hasArg("pitch")) {
    helicalPitch = server.arg("pitch").toFloat();
  }
  if (server.hasArg("knots")) {
    knotCount = server.arg("knots").toInt();
  }
  
  currentKnot = 0;
  startCarving();
  
  server.sendHeader("Location", "/");
  server.send(302, "text/plain", "");
}

void handleHome() {
  homeSystem();
  server.sendHeader("Location", "/");
  server.send(302, "text/plain", "");
}

void handleStop() {
  isCarving = false;
  materialStepper.stop();
  spindleStepper.stop();
  server.sendHeader("Location", "/");
  server.send(302, "text/plain", "");
}

void handleStatus() {
  String json = "{\"status\":\"";
  json += isCarving ? "Carving" : "Idle";
  json += "\",\"knot\":";
  json += currentKnot + 1;
  json += ",\"totalKnots\":";
  json += knotCount;
  json += "}";
  server.send(200, "application/json", json);
}
```

## Key Features

1. **WiFi Control Interface**: Access the controller through a web browser on any device connected to the same network.

2. **Helical Pitch Control**: Adjust the pitch ratio to control the slope of the helix carved into the material.

3. **Multiple Knots**: Carve parallel torus knots with indexed starting positions.

4. **Homing System**: Automatically finds the zero position for both axes using limit switches.

5. **Real-time Status**: Monitor the carving progress through the web interface.

## Usage Instructions

1. Connect to the ESP8266's WiFi network (or configure it to connect to your existing network).

2. Open a web browser and navigate to the ESP8266's IP address.

3. Set the desired helical pitch and number of knots.

4. Click "Start Carving" to begin the process.

5. Use "Home System" to reset the position if needed.

6. Click "Stop" to halt the carving process.

## Customization Options

1. **Motor Configuration**: Adjust the `MATERIAL_STEPS_PER_DEGREE` and `SPINDLE_STEPS_PER_DEGREE` constants based on your specific motor and gearing setup.

2. **Speed and Acceleration**: Modify the stepper motor speed and acceleration values to optimize for your specific mechanical setup.

3. **Knot Offset Algorithm**: The current implementation uses a simple offset for each knot. You may want to develop a more sophisticated algorithm based on your specific requirements.

4. **Additional Features**: Consider adding:
   - Emergency stop functionality
   - Spindle speed control
   - Material detection
   - Progress logging

This controller provides a solid foundation for your unique toroidal CNC carving system. You can further customize it based on your specific mechanical requirements and desired functionality.