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); // 控制油门