Optimierung Systemhochlauf
This commit is contained in:
@@ -6,6 +6,19 @@
|
||||
struct MOTOR_CONTROL_DATA motctrl[MOTOR_COUNT];
|
||||
struct CAN_INTERFACE_DATA intf_data[MOTOR_COUNT];
|
||||
|
||||
int iBusTimeoutCounter = 0;
|
||||
void IncBusTimeoutCounter(int iMotorIndex)
|
||||
{
|
||||
if (iBusTimeoutCounter < 2000)
|
||||
{
|
||||
iBusTimeoutCounter++;
|
||||
if (iBusTimeoutCounter >= 2000)
|
||||
{
|
||||
motctrl[iMotorIndex].nSwitchState = 0;
|
||||
MqttClient_Publish_MotorSwitchState(iMotorIndex, motctrl[iMotorIndex].nSwitchState);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// @brief Open socket of CAN interface for the given motor
|
||||
/// @param iMotorIndex
|
||||
/// @param ifacename
|
||||
@@ -152,24 +165,27 @@ void Can_SetMotorPower(int iMotorIndex, int iPower)
|
||||
/// @param iMotorIndex
|
||||
void Can_TransmitMotorGear(int iMotorIndex)
|
||||
{
|
||||
// Transmission rate: 100ms
|
||||
struct can_frame frame;
|
||||
|
||||
frame.can_id = 0x18F005D0;
|
||||
frame.can_id |= CAN_EFF_FLAG;
|
||||
frame.can_dlc = 8;
|
||||
frame.data[0] = motctrl[iMotorIndex].iMotorGear;
|
||||
frame.data[1] = 0xFF;
|
||||
frame.data[2] = 0xFF;
|
||||
frame.data[3] = 0xFF;
|
||||
frame.data[4] = 0xFF;
|
||||
frame.data[5] = 0xFF;
|
||||
frame.data[6] = 0xFF;
|
||||
frame.data[7] = 0xFF;
|
||||
|
||||
if (write(intf_data[iMotorIndex].socket, &frame, sizeof(frame)) != sizeof(frame))
|
||||
//if (motctrl[iMotorIndex].nSwitchState > 0)
|
||||
{
|
||||
// Transmission rate: 100ms
|
||||
struct can_frame frame;
|
||||
|
||||
frame.can_id = 0x18F005D0;
|
||||
frame.can_id |= CAN_EFF_FLAG;
|
||||
frame.can_dlc = 8;
|
||||
frame.data[0] = motctrl[iMotorIndex].iMotorGear;
|
||||
frame.data[1] = 0xFF;
|
||||
frame.data[2] = 0xFF;
|
||||
frame.data[3] = 0xFF;
|
||||
frame.data[4] = 0xFF;
|
||||
frame.data[5] = 0xFF;
|
||||
frame.data[6] = 0xFF;
|
||||
frame.data[7] = 0xFF;
|
||||
|
||||
if (write(intf_data[iMotorIndex].socket, &frame, sizeof(frame)) != sizeof(frame))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,24 +194,27 @@ void Can_TransmitMotorGear(int iMotorIndex)
|
||||
/// @param iMotorIndex
|
||||
void Can_TransmitMotorPower(int iMotorIndex)
|
||||
{
|
||||
// Transmission rate: 50ms
|
||||
struct can_frame frame;
|
||||
|
||||
frame.can_id = 0x0CF003D0;
|
||||
frame.can_id |= CAN_EFF_FLAG;
|
||||
frame.can_dlc = 8;
|
||||
frame.data[0] = 0xFF;
|
||||
frame.data[1] = motctrl[iMotorIndex].iMotorPower; // motor power 0 = 0%, 250 = 100%
|
||||
frame.data[2] = 0xFF;
|
||||
frame.data[3] = 0xFF;
|
||||
frame.data[4] = 0xFF;
|
||||
frame.data[5] = 0xFF;
|
||||
frame.data[6] = 0xFF;
|
||||
frame.data[7] = 0xFF;
|
||||
|
||||
if (write(intf_data[iMotorIndex].socket, &frame, sizeof(frame)) != sizeof(frame))
|
||||
//if (motctrl[iMotorIndex].nSwitchState > 0)
|
||||
{
|
||||
// Transmission rate: 50ms
|
||||
struct can_frame frame;
|
||||
|
||||
frame.can_id = 0x0CF003D0;
|
||||
frame.can_id |= CAN_EFF_FLAG;
|
||||
frame.can_dlc = 8;
|
||||
frame.data[0] = 0xFF;
|
||||
frame.data[1] = motctrl[iMotorIndex].iMotorPower; // motor power 0 = 0%, 250 = 100%
|
||||
frame.data[2] = 0xFF;
|
||||
frame.data[3] = 0xFF;
|
||||
frame.data[4] = 0xFF;
|
||||
frame.data[5] = 0xFF;
|
||||
frame.data[6] = 0xFF;
|
||||
frame.data[7] = 0xFF;
|
||||
|
||||
if (write(intf_data[iMotorIndex].socket, &frame, sizeof(frame)) != sizeof(frame))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +226,8 @@ void Can_ReadData(int iMotorIndex)
|
||||
ssize_t nbytes = 0;
|
||||
struct can_frame frame;
|
||||
|
||||
IncBusTimeoutCounter(iMotorIndex);
|
||||
|
||||
// wir wollen immer alle verfügbaren Frames lesen
|
||||
while ((nbytes = read(intf_data[iMotorIndex].socket, &frame, sizeof(frame))) > 0)
|
||||
{
|
||||
@@ -239,7 +260,8 @@ void Can_ReadData(int iMotorIndex)
|
||||
/// @param frame
|
||||
void Can_Read_Manu_PGN(int iMotorIndex, struct can_frame *frame)
|
||||
{
|
||||
motctrl[iMotorIndex].nSwitchState = frame->data[2];
|
||||
iBusTimeoutCounter = 0;
|
||||
motctrl[iMotorIndex].nSwitchState = frame->data[4];
|
||||
MqttClient_Publish_MotorSwitchState(iMotorIndex, motctrl[iMotorIndex].nSwitchState);
|
||||
}
|
||||
|
||||
@@ -247,6 +269,6 @@ void Can_Read_Manu_PGN(int iMotorIndex, struct can_frame *frame)
|
||||
/// @param frame
|
||||
void Can_Read_Manu_PGN2(int iMotorIndex, struct can_frame *frame)
|
||||
{
|
||||
motctrl[iMotorIndex].iActualMotorPowerW = (frame->data[3] << 16) | (frame->data[4] << 8) | frame->data[5];
|
||||
motctrl[iMotorIndex].iActualMotorPowerW = (frame->data[6] << 16) | (frame->data[5] << 8) | frame->data[4];
|
||||
MqttClient_Publish_MotorActualPowerW(iMotorIndex, motctrl[iMotorIndex].iActualMotorPowerW);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
#define MOTOR_GEAR_NEUTRAL 0x7D
|
||||
#define MOTOR_GEAR_FORWARD 0x7E
|
||||
|
||||
#define MOTOR_PWR_MIN_PCT 5
|
||||
#define MOTOR_PWR_MIN_PCT 15
|
||||
#define MOTOR_PWR_MAX_PCT 100
|
||||
#define MOTOR_PWR_STEP 14
|
||||
#define MOTOR_PWR_STEP 12
|
||||
|
||||
struct MOTOR_CONTROL_DATA
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user