Added parameters for motor config.
This commit is contained in:
@@ -21,35 +21,39 @@
|
|||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
|
||||||
// Rotational Stepper
|
// Rotational Stepper
|
||||||
#define dir1 16
|
static const int kDefaultRotDirPin = 16;
|
||||||
#define enableRotMotor 12
|
static const int kDefaultRotEnablePin = 12;
|
||||||
#define step1 26
|
static const int kDefaultRotStepPin = 26;
|
||||||
#define rotMicrostep 32
|
#define rotMicrostep 32
|
||||||
|
static const int kDefaultRotMicrostep = rotMicrostep;
|
||||||
|
|
||||||
// Pen Stepper
|
// Pen Stepper
|
||||||
#define step2 25
|
static const int kDefaultPenStepPin = 25;
|
||||||
#define dir2 27
|
static const int kDefaultPenDirPin = 27;
|
||||||
#define enablePenMotor 12
|
static const int kDefaultPenEnablePin = 12;
|
||||||
#define penMicrostep 32
|
#define penMicrostep 32
|
||||||
|
static const int kDefaultPenMicrostep = penMicrostep;
|
||||||
|
|
||||||
#define servoPin 17
|
static const int kDefaultServoPin = 17;
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Rotational Stepper
|
// Rotational Stepper
|
||||||
#define step1 2
|
static const int kDefaultRotStepPin = 2;
|
||||||
#define dir1 5
|
static const int kDefaultRotDirPin = 5;
|
||||||
#define enableRotMotor 8
|
static const int kDefaultRotEnablePin = 8;
|
||||||
#define rotMicrostep 16
|
#define rotMicrostep 16
|
||||||
|
static const int kDefaultRotMicrostep = rotMicrostep;
|
||||||
|
|
||||||
// Pen Stepper
|
// Pen Stepper
|
||||||
#define step2 3
|
static const int kDefaultPenStepPin = 3;
|
||||||
#define dir2 6
|
static const int kDefaultPenDirPin = 6;
|
||||||
#define enablePenMotor 8
|
static const int kDefaultPenEnablePin = 8;
|
||||||
#define penMicrostep 16
|
#define penMicrostep 16
|
||||||
|
static const int kDefaultPenMicrostep = penMicrostep;
|
||||||
|
|
||||||
#define servoPin 4
|
static const int kDefaultServoPin = 4;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -81,6 +85,15 @@ extern boolean g_bPrgButtonState;
|
|||||||
extern float fROT_STEP_CORRECTION;
|
extern float fROT_STEP_CORRECTION;
|
||||||
extern float fPEN_STEP_CORRECTION;
|
extern float fPEN_STEP_CORRECTION;
|
||||||
extern boolean g_bMotorsEnabled;
|
extern boolean g_bMotorsEnabled;
|
||||||
|
extern int g_iRotDirPin;
|
||||||
|
extern int g_iRotEnablePin;
|
||||||
|
extern int g_iRotStepPin;
|
||||||
|
extern int g_iPenStepPin;
|
||||||
|
extern int g_iPenDirPin;
|
||||||
|
extern int g_iPenEnablePin;
|
||||||
|
extern int g_iServoPin;
|
||||||
|
extern int g_iRotMicrostep;
|
||||||
|
extern int g_iPenMicrostep;
|
||||||
|
|
||||||
extern ConfigParameter configParameters[];
|
extern ConfigParameter configParameters[];
|
||||||
extern const size_t configParameterCount;
|
extern const size_t configParameterCount;
|
||||||
@@ -100,6 +113,7 @@ bool parseSMArgs(uint16_t *duration, int *penStepsEBB, int *rotStepsEBB);
|
|||||||
void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB);
|
void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB);
|
||||||
void storePenUpPosInEE();
|
void storePenUpPosInEE();
|
||||||
void storePenDownPosInEE();
|
void storePenDownPosInEE();
|
||||||
|
void updateStepCorrectionFactors();
|
||||||
|
|
||||||
bool initConfigStore();
|
bool initConfigStore();
|
||||||
bool loadConfigFromFile();
|
bool loadConfigFromFile();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const char *kConfigPath = "/config.json";
|
const char *kConfigPath = "/config.json";
|
||||||
|
const size_t kConfigJsonCapacity = 4096;
|
||||||
|
|
||||||
WebServer server(80);
|
WebServer server(80);
|
||||||
bool configStoreReady = false;
|
bool configStoreReady = false;
|
||||||
@@ -188,7 +189,6 @@ async function pollLogs() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(String("Config gespeichert: penUpPos=") + g_iPenUpPos + ", penDownPos=" + g_iPenDownPos);
|
|
||||||
server.send(200, "application/json", buildConfigJson());
|
server.send(200, "application/json", buildConfigJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,8 +214,17 @@ async function pollLogs() {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ConfigParameter configParameters[] = {
|
ConfigParameter configParameters[] = {
|
||||||
// {"penUpPos", &g_iPEN_UP_POS, "Pen Up Position", 5},
|
{"penUpPos", &g_iPenUpPos, "Pen Up Position", 40},
|
||||||
// {"penDownPos", &g_iPEN_DOWN_POS, "Pen Down Position", 20},
|
{"penDownPos", &g_iPenDownPos, "Pen Down Position", 10},
|
||||||
|
{"rotStepPin", &g_iRotStepPin, "Rotational Stepper Step Pin", kDefaultRotStepPin},
|
||||||
|
{"rotDirPin", &g_iRotDirPin, "Rotational Stepper Direction Pin", kDefaultRotDirPin},
|
||||||
|
{"rotEnablePin", &g_iRotEnablePin, "Rotational Stepper Enable Pin", kDefaultRotEnablePin},
|
||||||
|
{"penStepPin", &g_iPenStepPin, "Pen Stepper Step Pin", kDefaultPenStepPin},
|
||||||
|
{"penDirPin", &g_iPenDirPin, "Pen Stepper Direction Pin", kDefaultPenDirPin},
|
||||||
|
{"penEnablePin", &g_iPenEnablePin, "Pen Stepper Enable Pin", kDefaultPenEnablePin},
|
||||||
|
{"rotMicrostep", &g_iRotMicrostep, "Rotational Stepper Microsteps", kDefaultRotMicrostep},
|
||||||
|
{"penMicrostep", &g_iPenMicrostep, "Pen Stepper Microsteps", kDefaultPenMicrostep},
|
||||||
|
{"servoPin", &g_iServoPin, "Servo Pin", kDefaultServoPin},
|
||||||
};
|
};
|
||||||
|
|
||||||
const size_t configParameterCount = sizeof(configParameters) / sizeof(configParameters[0]);
|
const size_t configParameterCount = sizeof(configParameters) / sizeof(configParameters[0]);
|
||||||
@@ -242,12 +251,12 @@ bool loadConfigFromFile()
|
|||||||
return saveConfigToFile();
|
return saveConfigToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticJsonDocument<1024> doc;
|
StaticJsonDocument<kConfigJsonCapacity> doc;
|
||||||
DeserializationError err = deserializeJson(doc, file);
|
DeserializationError err = deserializeJson(doc, file);
|
||||||
file.close();
|
file.close();
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
Log("config.json ist ungueltig, defaults werden gespeichert");
|
Log(String("config.json ist ungueltig (") + err.c_str() + "), defaults werden gespeichert");
|
||||||
return saveConfigToFile();
|
return saveConfigToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,6 +282,7 @@ bool loadConfigFromFile()
|
|||||||
param->description = item["description"].as<String>();
|
param->description = item["description"].as<String>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateStepCorrectionFactors();
|
||||||
Log(String("Config geladen: penUpPos=") + g_iPenUpPos + ", penDownPos=" + g_iPenDownPos);
|
Log(String("Config geladen: penUpPos=") + g_iPenUpPos + ", penDownPos=" + g_iPenDownPos);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -287,7 +297,7 @@ bool saveConfigToFile()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticJsonDocument<1024> doc;
|
StaticJsonDocument<kConfigJsonCapacity> doc;
|
||||||
JsonArray params = doc.createNestedArray("parameters");
|
JsonArray params = doc.createNestedArray("parameters");
|
||||||
for (size_t i = 0; i < configParameterCount; ++i)
|
for (size_t i = 0; i < configParameterCount; ++i)
|
||||||
{
|
{
|
||||||
@@ -296,6 +306,12 @@ bool saveConfigToFile()
|
|||||||
item["value"] = *configParameters[i].value;
|
item["value"] = *configParameters[i].value;
|
||||||
item["description"] = configParameters[i].description;
|
item["description"] = configParameters[i].description;
|
||||||
}
|
}
|
||||||
|
if (doc.overflowed())
|
||||||
|
{
|
||||||
|
Log("Config JSON Dokument zu klein beim Speichern");
|
||||||
|
file.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool ok = serializeJsonPretty(doc, file) > 0;
|
bool ok = serializeJsonPretty(doc, file) > 0;
|
||||||
file.flush();
|
file.flush();
|
||||||
@@ -309,7 +325,7 @@ bool saveConfigToFile()
|
|||||||
|
|
||||||
String buildConfigJson()
|
String buildConfigJson()
|
||||||
{
|
{
|
||||||
StaticJsonDocument<1024> doc;
|
StaticJsonDocument<kConfigJsonCapacity> doc;
|
||||||
JsonArray params = doc.createNestedArray("parameters");
|
JsonArray params = doc.createNestedArray("parameters");
|
||||||
for (size_t i = 0; i < configParameterCount; ++i)
|
for (size_t i = 0; i < configParameterCount; ++i)
|
||||||
{
|
{
|
||||||
@@ -318,6 +334,11 @@ String buildConfigJson()
|
|||||||
item["value"] = *configParameters[i].value;
|
item["value"] = *configParameters[i].value;
|
||||||
item["description"] = configParameters[i].description;
|
item["description"] = configParameters[i].description;
|
||||||
}
|
}
|
||||||
|
if (doc.overflowed())
|
||||||
|
{
|
||||||
|
Log("Config JSON Dokument zu klein beim Lesen");
|
||||||
|
return String("{\"parameters\":[]}");
|
||||||
|
}
|
||||||
|
|
||||||
String output;
|
String output;
|
||||||
serializeJson(doc, output);
|
serializeJson(doc, output);
|
||||||
@@ -326,7 +347,7 @@ String buildConfigJson()
|
|||||||
|
|
||||||
bool applyConfigJson(const String &payload, String &errorMessage)
|
bool applyConfigJson(const String &payload, String &errorMessage)
|
||||||
{
|
{
|
||||||
StaticJsonDocument<1024> doc;
|
StaticJsonDocument<kConfigJsonCapacity> doc;
|
||||||
DeserializationError err = deserializeJson(doc, payload);
|
DeserializationError err = deserializeJson(doc, payload);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
@@ -361,6 +382,7 @@ bool applyConfigJson(const String &payload, String &errorMessage)
|
|||||||
param->description = item["description"].as<String>();
|
param->description = item["description"].as<String>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateStepCorrectionFactors();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
#include "EggDuino.h"
|
#include "EggDuino.h"
|
||||||
|
|
||||||
|
void updateStepCorrectionFactors()
|
||||||
|
{
|
||||||
|
if (g_iRotMicrostep <= 0)
|
||||||
|
{
|
||||||
|
g_iRotMicrostep = kDefaultRotMicrostep;
|
||||||
|
}
|
||||||
|
if (g_iPenMicrostep <= 0)
|
||||||
|
{
|
||||||
|
g_iPenMicrostep = kDefaultPenMicrostep;
|
||||||
|
}
|
||||||
|
fROT_STEP_CORRECTION = 16.0f / (float)g_iRotMicrostep;
|
||||||
|
fPEN_STEP_CORRECTION = 16.0f / (float)g_iPenMicrostep;
|
||||||
|
}
|
||||||
|
|
||||||
void initHardware()
|
void initHardware()
|
||||||
{
|
{
|
||||||
if (!initConfigStore())
|
if (!initConfigStore())
|
||||||
@@ -7,35 +21,36 @@ void initHardware()
|
|||||||
g_iPenUpPos = 5;
|
g_iPenUpPos = 5;
|
||||||
g_iPenDownPos = 20;
|
g_iPenDownPos = 20;
|
||||||
}
|
}
|
||||||
|
updateStepCorrectionFactors();
|
||||||
g_iPenState = g_iPenUpPos;
|
g_iPenState = g_iPenUpPos;
|
||||||
|
|
||||||
g_stepEngine.init();
|
g_stepEngine.init();
|
||||||
g_pStepperRotate = g_stepEngine.stepperConnectToPin(step1);
|
g_pStepperRotate = g_stepEngine.stepperConnectToPin(g_iRotStepPin);
|
||||||
if (g_pStepperRotate)
|
if (g_pStepperRotate)
|
||||||
{
|
{
|
||||||
// rotMotor.setMaxSpeed(2000.0);
|
// rotMotor.setMaxSpeed(2000.0);
|
||||||
// rotMotor.setAcceleration(10000.0);
|
// rotMotor.setAcceleration(10000.0);
|
||||||
|
|
||||||
g_pStepperRotate->setDirectionPin(dir1);
|
g_pStepperRotate->setDirectionPin(g_iRotDirPin);
|
||||||
g_pStepperRotate->setEnablePin(enableRotMotor);
|
g_pStepperRotate->setEnablePin(g_iRotEnablePin);
|
||||||
g_pStepperRotate->setAcceleration(10000);
|
g_pStepperRotate->setAcceleration(10000);
|
||||||
g_pStepperRotate->setAutoEnable(false);
|
g_pStepperRotate->setAutoEnable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stepper pen init
|
// Stepper pen init
|
||||||
g_pStepperPen = g_stepEngine.stepperConnectToPin(step2);
|
g_pStepperPen = g_stepEngine.stepperConnectToPin(g_iPenStepPin);
|
||||||
if (g_pStepperPen)
|
if (g_pStepperPen)
|
||||||
{
|
{
|
||||||
// penMotor.setMaxSpeed(2000.0);
|
// penMotor.setMaxSpeed(2000.0);
|
||||||
// penMotor.setAcceleration(10000.0);
|
// penMotor.setAcceleration(10000.0);
|
||||||
g_pStepperPen->setDirectionPin(dir2);
|
g_pStepperPen->setDirectionPin(g_iPenDirPin);
|
||||||
g_pStepperPen->setEnablePin(enablePenMotor);
|
g_pStepperPen->setEnablePin(g_iPenEnablePin);
|
||||||
g_pStepperPen->setAcceleration(10000);
|
g_pStepperPen->setAcceleration(10000);
|
||||||
g_pStepperPen->setAutoEnable(false);
|
g_pStepperPen->setAutoEnable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
motorsOff();
|
motorsOff();
|
||||||
penServo.attach(servoPin);
|
penServo.attach(g_iServoPin);
|
||||||
penServo.write(g_iPenState);
|
penServo.write(g_iPenState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +138,6 @@ void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB)
|
|||||||
motorsOn();
|
motorsOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((1 == fROT_STEP_CORRECTION) && (1 == fPEN_STEP_CORRECTION))
|
if ((1 == fROT_STEP_CORRECTION) && (1 == fPEN_STEP_CORRECTION))
|
||||||
{ // if coordinatessystems are identical
|
{ // if coordinatessystems are identical
|
||||||
// set Coordinates and Speed
|
// set Coordinates and Speed
|
||||||
@@ -163,12 +177,14 @@ void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB)
|
|||||||
|
|
||||||
void moveOneStep()
|
void moveOneStep()
|
||||||
{
|
{
|
||||||
while (g_pStepperPen->isRunning() || g_pStepperRotate->isRunning());
|
while (g_pStepperPen->isRunning() || g_pStepperRotate->isRunning())
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveToDestination()
|
void moveToDestination()
|
||||||
{
|
{
|
||||||
while (g_pStepperPen->isRunning() || g_pStepperRotate->isRunning());
|
while (g_pStepperPen->isRunning() || g_pStepperRotate->isRunning())
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setprgButtonState()
|
void setprgButtonState()
|
||||||
|
|||||||
15
src/main.cpp
15
src/main.cpp
@@ -59,9 +59,18 @@ int g_iPenState = g_iPenUpPos;
|
|||||||
uint32_t g_uiNodeCount = 0;
|
uint32_t g_uiNodeCount = 0;
|
||||||
unsigned int g_uiLayer = 0;
|
unsigned int g_uiLayer = 0;
|
||||||
boolean g_bPrgButtonState = 0;
|
boolean g_bPrgButtonState = 0;
|
||||||
float fROT_STEP_CORRECTION = 16.0 / rotMicrostep; // devide EBB-Coordinates by this factor to get EGGduino-Steps
|
|
||||||
float fPEN_STEP_CORRECTION = 16.0 / penMicrostep; // devide EBB-Coordinates by this factor to get EGGduino-Steps
|
|
||||||
boolean g_bMotorsEnabled = 0;
|
boolean g_bMotorsEnabled = 0;
|
||||||
|
int g_iRotDirPin = kDefaultRotDirPin;
|
||||||
|
int g_iRotEnablePin = kDefaultRotEnablePin;
|
||||||
|
int g_iRotStepPin = kDefaultRotStepPin;
|
||||||
|
int g_iPenStepPin = kDefaultPenStepPin;
|
||||||
|
int g_iPenDirPin = kDefaultPenDirPin;
|
||||||
|
int g_iPenEnablePin = kDefaultPenEnablePin;
|
||||||
|
int g_iServoPin = kDefaultServoPin;
|
||||||
|
int g_iRotMicrostep = kDefaultRotMicrostep;
|
||||||
|
int g_iPenMicrostep = kDefaultPenMicrostep;
|
||||||
|
float fROT_STEP_CORRECTION = 16.0 / kDefaultRotMicrostep; // devide EBB-Coordinates by this factor to get EGGduino-Steps
|
||||||
|
float fPEN_STEP_CORRECTION = 16.0 / kDefaultPenMicrostep; // devide EBB-Coordinates by this factor to get EGGduino-Steps
|
||||||
|
|
||||||
// Stepper Test
|
// Stepper Test
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
@@ -75,9 +84,9 @@ void setup()
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Starting...");
|
Serial.println("Starting...");
|
||||||
Log("Starting...");
|
Log("Starting...");
|
||||||
|
startWebInterface();
|
||||||
makeComInterface();
|
makeComInterface();
|
||||||
initHardware();
|
initHardware();
|
||||||
startWebInterface();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t g_uiState = 0;
|
uint8_t g_uiState = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user