想让机械臂实现步骤的录制和重现,可以通过对存储在ESP32的Flash文件系统中格式为.mission的任务文件进行操作来实现。在任务文件中,可以存储不同的JSON指令,来实现JSON指令批量化地录制和重现。
本章的JSON指令用于操作存储在ESP32 FLASH中的任务文件,包括新建任务文件、读取文件内容、编辑任务文件内容等。可以实现机械臂多功能自动化操作。
注意:本章与RoArm-M2-S_FLASHA文件系统操作的区别在于,本章仅用来对任务文件进行操作,而FLASH文件系统操作可以对所有的文件进行操作。
{"T":220,"name":"mission_a","intro":"test mission created in flash."}
注意:有关任务文件的操作大部分基于FLASH文件系统操作的函数封装而来,因此在本章节中输入的文件名都不需要格外输入带“.mission”文件后缀的名称。
{"T":221,"name":"mission_a"}
读取到的任务文件为mission_a.mission,返回值如下:
{"T":221,"name":"mission_a"}
---=== File Content ===---
reading file: [mission_a] starts:
{"name":"mission_a","intro":"test mission created in flash."}
[StepNum: 1 ] - {"T":104,"x":235,"y":0,"z":234,"t":3.14,"spd":0.25}
[StepNum: 2 ] - {"T":104,"x":104.3172406,"y":-112.6415887,"z":65.13450799,"t":2.448233337,"spd":0.25}
[StepNum: 3 ] - {"T":114,"led":155}
[StepNum: 4 ] - {"T":104,"x":-163.7763876,"y":-138.2353466,"z":105.0922663,"t":2.466641107,"spd":0.5}
[StepNum: 5 ] - {"T":114,"led":0}
[StepNum: 6 ] - {"T":114,"led":255}
[StepNum: 7 ] - {"T":104,"x":156.428798,"y":40.20501586,"z":76.68339473,"t":3.052621768,"spd":0.25}
[StepNum: 8 ] - {"T":111,"cmd":3000}
[StepNum: 9 ] - {"T":114,"led":0}
[StepNum: 10 ] - {"T":1,"mode":1}
^^^ ^^^ ^^^ reading file: mission_a.mission ends. ^^^ ^^^ ^^^
注意:任务文件的第一行内容为任务文件的名称和简要介绍,从第二行起才是需要执行的第一步JSON指令,上述读取到的内容会标注出来每个步骤的序号。
实际该任务文件案例的内容如下:
{"name":"mission_a","intro":"test mission created in flash."}
{"T":104,"x":235,"y":0,"z":234,"t":3.14,"spd":0.25}
{"T":104,"x":104.3172406,"y":-112.6415887,"z":65.13450799,"t":2.448233337,"spd":0.25}
{"T":114,"led":155}
{"T":104,"x":-163.7763876,"y":-138.2353466,"z":105.0922663,"t":2.466641107,"spd":0.5}
{"T":114,"led":0}
{"T":114,"led":255}
{"T":104,"x":156.428798,"y":40.20501586,"z":76.68339473,"t":3.052621768,"spd":0.25}
{"T":111,"cmd":3000}
{"T":114,"led":0}
{"T":1,"mode":1}
{"T":222,"name":"mission_a","step":"{\"T\":104,\"x\":235,\"y\":0,\"z\":234,\"t\":3.14,\"spd\":0.25}"}
输入该指令后,会输出任务文件的原始内容和增加了JSON指令后的新文件内容。
{"T":223,"name":"mission_a","spd":0.25}
输入该指令后,机械臂会输出当前机械臂所处位置的信息,且输出任务文件的原始内容和增加了JSON指令后的新文件内容。
{"T":224,"name":"mission_a","delay":3000}
输入该指令后,会在任务文件的末尾添加一条新的延时指令。
{"T":225,"name":"mission_a","stepNum":3,"step":"{\"T\":114,\"led\":255}"}
注意:在本条指令和后续指令中,给的stepNum值是为JSON指令执行的步数,而非行数。也就是说,如果给定的stepNum值为3,则在该任务文件中为第3步要执行的JSON指令,但是显示为第4行。
{"T":226,"name":"mission_a","stepNum":3,"spd":0.25}
{"T":227,"name":"mission_a","stepNum":3,"spd":3000}
{"T":228,"name":"mission_a","stepNum":3,"step":"{\"T\":114,\"led\":255}"}
{"T":229,"name":"mission_a","stepNum":3,"spd":0.25}
{"T":230,"name":"mission_a","stepNum":3,"delay":3000}
{"T":231,"name":"mission_a","stepNum":3}
{"T":241,"name":"mission_a","stepNum":3}
注意:该函数是否阻塞取决于具体命令是否会引发阻塞。如果您要执行的是机械臂逆运动学控制引发阻塞的指令,则该函数会进程阻塞。
{"T":242,"name":"mission_a","times":3}
播放的过程中,当串口接收到任何新信号后,并且当目前执行的指令运行完成后,即可退出播放。