RoboMaster TT 无人机microPython编程.2



还记得我们说的读取上次的状态吗,这个就是所有上次的状态
print(protocol.getTelloStatusWithName("temph")) print(protocol.getTelloMsgInt("[TELLO] mid?",1000))一个方法是打印我们上次的状态里面 的子项
一个是单纯的发送命令
pitch:%d;roll:%d;yaw:%d;vgx:%d;vgy%d;vgz:%d;templ:%d;temph:%d;tof:%d;h:%d;bat:%d;baro:%f;\r\n其实状态一次会返回这么多,只不过是我们对其中感兴趣的进行抽取

在SDK里面标有mid的命令需要搭配挑战卡一起使用

我们来看发送命令和相关的一些内容
protocol.sendTelloCtrlMsg("go "+str(int(50))+" "+str(int(50))+" "+str(int(0))+" "+str(int(100))) uart1.write("DIY yyy") print(protocol.getTelloMsgString("[TELLO] sn?",1000)) while not (protocol.getTelloResponseString(1000)=="DIY T"): protocol.sendTelloCtrlMsg()这种的叫控制命令的发送
int RMTT_Protocol::sendTelloCtrlMsg(char *cmd_str){ re_cnt = 0; while (true) { while (Serial1.available()) { Serial1.read(); } Serial1.printf("[TELLO] Re%02x%02x %s", re_tag, re_cnt++, cmd_str); // Serial.printf("[TELLO] Re%02x%02x %s", re_tag, re_cnt++, cmd_str); long oldtime = millis(); while (!Serial1.available()) { long newtime = millis(); if ((newtime - oldtime) > 1000) { Serial1.printf("[TELLO] Re%02x%02x %s", re_tag, re_cnt++, cmd_str); // Serial.printf("[TELLO] Re%02x%02x %s", re_tag, re_cnt++, cmd_str); oldtime = newtime; } }
String back; while (Serial1.available()) { back += String(char(Serial1.read())); }
// ETT Re[tag][id] ok/error // ETT Rexxxx ok/error // Serial.printf(back.c_str()); if (back.length() >= 12) { if ((back.c_str()[11] == 'o') && ((back.c_str()[12] == 'k'))) { break; } } else { delay(100); } } re_tag++; return 0;}python的找不到了,可以找一个C++的版本。


死循环的话就是不停的发送里面的命令,此处我们需要发送俩类:
发给TT本身的
发给扩展件的

发送给TT的命令,又分为两种:
发送成功的
发送失败的

这个地方有点没有看懂,如果是串口有了字符,便读取
接下来是一个打印,其实这里看写法是,一个是debug用的
对于扩展件来说,打印就是给下面的接收器发送
Serial1.printf("[TELLO] Re%02x%02x %s", re_tag, re_cnt++, cmd_str);上面中间的这个re我看不懂

这个是格式

这里是一段读取失败的处理代码
先最一开始获取从开机到现在的时间,内部是目前的运行时间
如果这个差大于1000ms,就是继续发送命令。接着把时间位更新

新建一个串,从serial1读取字符加到string里面

这个是Tello发给ESP32的
看样子最多12位,后面两位是ok
10位是接收数据位

再看这个 ETT ok(10-4=6)位(\r\n)(6-4=2)
其实我觉得,发回来的是一个数字的信息。这样设计会好一些

uart1.write("DIY yyy")自定义的命令是DIY空格+命令
print(protocol.getTelloMsgString("[TELLO] sn?",1000))这个命令是查询TT的SN,下面是接收的函数
String RMTT_Protocol::getTelloMsgString(char *cmd, uint32_t timeout){ while (Serial1.available()) { Serial1.read(); } String back; Serial1.printf(cmd); long oldtime = millis(); while (!Serial1.available()) { long newtime = millis(); if ((newtime - oldtime) > timeout) { back = "timeout"; return back; } } while (Serial1.available()) { back += String(char(Serial1.read())); } if (back.endsWith("\r\n")) { back = back.substring(0, back.indexOf("\r\n")); } return back;}
"[TELLO] sn?"发送这个串给飞机

这个函数先判断串口是不是有数据
接着创建串
然后把上面的串发出去

然后一段代码来判断是不是读取超时

接着就读这个数据,读到back里面
然后判断是不是\r\n结尾

然后是的话,就去掉结尾然后返回back
protocol.getTelloMsgString("[TELLO] sn?",1000)1000是超时参数

这个积木会使用所有的引脚模块
from machine import Pin, PWM
p13 = Pin(13, Pin.IN)
pwm13 = PWM(Pin(13))
p13.value(1)pwm13.duty(200)while True: while not ((p13.value())): pass
老实讲,我觉得扩展性非常差。如果就用积木的话
而且看库的导入情况,只用用到了自身的库
赞 (0)
