我正在为TI C2000 Piccolo微控制器编写一系列C文件。以下是我的电池充电状态算法的示例。 构建时,Code Composer Studio报告第三行到最后一行有错误(第二行“discharge_capacity”)“#31表达式必须具有整数类型” 嗯,受我的经验限制,我无法做出更多贡献。你能提供一些帮助吗?谢谢!
#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.
}
答案 0 :(得分:2)
你正在做按位XOR,而不是取幂。
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;