【课程引入】
疫情期间需要减少接触,可是万一遇到有人进入小区找不到路又看不懂路牌怎么办呢?这时候无人机就可以发挥大用场了,我们可以使用二哈摄像头给TT加上眼睛,让它能够认人并且认路,做一个空中“引路人”
【教学目标】
1、学会使用编程控制二哈摄像头
2、能够使无人机完成人脸识别引路功能
【任务要求】
使用mind+给TT编程,并使用二哈摄像头使TT能够人脸识别,并将对象带到指定地点。
材料清单
- Gravity HUSKYLENS 人工智能摄像头 X1 链接
步骤1 设计路线
步骤2 制作流程图
步骤3 将人工智能摄像头连接到TT上
步骤4 编写代码
代码
/*!
* MindPlus
* telloesp32
*
*/
#include <RMTT_Libs.h>
#include <DFRobot_HuskyLens.h>
// 动态变量
volatile float mind_n_ShiBieCiShu;
// 创建对象
DFRobot_HuskyLens huskylens;
RMTT_Protocol protocol;
RMTT_RGB tt_rgb;
// 主程序开始
void setup() {
Serial1.begin(1000000, 23, 18, SERIAL_8N1);
tt_rgb.Init();
led_effect_init();
huskylens.beginI2CUntilSuccess();
huskylens.writeAlgorithm(ALGORITHM_FACE_RECOGNITION);
protocol.startUntilControl();
protocol.sendTelloCtrlMsg("takeoff");
mind_n_ShiBieCiShu = 0;
}
void loop() {
huskylens.request();
if ((huskylens.isAppear(1,HUSKYLENSResultBlock) && (mind_n_ShiBieCiShu==0))) {
led_effect_blink(255, 0, 0, 0, 0, 255, 1);
protocol.sendTelloCtrlMsg((char *)String(String("forward ")+int(500)).c_str());
delay(1000);
protocol.sendTelloCtrlMsg((char *)String(String("forward ")+int(150)).c_str());
protocol.sendTelloCtrlMsg((char *)String(String("ccw ")+int(90)).c_str());
mind_n_ShiBieCiShu += 1;
huskylens.request();
}
if ((huskylens.isAppear(1,HUSKYLENSResultBlock) && (mind_n_ShiBieCiShu==1))) {
protocol.sendTelloCtrlMsg((char *)String(String("forward ")+int(200)).c_str());
protocol.sendTelloCtrlMsg((char *)String(String("ccw ")+int(90)).c_str());
mind_n_ShiBieCiShu += 1;
huskylens.request();
}
if ((huskylens.isAppear(1,HUSKYLENSResultBlock) && (mind_n_ShiBieCiShu==2))) {
protocol.sendTelloCtrlMsg((char *)String(String("forward ")+int(500)).c_str());
delay(1000);
protocol.sendTelloCtrlMsg((char *)String(String("forward ")+int(200)).c_str());
protocol.sendTelloCtrlMsg((char *)String(String("cw ")+int(90)).c_str());
mind_n_ShiBieCiShu += 1;
huskylens.request();
}
if ((huskylens.isAppear(1,HUSKYLENSResultBlock) && (mind_n_ShiBieCiShu==3))) {
led_effect_breath(0, 255, 0, 1);
protocol.sendTelloCtrlMsg("land");
huskylens.request();
}
}
评论