Dateien nach "/" hochladen

This commit is contained in:
LukasGro 2023-11-24 21:09:47 +00:00
parent c2032cd261
commit a3f6275014
5 changed files with 313 additions and 0 deletions

140
DVT_CmdHandlerClass.h Normal file
View File

@ -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];
}

76
DVT_EncoderClass.h Normal file
View File

@ -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

53
DVT_MainClass.h Normal file
View File

@ -0,0 +1,53 @@
#ifndef DVT_MAINCLASS_H
#define DVT_MAINCLASS_H
#include <Arduino.h>
#include <analogWrite.h>
#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

9
DVT_Types.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef DVT_TYPES_H
#define DVT_TYPES_H
typedef struct {
bool State;
long Time;
}DVT_State_t;
#endif

35
DVT_main.ino Normal file
View File

@ -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();
}