aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Control/PIDAlgo.c
blob: 6c1b647be87f50aa7562f9d7a0e5793c8d50bd37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "PIDAlgo.h"

float PIDAlgorithmCalculation(float _setPoint,float _mesuredParam , PID_Config_Params *params, float *_pre_error, float *_integral)
{
	float error;
	float derivative;
	float output;

	//Calculate P,I,D
	error = _setPoint - _mesuredParam;

	//In case of error too small then stop integration
	if(fabs(error) > params->epsilon)
	{
		*_integral = *_integral + error*params->dt;
	}

	derivative = (error - *_pre_error)/params->dt;

	output = params->Kp*error + params->Ki**_integral + 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;
}

float AdvancedPIDAlgorithmCalculation(float _setPoint,float _mesuredParam , PID_Config_Params *params, float *_pre_error, float *_integral)
{
    float error;
    float derivative;
    float output;

    //Calculate P,I,D
    error = _setPoint - _mesuredParam;

    //In case of error too small then stop integration
    if(fabs(error) > params->epsilon)
    {
        *_integral = *_integral + error*params->dt;
    }

    derivative = (error - *_pre_error)/params->dt;

    output = params->Kp*error/params->ProportionalErrorMultiplier + params->Ki**_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;
}

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;
}
"> void readCalibrationTables(ConversionInput* conversionInput); void SetCalibData(CalibrationData* calibrationData, int i, CalibData *tmpCurve); void SetNumberofInks(int nInks) { m_nInks = nInks; }; void SetNumberOfVolumes(int nVol) { m_nVolumes = nVol; }; void SetNumberOfInks(int nInks) { m_nInks = nInks; }; // void InitInterpolations(int numofInks, Interp *linearInterp, Interp *InvLinearInterp); void fillRGB(OutputCoordinates *outputCoords, VectorXd RGBOut); void fillLab(OutputCoordinates *outputCoords, VectorXd LabOut); void fillVolume(OutputCoordinates *&outputCoords, VectorXd Volume); void ProcessHiveNeighbors(ConversionInput *conversionInput, VectorXd LabC, VectorXd RGBC, VectorXd VolumeC, int InGamutRegion, MatrixXd &RGBOut, MatrixXd & LabOut, MatrixXd &VolumeOut, int nHive, int *&GamutRegion, int *indDataMax); void ArrangeHiveData(MatrixXd LabHive, MatrixXd RGBTmpVec, MatrixXd VolumeHive, int *GamutRegion, VectorXd xpos, VectorXd ypos, int nHive, MatrixXd &OLabHive, MatrixXd &ORGBHive, MatrixXd &OVolumeHive, int *&OGamutRegion); void FindTriplet(VectorXd Lab, MatrixXd Lab1, int nHive, int*indDataMax); int CountNumberofInks(ConversionInput* conversionInput); void VectorToDouble(VectorXd Vec, double *doub); VectorXd DoubleToVector(double *doub, int nSize); void CompareWhitePoints(); bool IsInGamut(double *InLab, SURROUND sur, CAM02CS CS, double *LabCoord); CT_Header read_header(ConversionInput* conversionInput, int &bytesread); void read_lut_type(int offset, int data_size, ColorTransf *Transf, ConversionInput* conversionInput); void read_xyz_type(int offset, int data_size, C_RGB_XYZ_Lab *xyz, ConversionInput* conversionInput); void read_text_type(int offset, int data_size, std::string *textstr, ConversionInput* conversionInput); void read_text_description_type(int offset, int data_size, std::string textdescstr, ConversionInput* conversionInput); }; } }