修改电机驱动

This commit is contained in:
2025-10-04 15:44:08 +08:00
parent 358be06b7d
commit b598c1d479
7 changed files with 698 additions and 860 deletions

View File

@@ -287,8 +287,7 @@ void flexcan_Receive_callback_1(flexcan_handle_t *handle,
{
flexcan_frame_t *buf = (flexcan_frame_t *)userData;
uint8_t i = 0;
static uint32_t start_time = 0;
uint8_t i = 0;
//--------------------------------------------------------------
switch (status)
{
@@ -296,51 +295,45 @@ void flexcan_Receive_callback_1(flexcan_handle_t *handle,
break;
case FLEXCAN_RX_FIFO_IDLE:
if(MOTOR_INPUT_ID_1 == (buf->id))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
{
time_elapsed = getCurrentTime() - start_time;
start_time = getCurrentTime();
if(LEFT_FRONT_MOTOR_INPUT1 == (buf->id))
{
can_fault_info.bit_data.motor1_count ++;
for(i = 0; i < (buf->length); i++)
{
un_motor_input1.arr[i] = buf->dataBuffer[i];
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
publishMessage(&un_motor_input1, 1);
// CAN_Send_Msg(&can_handle_1, 0x11111111, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_input1, 8, 18);//
}
else if(MOTOR_INPUT_ID_3 == (buf->id))
publishMessage(&un_motor_input1, 1);
}
else if( LEFT_FRONT_MOTOR_INPUT2 == (buf->id) )
{
// can_fault_info.bit_data.motor1_count ++;
for(i = 0; i < (buf->length); i++)
{
un_motor_temp1.arr[i] = buf->dataBuffer[i];
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
publishMessage(&un_motor_temp1, 1);//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
}
else if( LEFT_REAR_MOTOR2_INPUT1 == (buf->id) )//
{
can_fault_info.bit_data.motor3_count ++;
for(i = 0; i < (buf->length); i++)
{
un_motor_input3.arr[i] = buf->dataBuffer[i];
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
publishMessage(&un_motor_input3, 1);
// CAN_Send_Msg(&can_handle_1, 0x11111113, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_input3, 8, 18);//
}
else if(MOTOR_INPUT_ID_5 == (buf->id))//<2F><><EFBFBD>յ<EFBFBD>λ
// publishMessage(&un_motor_input3, 1); //<2F>޸<EFBFBD>Ϊ
}
else if( LEFT_REAR_MOTOR2_INPUT2 == (buf->id) )
{
for(i = 0; i < (buf->length); i++)
{
un_motor_input1.arr[i+8] = buf->dataBuffer[i];
}
// CAN_Send_Msg(&can_handle_1, 0x11111115, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_input1.arr[8], 8, 18);//
}
else if(MOTOR_INPUT_ID_7 == (buf->id))//<2F><><EFBFBD>յ<EFBFBD>λ
{
for(i = 0; i < (buf->length); i++)
{
un_motor_input3.arr[i+8] = buf->dataBuffer[i];
// CAN_Send_Msg(&can_handle_1, 0x11111117, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_input3.arr[8], 8, 18);//
}
un_motor_temp3.arr[i] = buf->dataBuffer[i];
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
publishMessage(&un_motor_temp3, 1);//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
}
else{}
else{}
break;
case FLEXCAN_TX_IDLE:
@@ -387,55 +380,45 @@ void flexcan_Receive_callback_2(flexcan_handle_t *handle,
break;
case FLEXCAN_RX_FIFO_IDLE:
if(MOTOR_INPUT_ID_2 == (buf->id))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
{
time_elapsed1 = getCurrentTime() - start_time1;
start_time1 = getCurrentTime();
if(RIGHT_FRONT_MOTOR_INPUT1 == (buf->id))
{
can_fault_info.bit_data.motor2_count ++;
for(i = 0; i < (buf->length); i++)
{
un_motor_input2.arr[i] = buf->dataBuffer[i];
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
publishMessage(&un_motor_input2, 1);
// CAN_Send_Msg(&can_handle_2, 0x11111112, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_input2, 8, 18);//
}
else if(MOTOR_INPUT_ID_4 == (buf->id))
publishMessage(&un_motor_input2, 1);
}
else if( RIGHT_FRONT_MOTOR_INPUT2 == (buf->id) )
{
for(i = 0; i < (buf->length); i++)
{
un_motor_temp2.arr[i] = buf->dataBuffer[i];
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
publishMessage(&un_motor_temp2, 1);//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
}
else if( RIGHT_REAR_MOTOR_INPUT1 == (buf->id) )//
{
can_fault_info.bit_data.motor4_count ++;
for(i = 0; i < (buf->length); i++)
{
un_motor_input4.arr[i] = buf->dataBuffer[i];
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
publishMessage(&un_motor_input4, 1);
// CAN_Send_Msg(&can_handle_2, 0x11111114, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_input4, 8, 18);//
}
else if(MOTOR_INPUT_ID_6 == (buf->id))//<2F><><EFBFBD>յ<EFBFBD>λ
publishMessage(&un_motor_input4, 1);
}
else if( RIGHT_REAR_MOTOR_INPUT2 == (buf->id) )
{
for(i = 0; i < (buf->length); i++)
{
un_motor_input2.arr[i+8] = buf->dataBuffer[i];
}
// CAN_Send_Msg(&can_handle_2, 0x11111116, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_input2.arr[8], 8, 18);//
}
else if(MOTOR_INPUT_ID_8 == (buf->id))//<2F><><EFBFBD>յ<EFBFBD>λ
{
for(i = 0; i < (buf->length); i++)
{
un_motor_input4.arr[i+8] = buf->dataBuffer[i];
un_motor_temp4.arr[i] = buf->dataBuffer[i];
}
// CAN_Send_Msg(&can_handle_2, 0x11111118, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_input4.arr[8], 8, 18);//
}
else{}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
publishMessage(&un_motor_temp4, 1);//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
}
else{}
break;
case FLEXCAN_TX_IDLE:
@@ -1135,18 +1118,35 @@ static void processSdoOutput8(void *signal_id)
static void processMotorOutput1(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>
CAN_Send_Msg(&can_handle_1, 0x10F81807, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output1, 8, 15);//<2F><><EFBFBD><EFBFBD><31>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_1, 0x10F83807, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output3, 8, 16);//
(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_OUTPUT1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output1, 8, 15);//<2F><><EFBFBD><EFBFBD><31>غ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_1, LEFT_REAR_MOTOR_OUTPUT1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output3, 8, 16);//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
static void processMotorOutput2(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>
CAN_Send_Msg(&can_handle_2, 0x10F82807, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output2, 8, 15);//<2F><><EFBFBD><EFBFBD><32><EFBFBD> <20><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_2, 0x10F84807, FLEXCAN_EXTEND_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output4, 8, 16);//
(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_OUTPUT1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output2, 8, 15);//<2F><><EFBFBD><EFBFBD><32>غ<EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_2, RIGHT_REAR_MOTOR_OUTPUT1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, (uint8_t *)&un_motor_output4, 8, 16);//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//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>
//
// 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, 18);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//
//}
//
//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>
// 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_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)
{
@@ -1342,33 +1342,33 @@ void canInterfaceInit(void)
memset(&un_motor_output1, 0, sizeof(UnMotorOutput));
memset(&un_motor_output2, 0, sizeof(UnMotorOutput));
un_motor_output1.bit_data.mode = 0x05;
un_motor_output1.bit_data.gear = 0x01;
un_motor_output1.bit_data.can_gear = 0x01;
un_motor_output1.bit_data.motor_direction = 0x01;
un_motor_output1.bit_data.control_data1 = 0x0;
un_motor_output1.bit_data.control_data2 = 0x0;
un_motor_output2.bit_data.mode = 0x05;
un_motor_output2.bit_data.gear = 0x01;
un_motor_output2.bit_data.can_gear = 0x01;
un_motor_output2.bit_data.motor_direction = 0x00;
un_motor_output2.bit_data.control_data1 = 0x0;
un_motor_output2.bit_data.control_data2 = 0x0;
un_motor_output3.bit_data.mode = 0x05;
un_motor_output3.bit_data.gear = 0x01;
un_motor_output3.bit_data.can_gear = 0x01;
un_motor_output3.bit_data.motor_direction = 0x01;
un_motor_output3.bit_data.control_data1 = 0x0;
un_motor_output3.bit_data.control_data2 = 0x0;
un_motor_output4.bit_data.mode = 0x05;
un_motor_output4.bit_data.gear = 0x01;
un_motor_output4.bit_data.can_gear = 0x01;
un_motor_output4.bit_data.motor_direction = 0x00;
un_motor_output4.bit_data.control_data1 = 0x0;
un_motor_output4.bit_data.control_data2 = 0x0;
// un_motor_output1.bit_data.mode = 0x05;
// un_motor_output1.bit_data.gear = 0x01;
// un_motor_output1.bit_data.can_gear = 0x01;
// un_motor_output1.bit_data.motor_direction = 0x01;
// un_motor_output1.bit_data.control_data1 = 0x0;
// un_motor_output1.bit_data.control_data2 = 0x0;
//
// un_motor_output2.bit_data.mode = 0x05;
// un_motor_output2.bit_data.gear = 0x01;
// un_motor_output2.bit_data.can_gear = 0x01;
// un_motor_output2.bit_data.motor_direction = 0x00;
// un_motor_output2.bit_data.control_data1 = 0x0;
// un_motor_output2.bit_data.control_data2 = 0x0;
//
// un_motor_output3.bit_data.mode = 0x05;
// un_motor_output3.bit_data.gear = 0x01;
// un_motor_output3.bit_data.can_gear = 0x01;
// un_motor_output3.bit_data.motor_direction = 0x01;
// un_motor_output3.bit_data.control_data1 = 0x0;
// un_motor_output3.bit_data.control_data2 = 0x0;
//
// un_motor_output4.bit_data.mode = 0x05;
// un_motor_output4.bit_data.gear = 0x01;
// un_motor_output4.bit_data.can_gear = 0x01;
// un_motor_output4.bit_data.motor_direction = 0x00;
// un_motor_output4.bit_data.control_data1 = 0x0;
// un_motor_output4.bit_data.control_data2 = 0x0;