Skip to content

Add runtime motor speed settings to web interface Summary #63

@FIWAtec

Description

@FIWAtec

✅ GitHub Issue: Add runtime motor speed settings to web interface
Summary

I added a feature to set the motor speeds (printSpeed and moveSpeed) at runtime from the web interface.
This makes it possible to fine-tune drawing speed without recompiling the firmware.

The feature consists of:

new input fields in index.html

a new request handler /setSpeeds in main.cpp

two global variables: printSpeedSteps and moveSpeedSteps

a new function Movement::setSpeeds()

updating both AccelStepper motors dynamically

✅ Changes in detail

  1. Global speed variables

Added to movement.cpp:

int printSpeedSteps = 1200; // default
int moveSpeedSteps = 2000; // default

These values can now be modified at runtime instead of being fixed constants.

  1. New function in Movement class

Added to movement.h:

void setSpeeds(int newPrintSpeed, int newMoveSpeed);

Implementation in movement.cpp:

void Movement::setSpeeds(int newPrintSpeed, int newMoveSpeed) {
printSpeedSteps = newPrintSpeed;
moveSpeedSteps = newMoveSpeed;

leftMotor->setMaxSpeed(moveSpeedSteps);
rightMotor->setMaxSpeed(moveSpeedSteps);

}

This allows both motors to update their speed instantly.

  1. New REST endpoint in main.cpp

Added:

server.on("/setSpeeds", HTTP_POST, [](AsyncWebServerRequest *request)
{
if (!request->hasParam("printSpeed", true) ||
!request->hasParam("moveSpeed", true)) {
request->send(400, "text/plain", "Missing parameters");
return;
}

int printSpeed = request->getParam("printSpeed", true)->value().toInt();
int moveSpeed  = request->getParam("moveSpeed", true)->value().toInt();

if (printSpeed <= 0 || moveSpeed <= 0) {
    request->send(400, "text/plain", "Invalid values");
    return;
}

movement->setSpeeds(printSpeed, moveSpeed);
request->send(200, "text/plain", "OK");

});

This receives the speed values from the browser and updates the Movement module.

  1. Web UI: two new input fields + button

Added to index.html (Distance slide):

Print speed (steps/s)

Move speed (steps/s)

Set speeds

  1. JavaScript handler in main.js

Added:

$("#setSpeeds").click(function () {
const printSpeed = parseInt($("#printSpeedInput").val());
const moveSpeed = parseInt($("#moveSpeedInput").val());

if (isNaN(printSpeed) || isNaN(moveSpeed)) {
    alert("Bitte Zahlen für beide Geschwindigkeiten eingeben.");
    return;
}

$.post("/setSpeeds", { printSpeed: printSpeed, moveSpeed: moveSpeed })
    .done(() => alert("Speeds updated"))
    .fail(() => alert("Setting speeds failed"));

});

This sends the values directly to the ESP32.

✅ Benefit

No flashing required to adjust motor speed

Users can tune drawing speed depending on:

wall surface

marker friction

belt tension

detail level of SVG

Makes the plotter more flexible and user-friendly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions