【课程引入】
TT本身能够通过手机APP控制飞行,但是万一遇到手机没电或者是手机没下载APP又需要马上使用无人机,就需要一个控制器来进行操控,我们可以通过编程制作一个备用遥控器给TT,以备不时之需。
【教学目标】
1、学会使用编程控制红外接收模块
2、能够使用自制的控制器控制无人机飞行
【任务要求】
使用mind+给TT编程,并使用配套的红外接收模块控制TT按照既定路线飞行。
材料清单
- 红外接收模块 X1 链接
步骤1 设计控制器按键功能
步骤2 制作流程图
步骤3 将红外模块连接到TT上
步骤4 编写代码
代码
/*!
* MindPlus
* telloesp32
*
*/
#include <RMTT_Libs.h>
#include <DFRobot_IRremote.h>
// 动态变量
String mind_s_control;
// 创建对象
RMTT_RGB tt_rgb;
RMTT_Protocol protocol;
IRremote_Receive remoteReceive_13;
// 主程序开始
void setup() {
tt_rgb.Init();
Serial1.begin(1000000, 23, 18, SERIAL_8N1);
led_effect_init();
remoteReceive_13.begin(13);
tt_rgb.SetRGB(0,0,255);
delay(1000);
protocol.startUntilControl();
}
void loop() {
mind_s_control = (remoteReceive_13.getIrCommand());
if ((mind_s_control==String("FD00FF"))) {
protocol.sendTelloCtrlMsg("land");
delay(1000);
mind_s_control = "0";
}
if ((mind_s_control==String("FD8877"))) {
protocol.sendTelloCtrlMsg((char *)String(String("forward ")+int(50)).c_str());
delay(1000);
mind_s_control = "0";
}
if ((mind_s_control==String("FD9867"))) {
protocol.sendTelloCtrlMsg((char *)String(String("back ")+int(50)).c_str());
delay(1000);
mind_s_control = "0";
}
if ((mind_s_control==String("FD28D7"))) {
protocol.sendTelloCtrlMsg((char *)String(String("left ")+int(50)).c_str());
delay(1000);
mind_s_control = "0";
}
if ((mind_s_control==String("FD6897"))) {
protocol.sendTelloCtrlMsg((char *)String(String("right ")+int(50)).c_str());
delay(1000);
mind_s_control = "0";
}
if ((mind_s_control==String("FD50AF"))) {
protocol.sendTelloCtrlMsg((char *)String(String("up ")+int(50)).c_str());
delay(1000);
mind_s_control = "0";
}
if ((mind_s_control==String("FD10EF"))) {
protocol.sendTelloCtrlMsg((char *)String(String("down ")+int(50)).c_str());
delay(1000);
mind_s_control = "0";
}
if ((mind_s_control==String("FD20DF"))) {
protocol.sendTelloCtrlMsg("flip l");
delay(1000);
mind_s_control = "0";
}
if ((mind_s_control==String("FD609F"))) {
protocol.sendTelloCtrlMsg("flip r");
delay(1000);
mind_s_control = "0";
}
if ((mind_s_control==String("FDA05F"))) {
led_effect_blink(255, 0, 0, 0, 255, 0, 2);
delay(1000);
mind_s_control = "0";
}
}
评论