mirror of
https://github.com/anklimov/lighthub
synced 2025-12-09 13:19:50 +03:00
Service Pack 1 PID, FLOAT and TENS types compatib.
This commit is contained in:
@@ -280,6 +280,7 @@ int out_AC::Ctrl(itemCmd cmd, char* subItem , bool toExecute)
|
||||
switch(suffixCode)
|
||||
{
|
||||
case S_SET:
|
||||
case S_ESET:
|
||||
set_tmp = cmd.getInt();
|
||||
if (set_tmp >= 10 && set_tmp <= 30)
|
||||
{
|
||||
|
||||
@@ -30,13 +30,6 @@ int out_dmx::Status()
|
||||
return driverStatus;
|
||||
}
|
||||
|
||||
int out_dmx::isActive()
|
||||
{
|
||||
itemArgStore st;
|
||||
st.aslong = item->getVal(); //Restore old params
|
||||
debugSerial<< F(" val:")<<st.v<<endl;
|
||||
return st.v;
|
||||
}
|
||||
|
||||
int out_dmx::Poll(short cause)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int isActive() override;
|
||||
|
||||
int getChanType() override;
|
||||
// int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
||||
// int PixelCtrl(itemCmd cmd) override;
|
||||
|
||||
@@ -427,6 +427,7 @@ case S_NOTFOUND:
|
||||
toExecute = true;
|
||||
debugSerial<<F("Forced execution");
|
||||
case S_SET:
|
||||
case S_ESET:
|
||||
if (!cmd.isValue()) return 0;
|
||||
|
||||
//TODO
|
||||
|
||||
@@ -161,8 +161,8 @@ if (digitalPinHasPWM(pinUp))
|
||||
if (inverted) velocity = map(-dif, 0, 10, 255, 0);
|
||||
else velocity = map(-dif, 0, 10, 0, 255);
|
||||
|
||||
if (velocity>255) velocity=255;
|
||||
if (velocity<0) velocity=0;
|
||||
velocity = constrain (velocity, MIN_PWM, 255);
|
||||
|
||||
analogWrite(pinUp,velocity);
|
||||
}
|
||||
|
||||
@@ -176,8 +176,7 @@ else if (digitalPinHasPWM(pinDown))
|
||||
velocity = map(-dif, 0, 10, 0, 255);
|
||||
else velocity = map(-dif, 0, 10, 255, 0);
|
||||
|
||||
if (velocity>255) velocity=255;
|
||||
if (velocity<0) velocity=0;
|
||||
velocity = constrain (velocity, MIN_PWM, 255);
|
||||
analogWrite(pinDown,velocity);
|
||||
}
|
||||
else
|
||||
@@ -200,11 +199,11 @@ if (digitalPinHasPWM(pinDown))
|
||||
{
|
||||
//Serial.println("pinDown PWM");
|
||||
int velocity;
|
||||
if (inverted) velocity = map(dif, 0, 10, 255, 0);
|
||||
else velocity = map(dif, 0, 10, 0, 255);
|
||||
if (inverted) velocity = map(dif, 0, 20, 255, 0);
|
||||
else velocity = map(dif, 0, 20, 0, 255);
|
||||
|
||||
velocity = constrain (velocity, MIN_PWM, 255);
|
||||
|
||||
if (velocity>255) velocity=255;
|
||||
if (velocity<0) velocity=0;
|
||||
analogWrite(pinDown,velocity);
|
||||
}
|
||||
else
|
||||
@@ -268,6 +267,7 @@ case S_NOTFOUND:
|
||||
toExecute = true;
|
||||
debugSerial<<F("Forced execution");
|
||||
case S_SET:
|
||||
case S_ESET:
|
||||
if (!cmd.isValue()) return 0;
|
||||
// item->setVal(cmd.getPercents());
|
||||
if (item->getExt()) item->setExt(millisNZ()); //Extend motor time
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
#include <item.h>
|
||||
|
||||
#ifndef POS_ERR
|
||||
#define POS_ERR 2
|
||||
#define POS_ERR 5
|
||||
#endif
|
||||
|
||||
#define MIN_PWM 70
|
||||
// The number of simultaniusly working motors
|
||||
#ifndef MOTOR_QUOTE
|
||||
#define MOTOR_QUOTE 1
|
||||
|
||||
@@ -77,7 +77,8 @@ bool out_pid::getConfig()
|
||||
{store->pid= new PID (&store->input, &store->output, &store->setpoint, kP, kI, kD, direction);
|
||||
if (!store->pid) return false;
|
||||
store->pid->SetMode(AUTOMATIC);
|
||||
store->pid->SetOutputLimits(outMin,outMax);
|
||||
//store->pid->SetOutputLimits(outMin,outMax);
|
||||
store->pid->SetSampleTime(5000);
|
||||
|
||||
return true;}
|
||||
else errorSerial<<F("PID already initialized")<<endl;
|
||||
@@ -136,11 +137,11 @@ int out_pid::Poll(short cause)
|
||||
if (store && store->pid && (Status() == CST_INITIALIZED) && item && (item->getCmd()!=CMD_OFF))
|
||||
{
|
||||
double prevOut=store->output;
|
||||
store->pid->Compute();
|
||||
if (abs(store->output-prevOut)>OUTPUT_TRESHOLD)
|
||||
if(store->pid->Compute())
|
||||
//if (abs(store->output-store-prevOut)>OUTPUT_TRESHOLD)
|
||||
{
|
||||
aJsonObject * oCmd = aJson.getArrayItem(item->itemArg, 1);
|
||||
itemCmd value((float) store->output);
|
||||
itemCmd value((float) (store->output * (100./255.)));
|
||||
executeCommand(oCmd,-1,value);
|
||||
}
|
||||
|
||||
@@ -182,6 +183,7 @@ return 1;
|
||||
|
||||
case S_NOTFOUND:
|
||||
case S_SET:
|
||||
case S_ESET:
|
||||
// Setpoint for PID
|
||||
if (!cmd.isValue()) return 0;
|
||||
store->setpoint=cmd.getFloat();
|
||||
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
double output;
|
||||
double input;
|
||||
double setpoint;
|
||||
float prevOut;
|
||||
int driverStatus;
|
||||
};
|
||||
|
||||
|
||||
@@ -83,13 +83,7 @@ int out_pwm::Status()
|
||||
return driverStatus;
|
||||
}
|
||||
|
||||
int out_pwm::isActive()
|
||||
{
|
||||
itemArgStore st;
|
||||
st.aslong = item->getVal(); //Restore old params
|
||||
debugSerial<< F(" val:")<<st.v<<endl;
|
||||
return st.v;
|
||||
}
|
||||
|
||||
|
||||
int out_pwm::Poll(short cause)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int isActive() override;
|
||||
|
||||
int getChanType() override;
|
||||
//int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
||||
int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) override;
|
||||
|
||||
@@ -87,13 +87,7 @@ int out_SPILed::Status()
|
||||
return driverStatus;
|
||||
}
|
||||
|
||||
int out_SPILed::isActive()
|
||||
{
|
||||
itemArgStore st;
|
||||
st.aslong = item->getVal(); //Restore old params
|
||||
debugSerial<< F(" val:")<<st.v<<endl;
|
||||
return st.v;
|
||||
}
|
||||
|
||||
|
||||
int out_SPILed::Poll(short cause)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,6 @@ public:
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int isActive() override;
|
||||
int getChanType() override;
|
||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||
//int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
||||
|
||||
Reference in New Issue
Block a user