From a3f6275014eb9e1bf2d452066a57e94d2bde8714 Mon Sep 17 00:00:00 2001 From: LukasGro Date: Fri, 24 Nov 2023 21:09:47 +0000 Subject: [PATCH] Dateien nach "/" hochladen --- DVT_CmdHandlerClass.h | 140 ++++++++++++++++++++++++++++++++++++++++++ DVT_EncoderClass.h | 76 +++++++++++++++++++++++ DVT_MainClass.h | 53 ++++++++++++++++ DVT_Types.h | 9 +++ DVT_main.ino | 35 +++++++++++ 5 files changed, 313 insertions(+) create mode 100644 DVT_CmdHandlerClass.h create mode 100644 DVT_EncoderClass.h create mode 100644 DVT_MainClass.h create mode 100644 DVT_Types.h create mode 100644 DVT_main.ino diff --git a/DVT_CmdHandlerClass.h b/DVT_CmdHandlerClass.h new file mode 100644 index 0000000..4f3ae42 --- /dev/null +++ b/DVT_CmdHandlerClass.h @@ -0,0 +1,140 @@ +#ifndef DVT_CMDHANDLERCLASS_H +#define DVT_CMDHANDLERCLASS_H + +#include "DVT_GantryClass.h" +#include "DVT_VariacClass.h" +#include "DVT_MainClass.h" +#include "DVT_EncoderClass.h" +#include "DVT_FilamentClass.h" +#include "DVT_XRayClass.h" + +typedef struct { + String Name; + int Value; + bool unknown; + int ID; +} cmd_t; + +class CommandHandler{ + private: + String cmdList[13]; + public: + CommandHandler(String cmdList[13]){ + for (int i = 0; i < sizeof(commandList) / sizeof(*commandList); i++) { + this->cmdList[i] = commandList[i]; + } + } + void issueOrder(cmd_t cmd); + void Recognize(String cmdstr); + String GetCommandByID(int ID); + cmd_t lastCommand; +}; + +CommandHandler cmds = CommandHandler(commandList); +#endif + +void CommandHandler::issueOrder(cmd_t cmd){ + debugMSG("issueOrder"); + + switch (cmd.ID) { + case PULS: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + ENCODE.SetPos(cmd.Value); + break; + case ANGL: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + ENCODE.SetPos(cmd.Value * ENCODE.puls_per_angle); + break; + case SPCL: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + GANTRY.SetClSpeed(cmd.Value); + break; + case SPCC: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + GANTRY.SetCcSpeed(cmd.Value); + break; + case RES: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + ENCODE.Reset(); + break; + case VARF: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + break; + case VARB: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + break; + case TEST: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + sysMSG(ENCODE.GetEncoderPos()); + break; + case RXON: + XRAY.SetTime(cmd.Value); + XRAY.Signal(); + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + break; + case STFI: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + FILAMENT.SetFilamentState(cmd.Value); + break; + case RXSH: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + break; + case SCAN: + CONTROLMSG("Command : " + cmd.Name + " Value : " + String(cmd.Value)); + break; + } +} + +void CommandHandler::Recognize(String cmdstr){ + cmd_t cmdbuffer; + debugMSG("CommandRecognize"); + cmdstr.toUpperCase(); + cmdstr.replace("\n", ""); + + if (cmdstr.indexOf(';') > 0) { + cmdbuffer.Name = cmdstr.substring(0, cmdstr.indexOf(';')); + cmdbuffer.Value = cmdstr.substring(cmdstr.indexOf(';') + 1).toInt(); + } else { + cmdbuffer.Name = cmdstr; + cmdbuffer.Value = 0; + } + + for (int i = 0; i < sizeof(cmdList) / sizeof(*cmdList); i++) { + if (cmdbuffer.Name == cmdList[i]) { + cmdbuffer.unknown = false; + cmdbuffer.ID = i; + break; + } else { + cmdbuffer.unknown = true; + } + } + + this->lastCommand = cmdbuffer; + debugMSG("Command Name : " + this->lastCommand.Name); + debugMSG("Command Value : " + String(this->lastCommand.Value)); + + switch (lastCommand.unknown) { + case 0: + debugMSG("Available"); + break; + case 1: + debugMSG("Unknown Command"); + break; + }; + + debugMSG(' '); + if (this->lastCommand.unknown) { + CONTROLMSG("Available Commandlist :"); + for (int i = 0; i < sizeof(this->cmdList) / sizeof(*this->cmdList); i++) { + CONTROLMSG(this->cmdList[i]); + } + CONTROLMSG(' '); + } else { + this->issueOrder(this->lastCommand); + } + +} + +String CommandHandler::GetCommandByID(int ID){ + return this->cmdList[ID]; +} diff --git a/DVT_EncoderClass.h b/DVT_EncoderClass.h new file mode 100644 index 0000000..44d81c8 --- /dev/null +++ b/DVT_EncoderClass.h @@ -0,0 +1,76 @@ +#ifndef DVT_ENCODERCLASS_H +#define DVT_ENCODERCLASS_H + + +#include "DVT_Types.h" +#include "DVT_MainClass.h" +#include "DVT_GantryClass.h" + + +long CurEncoderPos; +long NewEncoderPos; + +void IRAM_ATTR ISREncoderSteps() { + if (NewEncoderPos > CurEncoderPos) + { + if (NewEncoderPos - 5000 <= CurEncoderPos) { + //GANTRY.SetCcSpeed(NtCcSpeedSlow); + } else { + GANTRY.SetCcSpeed(NtCcSpeed); + } + CurEncoderPos++; + } + else if (NewEncoderPos < CurEncoderPos) + { + if (NewEncoderPos + 5000 >= CurEncoderPos) { + //GANTRY.SetCcSpeed(NtClSpeedSlow); + } else { + GANTRY.SetCcSpeed(NtClSpeed); + } + CurEncoderPos--; + } + else + { + detachInterrupt(ENCODER.GetPin()); + GANTRY.Stop(); + } +} + +void IRAM_ATTR ISREncoderSwitch() { + sysMSG("ISREncoderSwitch Trigger" + String(CurEncoderPos)); + CurEncoderPos = 0; +} + +class Encoder { + public: + Encoder(long CurPos) { + CurEncoderPos = CurPos; + attachInterrupt(INDUCT_SWITCH.GetPin(), ISREncoderSwitch, RISING); + } + void SetPos(int Pos) { + GANTRY.Start(); + NewEncoderPos = Pos; + debugMSG("Pos : " + String(NewEncoderPos)); + if (CurEncoderPos > NewEncoderPos) { + GANTRY.CcRotation(); + } else { + GANTRY.ClRotation(); + } + attachInterrupt(ENCODER.GetPin(), ISREncoderSteps, RISING); + } + + int GetEncoderPos() { + debugMSG("CurEncoderPos : " + String(CurEncoderPos)); + return CurEncoderPos; + } + void Reset() { + CurEncoderPos = -1; + } + + + double puls_per_angle = 113108 / 360; +}; + +Encoder ENCODE = Encoder(0); + +#endif diff --git a/DVT_MainClass.h b/DVT_MainClass.h new file mode 100644 index 0000000..c710bef --- /dev/null +++ b/DVT_MainClass.h @@ -0,0 +1,53 @@ +#ifndef DVT_MAINCLASS_H +#define DVT_MAINCLASS_H + +#include +#include +#include "DVT_Types.h" + +class Pin { + private: + byte pin; + byte pinMODE; + DVT_State_t pinSTATE; + public: + Pin(byte pin, byte pinMODE, bool pinSTATE) { + this->pin = pin; + this->pinMODE = pinMODE; + this->pinSTATE.State = pinSTATE; + + pinMode(pin, pinMODE); + if (this->pinMODE == OUTPUT) + digitalWrite(this->pin, this->pinSTATE.State); + } + void SetState(bool pinSTATE){ + digitalWrite(this->pin, pinSTATE); + } + void SetAnalogState(int pinSTATE){ + analogWrite(this->pin,pinSTATE); + } + bool GetState() { + return this->pinSTATE.State; + } + bool ReadState(){ + return digitalRead(this->pin); + } + byte GetPin(){ + return this->pin; + } +}; + +Pin INDUCT_SWITCH = Pin(PIN_INDUCT_SWITCH,INPUT,LOW); +Pin ENCODER = Pin(PIN_ENCODER,INPUT,LOW); +Pin VARIAC_LIMIT_BACK = Pin(PIN_VARIAC_LIMIT_BACK,INPUT,LOW); +Pin VARIAC_LIMIT_FOR = Pin(PIN_VARIAC_LIMIT_FOR,INPUT,LOW); +Pin ARM_STOP = Pin(PIN_ARM_STOP,OUTPUT,LOW); +Pin ARM_SPEED = Pin(PIN_ARM_SPEED,OUTPUT,LOW); +Pin ARM_DIRECT = Pin(PIN_ARM_DIRECT,OUTPUT,HIGH); +Pin STEPMOTOR_ABLE = Pin(PIN_STEPMOTOR_ABLE,OUTPUT,HIGH); +Pin STEPMOTOR_DIRECT = Pin(PIN_STEPMOTOR_DIRECT,OUTPUT,HIGH); +Pin STEPMOTOR_CLOCK = Pin(PIN_STEPMOTOR_CLOCK,OUTPUT,HIGH); +Pin XRAY_SWITCH = Pin(PIN_XRAY,OUTPUT,LOW); +Pin FILAMENT_SWITCH = Pin(PIN_FILAMENT_SWITCH,OUTPUT,LOW); + +#endif diff --git a/DVT_Types.h b/DVT_Types.h new file mode 100644 index 0000000..a5f9c4a --- /dev/null +++ b/DVT_Types.h @@ -0,0 +1,9 @@ +#ifndef DVT_TYPES_H +#define DVT_TYPES_H + +typedef struct { + bool State; + long Time; +}DVT_State_t; + +#endif diff --git a/DVT_main.ino b/DVT_main.ino new file mode 100644 index 0000000..3c3b942 --- /dev/null +++ b/DVT_main.ino @@ -0,0 +1,35 @@ +#include "DVT_CmdHandlerClass.h" +#include "DVT_EncoderClass.h" +#include "DVT_FilamentClass.h" +#include "DVT_XRayClass.h" + +void setup() { + Serial.begin(115200); + + CONTROLMSG(' '); + CONTROLMSG("#DVT Control"); + CONTROLMSG(' '); + + +} + + +long shuffle=0; +bool Status=false; + +void TESTSignal(){ + if (millis() >= shuffle){ + Status = !Status; + digitalWrite(PIN_STEPMOTOR_DIRECT,Status); + shuffle+=10; + } +} + + +void loop() { + while (Serial.available()) { + cmds.Recognize(Serial.readString()); + } + XRAY.RunTime(); + FILAMENT.Heated(); +}