aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Control
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Control')
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Control/PIDAlgo.c48
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Control/control.c17
2 files changed, 60 insertions, 5 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/PIDAlgo.c b/Software/Embedded_SW/Embedded/Modules/Control/PIDAlgo.c
index f9aee7929..a443b4785 100644
--- a/Software/Embedded_SW/Embedded/Modules/Control/PIDAlgo.c
+++ b/Software/Embedded_SW/Embedded/Modules/Control/PIDAlgo.c
@@ -71,3 +71,51 @@ float AdvancedPIDAlgorithmCalculation(float _setPoint,float _mesuredParam , PID_
return output;
}
+float TestPIDAlgorithmCalculation(float _setPoint,float _mesuredParam , PID_Config_Params *params, float *_pre_error, float *_integral)
+{
+ float error;
+ float derivative;
+ float output;
+
+ //double error = *mySetpoint - input;
+ error = _setPoint - _mesuredParam;
+ //ITerm+= (ki * error);
+ *_integral = *_integral + (error*params->Ki);
+ /* if(ITerm > outMax)
+ {
+ ITerm= outMax;
+ }
+ else if(ITerm < outMin)
+ {
+ ITerm= outMin;
+ } */
+ if(*_integral > params->MAX)
+ {
+ *_integral = params->MAX;
+ }
+ else if(*_integral < params->MIN)
+ {
+ *_integral = params->MIN;
+ }
+ // double dInput = (input - lastInput);
+ derivative = error - *_pre_error;
+
+ /*Compute PID Output*/
+ // double output = kp * error + ITerm- kd * dInput;
+ output = params->Kp*error/params->ProportionalErrorMultiplier + *_integral/params->IntegralErrorMultiplier + params->Kd*derivative;
+
+ //Saturation Filter
+ if(output > params->MAX)
+ {
+ output = params->MAX;
+ }
+ else if(output < params->MIN)
+ {
+ output = params->MIN;
+ }
+
+ //Update error
+ *_pre_error = error;
+
+ return output;
+}
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/control.c b/Software/Embedded_SW/Embedded/Modules/Control/control.c
index 69820e306..b7521d796 100644
--- a/Software/Embedded_SW/Embedded/Modules/Control/control.c
+++ b/Software/Embedded_SW/Embedded/Modules/Control/control.c
@@ -99,7 +99,7 @@ uint32_t ControlDatalog[MAX_TANGO_CONTROL_DEVICES];
uint16_t ControlBacklog[MAX_BACKLOG_SIZE]={0};
uint16_t backlogindex = 0;
uint32_t Control_timerBase = TIMER0_BASE; //Timer handle
-uint32_t MaxHighDevices = 0;
+uint32_t MaxHighDevices = 0xFF;
/******************** Functions ********************************************/
void OneMilliSecondFunction(UArg arg0);
@@ -125,7 +125,7 @@ void ControlInit(void)
ControlRestart = false;
memset(ControlDatalog,0,sizeof(uint32_t)*MAX_TANGO_CONTROL_DEVICES);
- MaxHighDevices = 0;
+ MaxHighDevices = 0xFF;
for (Device_i = 0; Device_i < MAX_TANGO_CONTROL_DEVICES; Device_i++)
{
ControlArray[Device_i].ControlActive = false;
@@ -243,8 +243,13 @@ uint32_t AddControlCallback( ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlF
break;
}
}
- /* if ((deviceId!=0xFF )&&(deviceId> MaxHighDevices))
- // MaxHighDevices = deviceId;
+/* if (MaxHighDevices == 0xFF)
+ MaxHighDevices = deviceId;
+ else
+ {
+ if ((deviceId!=0xFF )&&(deviceId> MaxHighDevices))
+ MaxHighDevices = deviceId;
+ }
}
else
{
@@ -359,7 +364,9 @@ uint32_t GetControlLowDevice_i(void)
}
uint32_t ControlLoop(uint32_t tick)
{
- //for (ControlDevice_i = 0; ControlDevice_i < MaxHighDevices;ControlDevice_i++)
+ //if (MaxHighDevices == 0xFF)
+ // return OK;
+ //for (ControlDevice_i = 0; ControlDevice_i <= MaxHighDevices;ControlDevice_i++)
for (ControlDevice_i = 0; ControlDevice_i < MAX_TANGO_CONTROL_DEVICES;ControlDevice_i++)
{
if (ControlArray[ControlDevice_i].ControlActive)