M12-05P/app/user/MotorCtrl.c
2024-01-11 16:29:14 +08:00

118 lines
2.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "MotorCtrl.h"
#include "hwCtrl.h"
#include "PINdef.h"
#include "appTask.h"
//#include "pfdl.h"
uint8_t MotorState[6],MotorStateReal[6];
void MotorValueInit(void)
{
uint8_t i = 0;
for (i = 0; i < 6; i++)
{
MotorState[i] = ACT_NOACT;
MotorStateReal[i] = ACT_NOACT;
}
}
void setMotorState(uint8_t motorid,uint8_t act)
{
//motorid-=1;
if (act <= ACT_XH && motorid < 6)
{
MotorState[motorid] = act;
}
}
/*
20240106
正转时第一个电机M1正转6秒后M2电机正转M1最大运行时间15秒
反转时第一个电机M2反转8秒后M1电机反转M2最大运行时间17秒。
20240111
正转时第一个电机M1正转2秒后M2电机正转M1最大运行时间15秒
反转时第一个电机M2反转5秒后M1电机反转M2最大运行时间17秒。
*/
#define MOTOR_DELAY_TIME_8S (500)
#define MOTOR_DELAY_TIME_6S (200)
#define MOTOR_DELAY_TIME_15S (1500)
#define MOTOR_DELAY_TIME_17S (1700)
void MotorCtrl(void)//10ms
{
static uint16_t MotorRunCount;
switch (MotorState[0])
{
case ACT_NOACT:
MotorRunCount = 0;
MotorStateReal[MOTOR1] = ACT_NOACT;
MotorStateReal[MOTOR2] = ACT_NOACT;
break;
case ACT_XQ:
MotorRunCount++;
if (MotorRunCount > MOTOR_DELAY_TIME_15S)
{
MotorRunCount = MOTOR_DELAY_TIME_15S;
MotorStateReal[MOTOR1] = ACT_NOACT;
}
else
{
MotorStateReal[MOTOR1] = ACT_XQ;
}
if (MotorRunCount > MOTOR_DELAY_TIME_6S)
{
//MotorRunCount = MOTOR_DELAY_TIME_6S;
MotorStateReal[MOTOR2] = ACT_XQ;
}
else
{
MotorStateReal[MOTOR2] = ACT_NOACT;
}
break;
case ACT_XH:
MotorRunCount++;
if (MotorRunCount > MOTOR_DELAY_TIME_17S)
{
MotorRunCount = MOTOR_DELAY_TIME_17S;
MotorStateReal[MOTOR2] = ACT_NOACT;
}
else
{
MotorStateReal[MOTOR2] = ACT_XH;
}
if (MotorRunCount > MOTOR_DELAY_TIME_8S)
{
//MotorRunCount = MOTOR_DELAY_TIME_8S;
MotorStateReal[MOTOR1] = ACT_XH;
}
else
{
MotorStateReal[MOTOR1] = ACT_NOACT;
}
break;
default:
break;
}
MOTOR1Ctrl(MotorStateReal[MOTOR1]);
MOTOR2Ctrl(MotorStateReal[MOTOR2]);
}