分布式电动汽车驱动防滑控制C代码
时间: 2024-05-10 20:21:32 浏览: 88
抱死判断
```
int slip = 0; // 是否抱死,0表示未抱死,1表示已抱死
double wheelSpeed[4] = {0}; // 四个车轮的速度
double wheelTorque[4] = {0}; // 四个车轮的扭矩
double wheelRpm[4] = {0}; // 四个车轮的转速
double wheelSlip[4] = {0}; // 四个车轮的滑动率
double wheelPower[4] = {0}; // 四个车轮的功率
double wheelEnergy[4] = {0}; // 四个车轮的能量
double brakeTorque[4] = {0}; // 四个车轮的制动扭矩
double regenTorque[4] = {0}; // 四个车轮的再生制动扭矩
// 计算四个车轮的速度、扭矩、转速、滑动率、功率和能量
for (int i = 0; i < 4; i++) {
wheelSpeed[i] = vehicleSpeed * gearRatio[i] * finalDriveRatio[i] * tireRadius[i];
wheelTorque[i] = motorTorque[i] * gearRatio[i] * finalDriveRatio[i] * efficiency[i];
wheelRpm[i] = wheelSpeed[i] / (tireRadius[i] * 2 * PI) * 60;
wheelSlip[i] = (wheelRpm[i] - motorRpm[i]) / wheelRpm[i];
wheelPower[i] = wheelTorque[i] * wheelSpeed[i];
wheelEnergy[i] = wheelPower[i] * deltaT;
}
// 判断是否抱死
for (int i = 0; i < 4; i++) {
if (wheelSpeed[i] == 0 && motorTorque[i] > 0) {
slip = 1;
break;
}
if (wheelSpeed[i] > 0 && motorTorque[i] < 0) {
slip = 1;
break;
}
if (wheelSlip[i] > 1) {
slip = 1;
break;
}
}
// 如果抱死,施加制动扭矩,否则施加电机扭矩
if (slip == 1) {
for (int i = 0; i < 4; i++) {
brakeTorque[i] = brakeForce[i] * tireRadius[i];
}
// 控制制动力分配,实现防侧滑
} else {
for (int i = 0; i < 4; i++) {
regenTorque[i] = regenForce[i] * tireRadius[i];
motorTorque[i] = motorTorque[i] - regenTorque[i];
}
}
```
制动力分配
```
double brakeTorque[4] = {0}; // 四个车轮的制动扭矩
double brakeForce[4] = {0}; // 四个车轮的制动力
double brakeEnergy[4] = {0}; // 四个车轮的制动能量
double brakeEnergySum = 0; // 制动能量总和
double brakeForceSum = 0; // 制动力总和
double brakeForceRatio[4] = {0}; // 四个车轮的制动力分配比例
// 计算制动扭矩、制动力和制动能量
for (int i = 0; i < 4; i++) {
brakeTorque[i] = brakeForce[i] * tireRadius[i];
brakeEnergy[i] = brakeForce[i] * wheelSpeed[i] * deltaT;
brakeEnergySum += brakeEnergy[i];
brakeForceSum += brakeForce[i];
}
// 计算制动力分配比例
for (int i = 0; i < 4; i++) {
brakeForceRatio[i] = brakeEnergy[i] / brakeEnergySum;
}
// 控制制动力分配,实现防侧滑
for (int i = 0; i < 4; i++) {
motorTorque[i] = motorTorque[i] - regenTorque[i] + brakeTorque[i] * brakeForceRatio[i];
}
```
阅读全文