[类型] 1.修改主核心超时10ms,副核心200ms,2.检测货物函数优化
详细描述
This commit is contained in:
parent
3045d138b1
commit
862cbbb00a
18
src/main.cpp
18
src/main.cpp
@ -289,18 +289,20 @@ bool check_tare()
|
|||||||
//
|
//
|
||||||
void checkinited()
|
void checkinited()
|
||||||
{
|
{
|
||||||
|
//根据初始化状态initstatus操作
|
||||||
switch (initstatus)
|
switch (initstatus)
|
||||||
{
|
{
|
||||||
|
//刚开机,等待500ms
|
||||||
case Initstatus::IS_WaitStart:
|
case Initstatus::IS_WaitStart:
|
||||||
{
|
{
|
||||||
if ((millis() - _tm_waitinit) > 500)
|
if ((millis() - _tm_waitinit) > 500)
|
||||||
initstatus = IS_Start;
|
initstatus = IS_Start;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// 开始初始化
|
||||||
case Initstatus::IS_Start:
|
case Initstatus::IS_Start:
|
||||||
{
|
{
|
||||||
// 一开始没有锁定状态
|
// 如果没有在锁定状态,先慢速收购直到锁定
|
||||||
if (motocontrol.gethooktatus() != HS_Locked)
|
if (motocontrol.gethooktatus() != HS_Locked)
|
||||||
{
|
{
|
||||||
// 开始自动慢速上升,直到顶部按钮按下
|
// 开始自动慢速上升,直到顶部按钮按下
|
||||||
@ -457,7 +459,7 @@ void loop()
|
|||||||
if (_looptm_core1>10)
|
if (_looptm_core1>10)
|
||||||
{
|
{
|
||||||
// ESP_LOGE(MOUDLENAME, "main loop time out %d ms", _looptm_core1);
|
// ESP_LOGE(MOUDLENAME, "main loop time out %d ms", _looptm_core1);
|
||||||
addLogMessage("core1 loop time out: " + String(_looptm_core1));
|
addLogMessage("core1 timeout: " + String(_looptm_core1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -472,6 +474,7 @@ void Task1(void *pvParameters)
|
|||||||
// 在这里可以添加一些代码,这样的话这个任务执行时会先执行一次这里的内容(当然后面进入while循环之后不会再执行这部分了)
|
// 在这里可以添加一些代码,这样的话这个任务执行时会先执行一次这里的内容(当然后面进入while循环之后不会再执行这部分了)
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
_tm_core0= millis();
|
||||||
if (_needweightalign)
|
if (_needweightalign)
|
||||||
{
|
{
|
||||||
_needweightalign = false;
|
_needweightalign = false;
|
||||||
@ -490,6 +493,15 @@ void Task1(void *pvParameters)
|
|||||||
/*保持mqtt心跳,如果Mqtt没有连接会自动连接*/
|
/*保持mqtt心跳,如果Mqtt没有连接会自动连接*/
|
||||||
fc.mqttLoop("cmd");
|
fc.mqttLoop("cmd");
|
||||||
vTaskDelay(10);
|
vTaskDelay(10);
|
||||||
|
_looptm_core0= millis()-_tm_core0;
|
||||||
|
|
||||||
|
//如果循环时间超过100ms,则打印错误日志
|
||||||
|
if (_looptm_core0>200)
|
||||||
|
{
|
||||||
|
// ESP_LOGE(MOUDLENAME, "main loop time out %d ms", _looptm_core1);
|
||||||
|
addLogMessage("core0 timeout: " + String(_looptm_core0));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void sendinfo() // 每500ms发送状态信息
|
void sendinfo() // 每500ms发送状态信息
|
||||||
|
@ -25,8 +25,6 @@ Motocontrol::Motocontrol()
|
|||||||
_curr_length = 0.0;
|
_curr_length = 0.0;
|
||||||
_hooksstatus = HS_UnInit;
|
_hooksstatus = HS_UnInit;
|
||||||
_weightalign = false;
|
_weightalign = false;
|
||||||
_overweightcount = 0;
|
|
||||||
_notweightcount = 0;
|
|
||||||
_controlstatus.is_autogoodsdown = false;
|
_controlstatus.is_autogoodsdown = false;
|
||||||
_servotatus = SS_ServoUnLocked; // 停止状态,为了防止舵机堵转,和延时关闭电机需要一个停止状态机
|
_servotatus = SS_ServoUnLocked; // 停止状态,为了防止舵机堵转,和延时关闭电机需要一个停止状态机
|
||||||
_unblocktimes = 0;
|
_unblocktimes = 0;
|
||||||
@ -52,6 +50,11 @@ void Motocontrol::setspeed(float motospeed, float acctime) // 设置速度
|
|||||||
|
|
||||||
void Motocontrol::setweight(int pullweight) // 设置重量
|
void Motocontrol::setweight(int pullweight) // 设置重量
|
||||||
{
|
{
|
||||||
|
// 到顶部锁定状态,有向上的压力,重量不准,直接退出
|
||||||
|
if (_controlstatus.is_toplocked)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
_pullweight = pullweight;
|
_pullweight = pullweight;
|
||||||
checkgoods();
|
checkgoods();
|
||||||
}
|
}
|
||||||
@ -106,49 +109,49 @@ String Motocontrol::gethooktatus_str(bool chstr)
|
|||||||
|
|
||||||
void Motocontrol::checkgoods() // 检测是否超重
|
void Motocontrol::checkgoods() // 检测是否超重
|
||||||
{
|
{
|
||||||
// 到顶部锁定状态,有向上的压力,重量不准,不能检测
|
static unsigned long lastChangeTime = 0; // 上次状态变化的时间
|
||||||
if (_controlstatus.is_toplocked)
|
static unsigned long lastChangeTimeOverweight = 0; // 上次超重状态变化的时间
|
||||||
{
|
const unsigned long debounceTime = 100; // 防抖时间,单位:毫秒
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否超重
|
// 检查是否超重
|
||||||
if (_pullweight > HOOK_WEIHT_MAX)
|
bool isOverweight = _pullweight > HOOK_WEIHT_MAX; // 当前是否超重
|
||||||
{
|
if (isOverweight != _controlstatus.is_overweight) {
|
||||||
// 防止毛刺
|
// 如果状态持续超过防抖时间,则切换状态
|
||||||
_overweightcount++;
|
if (millis() - lastChangeTimeOverweight > debounceTime) {
|
||||||
if (_overweightcount > 40)
|
_controlstatus.is_overweight = isOverweight;
|
||||||
_controlstatus.is_overweight = true;
|
lastChangeTimeOverweight = millis(); // 更新状态变化时间
|
||||||
}
|
|
||||||
else
|
// 添加日志信息
|
||||||
{
|
if (isOverweight) {
|
||||||
_controlstatus.is_overweight = false;
|
addLogMessage("Overweight: " + String(_pullweight));
|
||||||
_overweightcount = 0;
|
} else {
|
||||||
|
addLogMessage("Not overweight: " + String(_pullweight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 状态未变化,重置时间戳
|
||||||
|
lastChangeTimeOverweight = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 检查是否有货物
|
// 检查是否有货物
|
||||||
if (_pullweight < HOOK_WEIHT_MIN)
|
bool currentState = _pullweight >= HOOK_WEIHT_MIN; // 当前是否有货物
|
||||||
{
|
if (currentState != _controlstatus.is_havegoods) {
|
||||||
// 防止毛刺
|
// 如果状态持续超过防抖时间,则切换状态
|
||||||
_notweightcount++;
|
if (millis() - lastChangeTime > debounceTime) {
|
||||||
if (_notweightcount > 40)
|
_controlstatus.is_havegoods = currentState;
|
||||||
{
|
lastChangeTime = millis(); // 更新状态变化时间
|
||||||
// printf("goods weight<min 40 times :%d \n", _pullweight);
|
|
||||||
if (_controlstatus.is_havegoods)
|
// 添加日志信息
|
||||||
{
|
if (currentState) {
|
||||||
addLogMessage("goods no: " + String(_pullweight));
|
addLogMessage("Have goods: " + String(_pullweight));
|
||||||
|
} else {
|
||||||
|
addLogMessage("No goods: " + String(_pullweight));
|
||||||
}
|
}
|
||||||
_controlstatus.is_havegoods = false;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
// 状态未变化,重置时间戳
|
||||||
{
|
lastChangeTime = millis();
|
||||||
if (!_controlstatus.is_havegoods)
|
|
||||||
{
|
|
||||||
addLogMessage("goods ok: " + String(_pullweight));
|
|
||||||
}
|
|
||||||
_controlstatus.is_havegoods = true;
|
|
||||||
_notweightcount = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Motocontrol::lockservo() // 锁定舵机
|
void Motocontrol::lockservo() // 锁定舵机
|
||||||
|
@ -97,9 +97,7 @@ private:
|
|||||||
int _hook_currlen;
|
int _hook_currlen;
|
||||||
float _curr_length;
|
float _curr_length;
|
||||||
bool _weightalign;
|
bool _weightalign;
|
||||||
uint8_t _overweightcount;
|
|
||||||
|
|
||||||
uint8_t _notweightcount;
|
|
||||||
uint8_t _unblocktimes;
|
uint8_t _unblocktimes;
|
||||||
unsigned long _tm_waitunhook;
|
unsigned long _tm_waitunhook;
|
||||||
float _runspeed;
|
float _runspeed;
|
||||||
|
Loading…
Reference in New Issue
Block a user