From 049a5db8e5684fbe109355649478ad8de6ed3125 Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Fri, 9 May 2025 20:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afix=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91?= =?UTF-8?q?=EF=BC=9A1.=E5=88=87=E8=87=AA=E5=8A=A8=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=E6=A3=80=E6=B5=8B=20=E9=A2=84=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=A8=A1=E5=BC=8F=E6=98=AF=E5=90=A6=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=88=B0=E8=87=AA=E5=8A=A8=20=E5=86=8D=E5=B0=86=E6=B2=B9?= =?UTF-8?q?=E9=97=A8=E8=AE=BE=E7=BD=AE=E5=88=B01500=20=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E5=96=87=E5=8F=AD=E6=A8=8A=E5=93=99=E8=87=AA=E5=8A=A8=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=88=87=E6=8D=A2=E5=A4=B1=E8=B4=A5=202.=E8=A7=A3?= =?UTF-8?q?=E9=94=81=E6=94=B9=E4=B8=BA=E5=85=88=E5=88=87=E5=AE=9A=E7=82=B9?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=20=E3=80=90=E8=BF=87=20=20=E7=A8=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9A=20=E3=80=90=E5=BD=B1=20=20=E5=93=8D=E3=80=91=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动 --- src/commser.cpp | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/commser.cpp b/src/commser.cpp index 299131e..a792cab 100644 --- a/src/commser.cpp +++ b/src/commser.cpp @@ -22,7 +22,7 @@ static const char *MOUDLENAME = "COMMSER"; // char *password = "fxmf0622"; // wifi密码 char *ssid = "fxmf_sc02"; // 4g wifi帐号 char *password = "12345678"; // 4g wifi密码 -char *mqttServer = "wxsky.com"; // mqtt地址 +char *mqttServer = "szdot.top"; // mqtt地址 int mqttPort = 1883; // mqtt端口 char *mqttName = "admin"; // mqtt帐号 char *mqttPassword = "123456"; // mqtt密码 @@ -107,17 +107,26 @@ void mqtt_receiveCallback(char *topic, byte *payload, unsigned int length) // 切模式 set_mode(AUTO); // 设置飞控为自动模式 // 油门 - delay(500); - uint16_t chan[] = {1500, 1500, 1500, 1500}; // 加解锁 油门到底 - fc.mav_channels_override(chan); // 控制油门 + uint16_t chan[] = {1500, 1500, 1500, 1500}; + int8_t i = 0; + while (topicPubMsg[12] == "自动" && i < 10) + { + fc.mav_channels_override(chan); // 控制油门 + delay(50); + i++; + } + if (topicPubMsg[12] != "自动") + { + fc.playText("自动模式切换失败,请检查飞控是否正常工作"); + } } } else if (key == "unlock") // 解锁 { - - set_mode(ALT_HOLD); // 设置飞控为定高模式 + set_mode(LOITER); // 设置飞控为定点模式 delay(2000); // 可以根据需要调整延迟时间,确保模式切换生效 lock_or_unlock(false); // 解锁 + // 功能待修改 判断有没有在地面上 然后切定点 确认切定点油门设1100 } else if (key == "lock") // 加锁 { @@ -126,8 +135,8 @@ void mqtt_receiveCallback(char *topic, byte *payload, unsigned int length) fc.mav_channels_override(chan); // 控制油门 // 加锁 lock_or_unlock(true); - delay(2000); // 可以根据需要调整延迟时间,确保模式切换生效 - set_mode(ALT_HOLD); // 设置飞控为定高模式 + delay(2000); // 可以根据需要调整延迟时间,确保模式切换生效 + set_mode(LOITER); // 设置飞控为定点模式 } else if (key == "guidedMode") // 指点 { @@ -153,12 +162,22 @@ void mqtt_receiveCallback(char *topic, byte *payload, unsigned int length) } else if (key == "autoMode") // 自动auto模式 { + // 切模式 set_mode(AUTO); // 设置飞控为定高模式 // 油门 - delay(500); - uint16_t chan[] = {1500, 1500, 1500, 1500}; // 加解锁 油门到底 - fc.mav_channels_override(chan); // 控制油门 + uint16_t chan[] = {1500, 1500, 1500, 1500}; + int8_t i = 0; + while (topicPubMsg[12] == "自动" && i < 10) + { + fc.mav_channels_override(chan); // 控制油门 + delay(50); + i++; + } + if (topicPubMsg[12] != "自动") + { + fc.playText("自动模式切换失败,请检查飞控是否正常工作"); + } } else if (key == "loiterMode") // 悬停定点loiter模式 { @@ -167,7 +186,7 @@ void mqtt_receiveCallback(char *topic, byte *payload, unsigned int length) fc.mav_channels_override(chan); // 控制油门 delay(500); // 切模式 - set_mode(LOITER); // 设置飞控为定高模式 + set_mode(LOITER); // 设置飞控为定点模式 // 油门 delay(500); fc.mav_channels_override(chan); // 控制油门