问题描述
我是 arduino 的新手,我正在尝试制作一个程序来计算电池中剩余电量的百分比,使用库仑计数法(在带有公式的图片下方)。是否可以从 arduino 执行这种类型的计算?
解决方法
1.) 模型
假设 CBat 是电池的容量并且是常数(物理学家更喜欢用字母 Q 表示电荷;CBat 可能会随着老化而减少,“健康状况”)
按定义:
SOC(t) = Q(t)/CBat
微分方程:
dQ/dt = I(t)
近似值:“dt=1”
Q(t)-Q(t-1) ~= I(t)
或
SOC(t) ~= SOC(t-1) + I(t)/Cbat
2.) 阿杜尼奥: 以下为纯虚拟脚本,在线编译不服务。
// Assume current coming from serial port
const float C_per_Ah = 3600;
// signal adjustment
const float current_scale_A = 0.1; // Ampere per serial step
const int current_offset = 128; // Offset of serial value for I=0A
float CBat_Ah = 94; /* Assumed Battery Capacity in Ah */
float Cbat_C = CBat_Ah * C_per_Ah; /* ... in Coulomb */
float SOC = 0.7; /* Initial State of Charge */
int incomingByte = current_offset; // for incoming serial data,initial 0 Ampere
float I = 0; /* current */
// the setup routine runs once when you press reset:
void setup()
{
Serial.begin(9600); // opens serial port,sets data rate to 9600 bps
}
// the loop routine runs over and over again forever:
void loop()
{
delay(1000); // wait for a second
if (Serial.available() > 0)
{
// read the incoming byte:
incomingByte = Serial.read();
}
I = (incomingByte-current_offset) * current_scale_A;
SOC = SOC + I/Cbat_C;
Serial.print("New SOC: ");
Serial.println(SOC,4);
}