RoArm-M2-S FLASH File System Operation

From Waveshare Wiki
Jump to: navigation, search

FLASH File System Operation

The slave board used by the robotic arm loses data after power-off. To save certain data and prevent it from being lost during power off, you can write this data into a file and store it in the Flash file system. Simply write the file to Flash before power-off, ensuring the file remains intact after power is restored, and then read the file upon powering up.

The JSON commands in this chapter are designed for manipulating files stored in the ESP32 FLASH, including scanning files, creating new files, editing file content, and reading file content. Files are retained even after power-off. If you re-upload the demo to RoArm-M2-S, you can also choose to save Flash files in the Arduino IDE.


Scan FLASH Files

{"T":200}
  • 200: indicates this command is CMD_SCAN_FILES for scanning all file folders of the current Flash file system.

The returned data is shown below:

>>>---=== File Name and First line ===---<<<
[file]: [boot.mission]
[first line]:
{"name":"boot","intro":"these cmds run automatically at boot."}
>>>---=== File Name and First line ===---<<<
[file]: [mission_a.mission]
[first line]:
{"name":"mission_a","intro":"test mission created in flash."}
>>>---=== File Name and First line ===---<<<
[file]: [wifiConfig.json]
[first line]:
{"wifi_mode_on_boot":3,"sta_ssid":"JSBZY-2.4G","sta_password":"waveshare0755","ap_ssid":"RoArm-M2","ap_password":"12345678"}

The returned values include the file name of each file folder and the first line of contents. This file folder will display the full file name. If you create a new file with a suffix, it will be displayed too. Files with the suffix .mission are mission files, which can store some commands for batch operation of the robotic arm.

  • boot.mission: the task file that can automatically run after booting the robotic arm. If there is no file like this after startup, it will automatically generate one. All the rest of the JSON commands can be added to this file to configure the steps that need to be executed automatically after powering up;
  • mission_a.mission is the case of testing the generated task file, which does not represent the mission_a.mission file is on RoArm-M2.
  • wifiConfig.json is for storing WiFi-related configuration files. If the file is not scanned after startup, it will automatically generate and set a hotspot in the default AP mode. For more details, you can refer to RoArm-M2-S WIFI Configuration.

New File Folder

{"T":201,"name":"file.txt","content":"inputContentHere."}
  • 201: indicates this command is CMD_CREATE_FILE for creating a file folder.
  • name: the file name to be created, which must be input the full file name. If you want to create a file with the suffix, the suffix must be ".txt" as shown above.
  • content: the content of the first line in the file.

Read the File Content

{"T":202,"name":"mission_a.mission"}
  • 202: indicates this command is CMD_READ_FILE for reading a file content.
  • name: the file name to be read. The full filename must be entered, if you created the file with a suffix, the filename must include the suffix.

The return content is as follows, the return content will be labeled out the line number (the following is an example, it does not mean that you will have the file mission_a.mission in your RoArm-M2):

{"T":202,"name":"mission_a.mission"}

---=== '''File Content '''===---
reading file: [mission_a.mission] starts:
[lineNum: 1 ] - {"name":"mission_a","intro":"test mission created in flash."}
[lineNum: 2 ] - {"T":104,"x":235,"y":0,"z":234,"t":3.14,"spd":0.25}
[lineNum: 3 ] - {"T":104,"x":104.3172406,"y":-112.6415887,"z":65.13450799,"t":2.448233337,"spd":0.25}
[lineNum: 4 ] - {"T":114,"led":155}
[lineNum: 5 ] - {"T":104,"x":-163.7763876,"y":-138.2353466,"z":105.0922663,"t":2.466641107,"spd":0.5}
[lineNum: 6 ] - {"T":114,"led":0}
[lineNum: 7 ] - {"T":114,"led":255}
[lineNum: 8 ] - {"T":104,"x":156.428798,"y":40.20501586,"z":76.68339473,"t":3.052621768,"spd":0.25}
[lineNum: 9 ] - {"T":111,"cmd":3000}
[lineNum: 10 ] - {"T":114,"led":0}
[lineNum: 11 ] - {"T":1,"mode":1}
^^^ ^^^ ^^^ reading file: mission_a.mission ends. ^^^ ^^^ ^^^

The actual file contents in the mission_a.mission file are as follows:

{"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}

Delete File

{"T":203,"name":"file.txt"}
  • 203: this command is CMD_DELETE_FILE for deleting the specified file.
  • name: the file name to be deleted, and you need to input the full file name here.

Edit FLASH File

Add The New Content At the End of File

{"T":204,"name":"file.txt","content":"inputContentHere."}
  • 204: This command, CMD_APPEND_LINE, is used to add a line of input to the end of the specified file.
  • name: The name of the file to be edited must be entered in full.
  • content: The content to be added.

Inserts Content at A Specified Number of Lines

{"T":205,"name":"file.txt","lineNum":3,"content":"content"}
  • 205: this command is CMD_INSERT_LINE for inserting a line in the specified line of the designated file.
  • name: the file name to be edited, and you need to input the full file name.
  • lineNum: Specify the line number for inserting new content. The first line of the file is considered line number 1. For example, if the lineNum is set to 3, the original third line will become the fourth line, and the newly added content will be inserted as the third line.
  • content: the content to be inserted.

Replace the Content of the Specified Line

{"T":206,"name":"file.txt","lineNum":3,"content":"Content"}
  • 206: this command is CMD_REPLACE_LINE for replacing the content of the specified line in the specified file.
  • name: the file name to be edited, which should be edited as the full file name with a suffix.
  • lineNum: Specify the line number of the content to be replaced. For example, the lineNum value here is 3, it represents the content of the third line that will be replaced.
  • content: the content to be replaced.

Read the Content of the Specified Line Number

{"T":207,"name":"file.txt","lineNum":3}
  • 207: this command is CMD_READ_LINE for reading the content of the specified line number in the specified file folder.
  • name: the file name to be read, which should be input the full file name.
  • lineNum: the specified line number to be read.

Delete the Content of the Specified Line in the File

{"T":208,"name":"file.txt","lineNum":3}
  • 208: this command is CMD_DELETE_LINE for deleting the content of the specified line number of the specified file.
  • name: the file name to be edited, which should be input the full file name.
  • lineNum: the line number to be deleted. For example, the lineNum is 3 meaning the original third line will be deleted and the content of the subsequent lines will shift up by one line.

RoArm-M2-S Tutorial Directory

RoArm-M2-S ROS2 Humble + Moveit2 Tutorial

M2-S ROS2Humblemian-1.png

RoArm-M2-S User Tutorial