增加转向扭矩控制

This commit is contained in:
2025-07-08 21:07:11 +08:00
parent 1b9b848949
commit eefa6daf38
4 changed files with 1673 additions and 1560 deletions

View File

@@ -19,6 +19,43 @@ DiffData diff_data;
PID_t speed_pid; PID_t speed_pid;
PID_t yaw_rate_pid; PID_t yaw_rate_pid;
/**
* @brief 根据挡位和输入转矩计算输出转矩值
* @param gear 挡位状态STATE_FORWARD/STATE_BACKWARD/其他)
* @param input_torque 输入转矩值
* @return 处理后的转矩值(已包含偏移量和系数)
*/
float calculateTorqueOutput(uint8_t gear, float input_torque)
{
const float OFFSET = 300.0f; // 偏移量常量
const float SCALE_FACTOR = 100.0f; // 缩放系数
const float DEFAULT_VALUE = 30000.0f; // 默认输出值
float output_torque;
if (gear == STATE_FORWARD)
{
output_torque = (input_torque + OFFSET) * SCALE_FACTOR;
}
else if (gear == STATE_BACKWARD)
{
output_torque = (-input_torque + OFFSET) * SCALE_FACTOR;
}
else
{
output_torque = DEFAULT_VALUE;
}
return output_torque;
}
// 设置电机输出 // 设置电机输出
void setMotorOutput(float *out_torq, float max_torque, uint16_t feed_power, uint16_t discharge_power) void setMotorOutput(float *out_torq, float max_torque, uint16_t feed_power, uint16_t discharge_power)
{ {
@@ -29,33 +66,52 @@ void setMotorOutput(float *out_torq, float max_torque, uint16_t feed_power, uint
float abs_right_rear_speed = 0; float abs_right_rear_speed = 0;
// 档位 // 档位
un_motor_output1.bit_data.gear = diff_data.state; // 1 表示前进2 表示后退0空挡 if(diff_data.state != STATE_STATIC_TURN)
un_motor_output2.bit_data.gear = diff_data.state; {
un_motor_output3.bit_data.gear = diff_data.state; un_motor_output1.bit_data.gear = diff_data.state; // 1 表示前进2 表示后退0空挡
un_motor_output4.bit_data.gear = diff_data.state; un_motor_output2.bit_data.gear = diff_data.state;
un_motor_output3.bit_data.gear = diff_data.state; // 1 表示前进2 表示后退0空挡
un_motor_output4.bit_data.gear = diff_data.state;
}
else//原地转向状态的话,根据扭矩大小确定方向
{
un_motor_output1.bit_data.gear = (out_torq[0] < 0) ? STATE_BACKWARD : STATE_FORWARD;
un_motor_output2.bit_data.gear = (out_torq[1] < 0) ? STATE_BACKWARD : STATE_FORWARD;
un_motor_output3.bit_data.gear = (out_torq[2] < 0) ? STATE_BACKWARD : STATE_FORWARD;
un_motor_output4.bit_data.gear = (out_torq[3] < 0) ? STATE_BACKWARD : STATE_FORWARD;
}
//增加系数以及偏移量 abs_left_front_speed = calculateTorqueOutput(un_motor_output1.bit_data.gear, out_torq[0]); //根据挡位增加转矩方向
if(diff_data.state == STATE_FORWARD)//根据挡位来判断,扭矩的正负 abs_right_front_speed = calculateTorqueOutput(un_motor_output2.bit_data.gear, out_torq[1]);
abs_left_rear_speed = calculateTorqueOutput(un_motor_output3.bit_data.gear, out_torq[2]);
abs_right_rear_speed = calculateTorqueOutput(un_motor_output4.bit_data.gear, out_torq[3]);
if(STATE_FORWARD == un_motor_output3.bit_data.gear)//把后两台电机反相
{ {
abs_left_front_speed = (out_torq[0] + 300.0f) *100.0f; un_motor_output3.bit_data.gear = STATE_BACKWARD;
abs_right_front_speed = (out_torq[1] + 300.0f) *100.0f;
abs_left_rear_speed = (out_torq[2] + 300.0f) *100.0f;
abs_right_rear_speed = (out_torq[3] + 300.0f) *100.0f;
} }
else if(diff_data.state == STATE_BACKWARD)//倒挡直接修改为负扭矩发送出去 else if(STATE_BACKWARD == un_motor_output3.bit_data.gear)
{ {
abs_left_front_speed = (-out_torq[0] + 300.0f) *100.0f; un_motor_output3.bit_data.gear = STATE_FORWARD;
abs_right_front_speed = (-out_torq[1] + 300.0f) *100.0f;
abs_left_rear_speed = (-out_torq[2] + 300.0f) *100.0f;
abs_right_rear_speed = (-out_torq[3] + 300.0f) *100.0f;
} }
else//空挡直接发0 else
{ {
abs_left_front_speed = 0; un_motor_output3.bit_data.gear = STATE_INIT;
abs_right_front_speed = 0; }
abs_left_rear_speed = 0;
abs_right_rear_speed = 0; if(STATE_FORWARD == un_motor_output4.bit_data.gear)
{
un_motor_output4.bit_data.gear = STATE_BACKWARD;
}
else if(STATE_BACKWARD == un_motor_output4.bit_data.gear)
{
un_motor_output4.bit_data.gear = STATE_FORWARD;
}
else
{
un_motor_output4.bit_data.gear = STATE_INIT;
} }
@@ -69,12 +125,17 @@ void setMotorOutput(float *out_torq, float max_torque, uint16_t feed_power, uint
un_motor_output3.bit_data.mode = MOTOR_MODE; un_motor_output3.bit_data.mode = MOTOR_MODE;
un_motor_output4.bit_data.mode = MOTOR_MODE; un_motor_output4.bit_data.mode = MOTOR_MODE;
// 设置最大扭矩 // 设置扭矩
un_motor_output1.bit_data.set_torque = (uint16_t)( (int16_t)abs_left_front_speed ); un_motor_output1.bit_data.set_torque = (uint16_t)( (int16_t)abs_left_front_speed );
un_motor_output2.bit_data.set_torque = (uint16_t)( (int16_t)abs_right_front_speed ); un_motor_output2.bit_data.set_torque = (uint16_t)( (int16_t)abs_right_front_speed );
un_motor_output3.bit_data.set_torque = (uint16_t)( (int16_t)abs_left_rear_speed ); un_motor_output3.bit_data.set_torque = (uint16_t)( (int16_t)abs_left_rear_speed );
un_motor_output4.bit_data.set_torque = (uint16_t)( (int16_t)abs_right_rear_speed ); un_motor_output4.bit_data.set_torque = (uint16_t)( (int16_t)abs_right_rear_speed );
//设定转速
un_motor_output1.bit_data.set_rotation_speed = 30000;
un_motor_output2.bit_data.set_rotation_speed = 30000;
un_motor_output3.bit_data.set_rotation_speed = 30000;
un_motor_output4.bit_data.set_rotation_speed = 30000;
// 设置馈电功率 // 设置馈电功率
un_motor_output1.bit_data.feed_power = feed_power; un_motor_output1.bit_data.feed_power = feed_power;
@@ -326,7 +387,6 @@ void computeInverseKinematics(float linear_velocity_x, float yaw_rate, float max
linear_velocity_x = constrain(linear_velocity_x, -max_torque, max_torque); linear_velocity_x = constrain(linear_velocity_x, -max_torque, max_torque);
yaw_rate = constrain(yaw_rate, -2*max_torque, 2*max_torque); yaw_rate = constrain(yaw_rate, -2*max_torque, 2*max_torque);
float left_speed_mps = linear_velocity_x + yaw_rate; float left_speed_mps = linear_velocity_x + yaw_rate;
float right_speed_mps = linear_velocity_x - yaw_rate; float right_speed_mps = linear_velocity_x - yaw_rate;
@@ -361,9 +421,9 @@ void computeInverseKinematics(float linear_velocity_x, float yaw_rate, float max
motor_speed[1] = right_speed_mps; motor_speed[1] = right_speed_mps;
motor_speed[3] = right_speed_mps; motor_speed[3] = right_speed_mps;
adjust_torque_by_speed_diff( diff_data.left_front_motor_speed,diff_data.left_rear_motor_speed, &motor_speed[0], &motor_speed[2],100, 5); // adjust_torque_by_speed_diff( diff_data.left_front_motor_speed,diff_data.left_rear_motor_speed, &motor_speed[0], &motor_speed[2],100, 5);
adjust_torque_by_speed_diff( diff_data.right_front_motor_speed,diff_data.right_rear_motor_speed, &motor_speed[1], &motor_speed[3],100, 5); // adjust_torque_by_speed_diff( diff_data.right_front_motor_speed,diff_data.right_rear_motor_speed, &motor_speed[1], &motor_speed[3],100, 5);
//
// printf("speed: FL=%.1f FR=%.1f RL=%.1f RR=%.1f\n", diff_data.left_front_motor_speed, diff_data.right_front_motor_speed, diff_data.left_rear_motor_speed, diff_data.right_rear_motor_speed); // printf("speed: FL=%.1f FR=%.1f RL=%.1f RR=%.1f\n", diff_data.left_front_motor_speed, diff_data.right_front_motor_speed, diff_data.left_rear_motor_speed, diff_data.right_rear_motor_speed);
@@ -491,6 +551,10 @@ void handleVehicleState(DiffData *ctx)
{ {
ctx->state = STATE_BACKWARD; ctx->state = STATE_BACKWARD;
} }
else if( (ctx->desired_speed == 0.0f) && (ctx->desired_curvature != 0) )//无速度有转向
{
ctx->state = STATE_STATIC_TURN;
}
else else
{ {
ctx->state = STATE_FORWARD; ctx->state = STATE_FORWARD;
@@ -503,15 +567,19 @@ void handleVehicleState(DiffData *ctx)
//------------------------------------------- //-------------------------------------------
case STATE_FORWARD: case STATE_FORWARD:
{ {
if ((ctx->desired_speed < 0.0f) && (ctx->speed == 0.0f)) if( (ctx->desired_speed < 0.0f) && (ctx->speed == 0.0f) )
{ {
ctx->state = STATE_BACKWARD; // 零速时允许切换方向 ctx->state = STATE_BACKWARD; // 零速时允许切换方向
} }
else if ((ctx->desired_speed < 0.0f) && (ctx->speed != 0.0f)) else if( (ctx->desired_speed < 0.0f) && (ctx->speed != 0.0f) )
{ {
ctx->desired_speed = 0.0f; // 非零速时清空期望速度 ctx->desired_speed = 0.0f; // 非零速时清空期望速度
ctx->state = STATE_FORWARD; // 显式保持当前状态 ctx->state = STATE_FORWARD; // 显式保持当前状态
} }
else if( (ctx->desired_speed == 0.0f) && (ctx->speed == 0.0f) && (ctx->desired_curvature != 0.0f) )
{
ctx->state = STATE_STATIC_TURN; // 原地转向
}
else else
{ {
ctx->state = STATE_FORWARD; // 新增:其他情况保持前进状态 ctx->state = STATE_FORWARD; // 新增:其他情况保持前进状态
@@ -533,12 +601,38 @@ void handleVehicleState(DiffData *ctx)
ctx->desired_speed = 0.0f; // 非零速时清空期望速度 ctx->desired_speed = 0.0f; // 非零速时清空期望速度
ctx->state = STATE_BACKWARD; // 显式保持当前状态 ctx->state = STATE_BACKWARD; // 显式保持当前状态
} }
else if( (ctx->desired_speed == 0.0f) && (ctx->speed == 0.0f) && (ctx->desired_curvature != 0.0f) )
{
ctx->state = STATE_STATIC_TURN; // 原地转向
}
else else
{ {
ctx->state = STATE_BACKWARD; // 新增:其他情况保持倒车状态 ctx->state = STATE_BACKWARD; // 新增:其他情况保持倒车状态
} }
break; break;
} }
//-------------------------------------------
// 原地转向状态
//-------------------------------------------
case STATE_STATIC_TURN:
{
if ((ctx->desired_speed > 0.0f) && (ctx->speed == 0.0f))
{
ctx->state = STATE_FORWARD; // 零速时允许切换方向
}
else if ((ctx->desired_speed < 0.0f) && (ctx->speed == 0.0f))
{
ctx->state = STATE_BACKWARD; // 显式保持当前状态
}
else
{
ctx->state = STATE_STATIC_TURN; // 原地转向
}
break;
}
default:;
} }
} }
@@ -580,6 +674,8 @@ static void diffProcess(void *signal_id)
float output_speed = calculatePidOutput(&speed_pid, diff_data.desired_speed, diff_data.speed, 0.0f, dt); float output_speed = calculatePidOutput(&speed_pid, diff_data.desired_speed, diff_data.speed, 0.0f, dt);
float output_yaw_rate = calculatePidOutput(&yaw_rate_pid, diff_data.desired_yaw_rate, diff_data.yaw_rate, 0.0f, dt); float output_yaw_rate = calculatePidOutput(&yaw_rate_pid, diff_data.desired_yaw_rate, diff_data.yaw_rate, 0.0f, dt);
// 计算最大加速度,用函数计算 // 计算最大加速度,用函数计算
float max_acceleration = calculateMaxAcceleration(); float max_acceleration = calculateMaxAcceleration();
// 限制输出速度在当前速度和最大加速度计算出来的速度之间 // 限制输出速度在当前速度和最大加速度计算出来的速度之间
@@ -707,6 +803,8 @@ static void diffInput(void *signal_id)
diff_data.desired_speed = mapRemoteControlSpeed(diff_data.desired_speed, 0.1, 20, 5, 5, 0.5); diff_data.desired_speed = mapRemoteControlSpeed(diff_data.desired_speed, 0.1, 20, 5, 5, 0.5);
diff_data.desired_curvature = mapRemoteControlSpeed(diff_data.desired_curvature, 0.1, 2, 2, 1, 0.5); diff_data.desired_curvature = mapRemoteControlSpeed(diff_data.desired_curvature, 0.1, 2, 2, 1, 0.5);
diff_data.desired_curvature = -diff_data.desired_curvature;
if(diff_data.desired_speed >= 0)//20250320 增加根据速度大小来决定方向,解决后退时转弯反向的问题 if(diff_data.desired_speed >= 0)//20250320 增加根据速度大小来决定方向,解决后退时转弯反向的问题
{ {
diff_data.desired_curvature = diff_data.desired_curvature; diff_data.desired_curvature = diff_data.desired_curvature;
@@ -743,6 +841,9 @@ static void diffInput(void *signal_id)
{ {
diff_data.left_front_motor_speed = (float)((int16_t)(un_motor_input1.bit_data.speed - 30000));//20240921 增加偏移量 diff_data.left_front_motor_speed = (float)((int16_t)(un_motor_input1.bit_data.speed - 30000));//20240921 增加偏移量
diff_data.left_rear_motor_speed = (float)((int16_t)(un_motor_input3.bit_data.speed - 30000));//20240921 增加偏移量 diff_data.left_rear_motor_speed = (float)((int16_t)(un_motor_input3.bit_data.speed - 30000));//20240921 增加偏移量
diff_data.left_rear_motor_speed = - diff_data.left_rear_motor_speed;//20250708 增加反相
if(fabs(diff_data.left_rear_motor_speed) > fabs(diff_data.left_front_motor_speed))//取速度较小的轮速 if(fabs(diff_data.left_rear_motor_speed) > fabs(diff_data.left_front_motor_speed))//取速度较小的轮速
{ {
@@ -759,6 +860,8 @@ static void diffInput(void *signal_id)
diff_data.right_front_motor_speed = (float)((int16_t)(un_motor_input2.bit_data.speed - 30000)); // 20250502 1号控制器增加反相 diff_data.right_front_motor_speed = (float)((int16_t)(un_motor_input2.bit_data.speed - 30000)); // 20250502 1号控制器增加反相
diff_data.right_rear_motor_speed = (float)((int16_t)(un_motor_input4.bit_data.speed - 30000)); diff_data.right_rear_motor_speed = (float)((int16_t)(un_motor_input4.bit_data.speed - 30000));
diff_data.right_rear_motor_speed = - diff_data.right_rear_motor_speed;//20250708 增加反相
if(fabs(diff_data.right_front_motor_speed) > fabs(diff_data.right_rear_motor_speed))//取速度较小的轮速 if(fabs(diff_data.right_front_motor_speed) > fabs(diff_data.right_rear_motor_speed))//取速度较小的轮速
{ {
motor_speed_temp = diff_data.right_rear_motor_speed; motor_speed_temp = diff_data.right_rear_motor_speed;
@@ -787,18 +890,18 @@ static void diffInput(void *signal_id)
diff_data.desired_curvature = 0.0; diff_data.desired_curvature = 0.0;
} }
if (diff_data.emergency_stop_state == 1)//刹车 20241017 增加的扭矩限制 // if (diff_data.emergency_stop_state == 1)//刹车 20241017 增加的扭矩限制
{ // {
diff_data.max_Torq = 5;//20240403修改。刹车就是5N // diff_data.max_Torq = 5;//20240403修改。刹车就是5N
} // }
else if ((0 == diff_data.desired_speed) && (0 == diff_data.desired_curvature) && (diff_data.left_motor_speed > -100) && (diff_data.left_motor_speed < 100)&& (((diff_data.right_motor_speed > -100) && (diff_data.right_motor_speed < 100))))//20240330只有当手柄回中然后当前已经停止的状态才设置为最小停车扭矩 // else if ((0 == diff_data.desired_speed) && (0 == diff_data.desired_curvature) && (diff_data.left_motor_speed > -100) && (diff_data.left_motor_speed < 100)&& (((diff_data.right_motor_speed > -100) && (diff_data.right_motor_speed < 100))))//20240330只有当手柄回中然后当前已经停止的状态才设置为最小停车扭矩
{ // {
diff_data.max_Torq = 5;//停车 就为0 20250425 修改为5解决手柄回中震荡问题 // diff_data.max_Torq = 5;//停车 就为0 20250425 修改为5解决手柄回中震荡问题
} // }
else // else
{ // {
diff_data.max_Torq = (uint16_t)getParam("maxTorq");//参数读取设定最大扭矩 // diff_data.max_Torq = (uint16_t)getParam("maxTorq");//参数读取设定最大扭矩
} // }
diffProcess(&diff_data);//计算左右电机期望转速 diffProcess(&diff_data);//计算左右电机期望转速
} }
@@ -814,8 +917,11 @@ void preChargeFinish(void *signal_id)
setMotorOutput(out_torq, (uint16_t)getParam("maxTorq"), (uint16_t)getParam("feedPwr"), (uint16_t)getParam("dispPwr")); setMotorOutput(out_torq, (uint16_t)getParam("maxTorq"), (uint16_t)getParam("feedPwr"), (uint16_t)getParam("dispPwr"));
// 档位 // 档位
// un_motor_output1.bit_data.gear = 0; // 0表示空挡 un_motor_output1.bit_data.gear = 0; // 0表示空挡
// un_motor_output2.bit_data.gear = 0; un_motor_output2.bit_data.gear = 0;
un_motor_output3.bit_data.gear = 0; // 0表示空挡
un_motor_output4.bit_data.gear = 0;
publishMessage(&un_motor_output1, 1); publishMessage(&un_motor_output1, 1);
publishMessage(&un_motor_output2, 1); publishMessage(&un_motor_output2, 1);
publishMessage(&un_motor_output3, 1); publishMessage(&un_motor_output3, 1);
@@ -866,15 +972,14 @@ void diffParametersInit(void *signal_id)
diff_data.min_Torq = (uint16_t)getParam("minTorq");//参数读取设定最大扭矩 diff_data.min_Torq = (uint16_t)getParam("minTorq");//参数读取设定最大扭矩
// printf("desired_speed: %f, desired_yaw_rate: %f\n", diff_data.desired_speed, diff_data.desired_yaw_rate); printf("desired_speed: %f, desired_yaw_rate: %f\n", diff_data.desired_speed, diff_data.desired_yaw_rate);
// printf("speed: %f, yaw_rate: %f\n", diff_data.speed, diff_data.yaw_rate); printf("speed: %f, yaw_rate: %f\n", diff_data.speed, diff_data.yaw_rate);
// printf("speed: %f, yaw_rate: %f\n", diff_data.speed, diff_data.yaw_rate); // printf("speed: %f, yaw_rate: %f\n", diff_data.speed, diff_data.yaw_rate);
// printf("left_motor_speed = %f\n",diff_data.left_motor_speed); printf("LF_speed = %f,RF_speed = %f,LR_speed = %f,RR_speed = %f\n",diff_data.left_front_motor_speed,diff_data.right_front_motor_speed,diff_data.left_rear_motor_speed,diff_data.right_rear_motor_speed);
// printf("right_motor_speed = %f\n",diff_data.right_motor_speed);
// printf("speed: FL=%.1f FR=%.1f RL=%.1f RR=%.1f\n", diff_data.left_front_motor_speed, diff_data.right_front_motor_speed, diff_data.left_rear_motor_speed, diff_data.right_rear_motor_speed); // printf("speed: FL=%.1f FR=%.1f RL=%.1f RR=%.1f\n", diff_data.left_front_motor_speed, diff_data.right_front_motor_speed, diff_data.left_rear_motor_speed, diff_data.right_rear_motor_speed);
// printf("torq: FL=%.1fNm FR=%.1fNm RL=%.1fNm RR=%.1fNm\n", diff_data.out_torq[0], diff_data.out_torq[1], diff_data.out_torq[2], diff_data.out_torq[3]); printf("torq: FL=%.1fNm FR=%.1fNm RL=%.1fNm RR=%.1fNm\n", diff_data.out_torq[0], diff_data.out_torq[1], diff_data.out_torq[2], diff_data.out_torq[3]);
float deffspeed = (float)((int16_t)(un_remote_control_input.bit_data.speed)); float deffspeed = (float)((int16_t)(un_remote_control_input.bit_data.speed));
float deffcurvature = (float)((int16_t)(un_remote_control_input.bit_data.curvature)); float deffcurvature = (float)((int16_t)(un_remote_control_input.bit_data.curvature));
@@ -882,7 +987,7 @@ void diffParametersInit(void *signal_id)
deffspeed = deffspeed * 0.01f; deffspeed = deffspeed * 0.01f;
deffcurvature = deffcurvature * 0.0001f; deffcurvature = deffcurvature * 0.0001f;
printf("remote speed = %f, remote curvature = %f\n", deffspeed, deffcurvature); printf(" car state = %d\n", diff_data.state);
timerStart(&diff_app_timer,1000,1);//1s调用一次 timerStart(&diff_app_timer,1000,1);//1s调用一次
} }

View File

@@ -30,8 +30,9 @@ extern "C"
typedef enum typedef enum
{ {
STATE_INIT, ///< 初始状态转速为0且等待扭矩方向判定 STATE_INIT, ///< 初始状态转速为0且等待扭矩方向判定
STATE_FORWARD, ///< 正向旋转状态(扭矩为正) STATE_FORWARD, ///< 前进
STATE_BACKWARD, ///< 反向旋转状态(扭矩为负) STATE_BACKWARD, ///< 后退
STATE_STATIC_TURN ///< 原地转向
} MotorState; } MotorState;
typedef enum typedef enum
@@ -43,7 +44,7 @@ typedef enum
typedef struct DiffData typedef struct DiffData
{ {
ControlMode mode ; // 控制模式 ControlMode mode ; // 控制模式
MotorState state; //当前状态机状态 MotorState state; //当前车辆状态
float desired_speed; // 期望速度 float desired_speed; // 期望速度
float desired_curvature; // 期望曲率 float desired_curvature; // 期望曲率
float left_motor_speed; // 当前左电机速度 float left_motor_speed; // 当前左电机速度

View File

@@ -1100,7 +1100,7 @@ static void processMotorOutput3(void *signal_id)
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_1, LEFT_FRONT_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output1.arr[8], 8, 17);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CAN_Send_Msg(&can_handle_1, LEFT_FRONT_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output1.arr[8], 8, 17);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_1, LEFT_REAR_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output3.arr[8], 8, 17);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CAN_Send_Msg(&can_handle_1, LEFT_REAR_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output3.arr[8], 8, 18);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
} }
@@ -1108,13 +1108,18 @@ static void processMotorOutput4(void *signal_id)
{ {
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_2, RIGHT_FRONT_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output2.arr[8], 8, 17);//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CAN_Send_Msg(&can_handle_2, RIGHT_FRONT_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output2.arr[8], 8, 17);//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_2, RIGHT_FRONT_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output4.arr[8], 8, 17);//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CAN_Send_Msg(&can_handle_2, RIGHT_REAR_MOTOR_OUTPUT2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output4.arr[8], 8, 18);//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
} }
static void processKgfOutput1(void *signal_id) static void processKgfOutput1(void *signal_id)
{ {
(void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (void)signal_id; // <20><><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD>Ϊ<EFBFBD><CEAA>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_0, 0x11000002, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_inf_can_kgf_output1, 8, 15);//KGF1
if(1 == ecu_online)//20250318 <20>޸<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>߲<EFBFBD><DFB2>ܷ<EFBFBD><DCB7>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>E3ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>
{
un_inf_can_kgf_output1.bit_data.can_rx5 = 0xE3;
CAN_Send_Msg(&can_handle_0, 0x11000002, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_inf_can_kgf_output1, 8, 15);//KGF1
}
} }
static void processKgfOutput2(void *signal_id) static void processKgfOutput2(void *signal_id)
@@ -1385,8 +1390,10 @@ void canInterfaceInit(void)
subscribe(&can_timer_interface1, canSendAll); subscribe(&can_timer_interface1, canSendAll);
subscribe(&can_timer_interface2, canInterfaceTimerProcess); subscribe(&can_timer_interface2, canInterfaceTimerProcess);
subscribe(&un_motor_output1, processMotorOutput1); subscribe(&un_motor_output1, processMotorOutput1);
subscribe(&un_motor_output2, processMotorOutput2); subscribe(&un_motor_output2, processMotorOutput2);
subscribe(&un_inf_can_kgf_output1, processKgfOutput1); subscribe(&un_inf_can_kgf_output1, processKgfOutput1);
subscribe(&un_inf_can_kgf_output2, processKgfOutput2); subscribe(&un_inf_can_kgf_output2, processKgfOutput2);
subscribe(&un_wheel_wpeed_output, processWheelSpeedOutput); subscribe(&un_wheel_wpeed_output, processWheelSpeedOutput);

2
main.c
View File

@@ -115,7 +115,7 @@ int main(void)
//打印版本号 //打印版本号
printf("version: V1.72 \n"); printf("version: V1.75 \n");
// 初始化框架 放在最前面解决电机can发送信号累积不处理的问题。 // 初始化框架 放在最前面解决电机can发送信号累积不处理的问题。
testAppInit(); testAppInit();