回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

别越过那根线! 简单

头像 小怼怼 2021.01.09 775 0

我拿到传感器套装的时候,第一块拿起的传感器就是颜色传感器。我的脑海里面突然出现了星际穿越里面的一句话:不要温顺的走近哪个良夜.虽然不知道为什么会想起这个。但是还是有一点启发,那就让飞机不要飞越某种障碍吧。识别颜色的传感器,那就不要越过一根红色的“墙”吧。

材料清单

  • TT无人机 X1
  • 扩展件 X1
  • 颜色传感器 X1
  • 红色卡纸若干 X1

步骤1 组装

project-image

将RGB感光传感器用发泡胶固定在机身前方

project-image

近距离的看这个地方的固定

project-image

注意也是IIC的接口27,28的接口

project-image

对于剩下的接口需要再对接口进行焊接才可以启用,可以做更多的应用

步骤2 飞行场地的改造

因为对于颜色传感器开说,其有效识别距离太短。所以需要飞机很接近飞行表面。所以需要用泡沫板等轻质东西组建一个小围墙,在围墙的上方贴满红色卡纸。围墙高度为50厘米。

步骤3 编码

project-image
代码
/*!
 * MindPlus
 * telloesp32
 *
 */
#include <RMTT_Libs.h>
#include <DFRobot_TCS34725.h>

// 动态变量
volatile float mind_n_my_float_variable;
// 创建对象
RMTT_Protocol    protocol;
DFRobot_TCS34725 tcs34725;
RMTT_RGB         tt_rgb;


// 主程序开始
void setup() {
	Serial1.begin(1000000, 23, 18, SERIAL_8N1);
	tt_rgb.Init();
	delay(3000);
	protocol.startUntilControl();
	protocol.sendTelloCtrlMsg("motoron");
	protocol.sendTelloCtrlMsg("takeoff");
	protocol.sendTelloCtrlMsg((char *)String(String("down ")+int(20)).c_str());
	mind_n_my_float_variable = tcs34725.getRed();
	tcs34725.begin();
}
void loop() {
	protocol.sendTelloCtrlMsg((char *)String(String("left ")+int(50)).c_str());
	protocol.sendTelloCtrlMsg((char *)String(String("right ")+int(305)).c_str());
	if ((mind_n_my_float_variable==tcs34725.getRedToGamma())) {
		protocol.sendTelloCtrlMsg("stop");
		delay(1000);
		tt_rgb.SetRGB(255,0,0);
	}
}

步骤4 代码讲解

代码很简单,飞机起飞后会降落在一个合适的高度开始飞行,颜色传感器持续的对颜色做分辨,当分辨到红色的时候,向飞机下达停止并悬停的命令。

评论

user-avatar