[类型] 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()
|
||||
{
|
||||
//根据初始化状态initstatus操作
|
||||
switch (initstatus)
|
||||
{
|
||||
//刚开机,等待500ms
|
||||
case Initstatus::IS_WaitStart:
|
||||
{
|
||||
if ((millis() - _tm_waitinit) > 500)
|
||||
initstatus = IS_Start;
|
||||
break;
|
||||
}
|
||||
|
||||
// 开始初始化
|
||||
case Initstatus::IS_Start:
|
||||
{
|
||||
// 一开始没有锁定状态
|
||||
// 如果没有在锁定状态,先慢速收购直到锁定
|
||||
if (motocontrol.gethooktatus() != HS_Locked)
|
||||
{
|
||||
// 开始自动慢速上升,直到顶部按钮按下
|
||||
@ -457,7 +459,7 @@ void loop()
|
||||
if (_looptm_core1>10)
|
||||
{
|
||||
// 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 (1)
|
||||
{
|
||||
_tm_core0= millis();
|
||||
if (_needweightalign)
|
||||
{
|
||||
_needweightalign = false;
|
||||
@ -490,6 +493,15 @@ void Task1(void *pvParameters)
|
||||
/*保持mqtt心跳,如果Mqtt没有连接会自动连接*/
|
||||
fc.mqttLoop("cmd");
|
||||
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发送状态信息
|
||||
|
@ -25,8 +25,6 @@ Motocontrol::Motocontrol()
|
||||
_curr_length = 0.0;
|
||||
_hooksstatus = HS_UnInit;
|
||||
_weightalign = false;
|
||||
_overweightcount = 0;
|
||||
_notweightcount = 0;
|
||||
_controlstatus.is_autogoodsdown = false;
|
||||
_servotatus = SS_ServoUnLocked; // 停止状态,为了防止舵机堵转,和延时关闭电机需要一个停止状态机
|
||||
_unblocktimes = 0;
|
||||
@ -52,6 +50,11 @@ void Motocontrol::setspeed(float motospeed, float acctime) // 设置速度
|
||||
|
||||
void Motocontrol::setweight(int pullweight) // 设置重量
|
||||
{
|
||||
// 到顶部锁定状态,有向上的压力,重量不准,直接退出
|
||||
if (_controlstatus.is_toplocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pullweight = pullweight;
|
||||
checkgoods();
|
||||
}
|
||||
@ -106,49 +109,49 @@ String Motocontrol::gethooktatus_str(bool chstr)
|
||||
|
||||
void Motocontrol::checkgoods() // 检测是否超重
|
||||
{
|
||||
// 到顶部锁定状态,有向上的压力,重量不准,不能检测
|
||||
if (_controlstatus.is_toplocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
static unsigned long lastChangeTime = 0; // 上次状态变化的时间
|
||||
static unsigned long lastChangeTimeOverweight = 0; // 上次超重状态变化的时间
|
||||
const unsigned long debounceTime = 100; // 防抖时间,单位:毫秒
|
||||
|
||||
// 检查是否超重
|
||||
if (_pullweight > HOOK_WEIHT_MAX)
|
||||
{
|
||||
// 防止毛刺
|
||||
_overweightcount++;
|
||||
if (_overweightcount > 40)
|
||||
_controlstatus.is_overweight = true;
|
||||
bool isOverweight = _pullweight > HOOK_WEIHT_MAX; // 当前是否超重
|
||||
if (isOverweight != _controlstatus.is_overweight) {
|
||||
// 如果状态持续超过防抖时间,则切换状态
|
||||
if (millis() - lastChangeTimeOverweight > debounceTime) {
|
||||
_controlstatus.is_overweight = isOverweight;
|
||||
lastChangeTimeOverweight = millis(); // 更新状态变化时间
|
||||
|
||||
// 添加日志信息
|
||||
if (isOverweight) {
|
||||
addLogMessage("Overweight: " + String(_pullweight));
|
||||
} else {
|
||||
addLogMessage("Not overweight: " + String(_pullweight));
|
||||
}
|
||||
else
|
||||
{
|
||||
_controlstatus.is_overweight = false;
|
||||
_overweightcount = 0;
|
||||
}
|
||||
} else {
|
||||
// 状态未变化,重置时间戳
|
||||
lastChangeTimeOverweight = millis();
|
||||
}
|
||||
|
||||
|
||||
// 检查是否有货物
|
||||
if (_pullweight < HOOK_WEIHT_MIN)
|
||||
{
|
||||
// 防止毛刺
|
||||
_notweightcount++;
|
||||
if (_notweightcount > 40)
|
||||
{
|
||||
// printf("goods weight<min 40 times :%d \n", _pullweight);
|
||||
if (_controlstatus.is_havegoods)
|
||||
{
|
||||
addLogMessage("goods no: " + String(_pullweight));
|
||||
}
|
||||
_controlstatus.is_havegoods = false;
|
||||
bool currentState = _pullweight >= HOOK_WEIHT_MIN; // 当前是否有货物
|
||||
if (currentState != _controlstatus.is_havegoods) {
|
||||
// 如果状态持续超过防抖时间,则切换状态
|
||||
if (millis() - lastChangeTime > debounceTime) {
|
||||
_controlstatus.is_havegoods = currentState;
|
||||
lastChangeTime = millis(); // 更新状态变化时间
|
||||
|
||||
// 添加日志信息
|
||||
if (currentState) {
|
||||
addLogMessage("Have goods: " + String(_pullweight));
|
||||
} else {
|
||||
addLogMessage("No goods: " + String(_pullweight));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_controlstatus.is_havegoods)
|
||||
{
|
||||
addLogMessage("goods ok: " + String(_pullweight));
|
||||
}
|
||||
_controlstatus.is_havegoods = true;
|
||||
_notweightcount = 0;
|
||||
} else {
|
||||
// 状态未变化,重置时间戳
|
||||
lastChangeTime = millis();
|
||||
}
|
||||
}
|
||||
void Motocontrol::lockservo() // 锁定舵机
|
||||
|
@ -97,9 +97,7 @@ private:
|
||||
int _hook_currlen;
|
||||
float _curr_length;
|
||||
bool _weightalign;
|
||||
uint8_t _overweightcount;
|
||||
|
||||
uint8_t _notweightcount;
|
||||
uint8_t _unblocktimes;
|
||||
unsigned long _tm_waitunhook;
|
||||
float _runspeed;
|
||||
|
Loading…
Reference in New Issue
Block a user