I am trying to implement a function called void gradual_change(). This function will take two parameters (double) and and will assign them to two local variable called inner_previous_value and inner_current_value I am trying to step the value from previous to current but when I implement them my code goes crazy and don't knnow how to fix it
HERE IS MY CODE:
void gradual_change(double p, double c)
{
double convert_coeff = 1000 * (7.31 - 2.048) / (16383 * 33.1);
double ramping_return;
double inner_previous_value = p;
qDebug() << "Inner Previous Value: " << inner_previous_value;
double inner_current_value = c;
qDebug() << " Inner Current Value: " << inner_current_value;
double inner_difference = abs(inner_current_value - inner_previous_value);
qDebug() << "Inner Difference: " << inner_difference;
double ramping_scale = (16383-100 / convert_coeff);
qDebug() << "Ramping Scale: " << ramping_scale;
// If the values are not equal write different current (inner_current_value)
if(inner_previous_value != inner_current_value)
{ // Here, we check if we need to ramp. if the value of the inner_previous_value is less than the ramping_scale
// we simply make the previous value into the current value.
if(inner_difference < ramping_scale)
{
inner_previous_value = inner_current_value;
qDebug() << "CASE 1 - the previous current have been updated from " << p << "To " << inner_previous_value;
}
// Here, we create two possible cases when ramping up or ramping down.
else
{
if((inner_previous_value < inner_current_value) && ((inner_previous_value!=ramping_scale)||inner_previous_value==ramping_scale))
{
qDebug() << "CASE 2 - RAMPING UP";
for(inner_previous_value; inner_previous_value < inner_current_value;)
{
inner_previous_value=inner_previous_value-inner_current_value;
//qDebug() << inner_previous_value;
if(inner_previous_value == inner_current_value)
{
qDebug() << "IN CASE 2 - ramping up - INNER PREVIOUS VALUE IS: " << inner_previous_value;
break;
}
}
}
else //if(inner_previous_value > inner_current_value)
{
qDebug() << "Case 3 - Ramping Down";
for(inner_previous_value; inner_previous_value > inner_current_value;)
{
inner_previous_value = inner_previous_value - inner_current_value;
if(inner_previous_value==inner_current_value)
{
break;
}
}
}
}
}
ramping_return = inner_previous_value;
qDebug() << "RAMPING RETURN: " << ramping_return;
}
int main(int argc, char *argv[])
{`enter code here`
QCoreApplication a(argc, argv);
while(1){
cout << "Enter P, and C: " << endl;
double p, c;
cin >> p >> c;
gradual_change(p,c);
}
return a.exec();
}
hope somebody could help me
Aucun commentaire:
Enregistrer un commentaire