Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Some problems with structure and array . . . (http://www.go4expert.com/forums/structure-array-t6899/)

boschow 17Oct2007 22:08

Some problems with structure and array . . .
 
Hi all,
i am having some problem with this part of the program written in C++ and i don't know what is wrong if you could please check it out . . .

Code:

#include <iostream>

using namespace std;
typedef struct {
    float pid_output;
    float pid_out_last;
    float error;
    float error_act;
    float error_last;
    float temp_p;
    float temp_i;
}pid_para_global;

typedef struct {
    float setpoint[4];
    float actual[4];
    float p_par[4];
    float i_par[4];
    float dead_band[4];
}pid_para;
   
float PID(pid_para_global *pid_glob, pid_para *pid_para)

    if ((pid_para->actual[0] > (pid_para->dead_band[0] + pid_para->setpoint[0]))
    || (pid_para->actual[0] < (pid_para->setpoint[0] - pid_para->dead_band[0])))
    {
      pid_glob->error_act = pid_para->setpoint - pid_para->actual;
      pid_glob->error = pid_glob->error_act - pid_glob->error_last;
    } else { pid_glob->error = 0; }
    // error_last = error;
    pid_glob->temp_p = pid_para->p_par[0] * pid_glob->error;
    pid_glob->temp_i = pid_para->p_par[0] * (pid_glob->error / pid_para->i_par[0]);
    pid_glob->pid_out_last = pid_glob->temp_p + pid_glob->temp_i;
    pid_glob->pid_output = pid_glob->pid_output + pid_glob->pid_out_last;
    if (pid_glob->pid_output < 0) pid_glob->pid_output = 0;
    if (pid_glob->pid_output > 100) pid_glob->pid_output = 100;
    return pid_glob->pid_output;
}

int main()
{
    float rezult;
    pid_para_global *pid_global_par;
    pid_para *pid_par;
    cout << "P parameter value? " << endl;
    cin >> pid_par->p_par[0];
    cout << "I parameter value? " << endl;
    cin >> pid_par->i_par[0];
    cout << "Value of deadband " << endl;
    cin >> pid_par->dead_band[0];
    cout << "Setpoint value ?" << endl;
    cin >> pid_par->setpoint[0];
    do {   
    cout << "Actual value ?" << endl;
    cin >> pid_par->actual[0];
    rezult = PID(pid_global_par, pid_par);
    cout << "Calculation rezult is " << rezult << endl << endl;
    }while (pid_par->actual[0] != 0);
}

After i insert the last value the program closes . . . and i don't know why . . . Without making structures and arrays it was working perfectly now it doesn't. Could you please check out what is wrong ?

Thanks for your time and help,
Best regards,
BoSCHoW.

shabbir 18Oct2007 10:08

Re: Some problems with structure and array . . .
 
Duplicate of Some problems with structure and array . . .. Thread closed.


All times are GMT +5.5. The time now is 15:18.