0

我正在为 TI C2000 Piccolo 微控制器编写一系列 C 文件。下面是我的电池充电状态算法的一个例子。在构建时,Code Composer Studio 报告说倒数第三行在“#31 表达式必须具有整数类型”上出现错误(第二个“discharge_capacity”)好吧,受我经验的限制,我无法贡献更多。你能提供一些帮助吗?谢谢!


#include "F2806x_Device.h"
#include "math.h"
/*Global Variables*/
//float32 SOC; // State of Charge for the entire battery pack
float32 discharge_capacity; // capacity that that has been discharged by the battery determined the curve fitting equation.

/* Inputs*/
int current = 6500; // Input battery stack current in mA.
float32 voltage = 2.5; // Input battery voltage in V. In this case this should be the average of the 27 cells voltage.

/* Assumed Constants */
int capacity = 3250; // in mAh. Minimum Nominal Capacity at 25 degrees Celcius for an    individual cell.

/* Curve Fitting Equation Parameters*/                      
float32 p1 = 3095.00;
float32 p2 = 40090.00;
float32 p3 = 191000.00;
float32 p4 = 398300.00;
float32 p5 = 310900.00;

float32 socPct;
float32 packSoc;
float32 SOC(float32 voltage, float32 current);
float32 voltage_b;
float32 current_b;
int main()
{   
float32 packSoc = SOC(voltage, current); // Average state of charge for each cell in the batter pack.
//printf(packSoc);
}

float32 SOC(float32 voltage_b, float32 current_b)
{
 /* Purpose of this code is to receive the (1) average cell voltage
  * for all 27 cells and (2) current running through all the cells,
  * and output the State of Charge for the entire battery pack.
  *
  *
  *
  *
  */
/*Curve fitting algorithm */
 float32 x = voltage_b + 0.23*((current_b-650)/3250); // Voltage is adjusted by the current.
if (x >= 4.2)
{// When voltage is at 4.2V or more, battery is at full capacity regardless of the current.
    discharge_capacity = 0.00;
}
else {
    discharge_capacity = (p5 - p1*x^4 - p2*x^3 + p3*x^2 - p4*x);  // Finds the capacity of the batteries that has been used up. ERROR FOUND HERE!!!!!!
}
socPct = 100*(capacity - discharge_capacity)/capacity;
return socPct; // Return State of Charge of a battery in percent.

}

4

1 回答 1

2

你正在做按位异或,而不是求幂。

discharge_capacity = (p5 - p1*x^4 - p2*x^3 + p3*x^2 - p4*x);

我怀疑上面的行应该是:

discharge_capacity = (p5 - p1*(x*x*x*x) - p2*(x*x*x) + p3*x*x - p4*x);

这可以更简洁地写成:

discharge_capacity = p5 - (((p1 * x - p2) * x + p3) * x - p4) * x;
于 2013-11-01T04:03:30.107 回答