RoArm-M2-S Step Recording and Reproduction

From Waveshare Wiki
Jump to: navigation, search

Step Recording & Reoriduction

You can achieve recording and reproduction of steps for the robotic arm by configuring task files stored in the ESP32's Flash file system with the .mission format. In the task file, you can store various JSON commands to enable batch recording and reproduction of JSON instructions.
The JSON commands in this chapter are designed to operate task files stored in the ESP32 FLASH, including creating new task files, reading file content, editing task file content, etc. It enables multifunctional automation operations for the robotic arm.
Note: The distinction between this chapter and RoArm-M2-S_FLASHA file system operations is that this chapter is exclusively used for configuring task files, while FLASH file system operations can be applied to all files.

Create Mission File

{"T":220,"name":"mission_a","intro":"test mission created in flash."}
  • 220: This command is CMD_CREATE_MISSION for creating a new mission file.
  • name: the name of the mission file to be created.
  • intro: the brief introduction of this mission file.

Note: the operation on the related mission file is mostly based on the function package of the FLASH file system. In this chapter, there is no need to input the file names with the '.mission' file extension.

Read the Content of the Mission File

{"T":221,"name":"mission_a"}
  • 221: This command is CMD_MISSION_CONTENT for reading the specific content of the mission file.
  • name: the name of the mission file to be read.

The mission file read is mission_a.mission, and the return value is shown below:

{"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. ^^^ ^^^ ^^^

Note: the content of the first line in the mission file is the name and the brief introduction of the mission file. the first JSON command to be executed starts from the second line, and the above content read will be labeled out the number of each step.
The content of the actual mission file is shown below:

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

Edit Mission File

Add New JSON Command at the End of the Mission File

{"T":222,"name":"mission_a","step":"{\"T\":104,\"x\":235,\"y\":0,\"z\":234,\"t\":3.14,\"spd\":0.25}"}
  • 222: This command is CMD_APPEND_STEP_JSON, which is used to directly add the new JSON command at the end of the specified mission file.
  • name: The name of the mission file to be edited.
  • step: The new JSON command to be added. The above case adds the command {"T":104,"x":235,"y":0,"z":234,"t":3.14,"spd":0.25}. Note that each new JSOM command should add "\" before. For the specific format to be added, you can refer to the above cases.

Entering this command outputs the original contents of the task file and the contents of the new file with the addition of the JSON command.

Add New JSON Command Moving to the Current Position At the End of the File

{"T":223,"name":"mission_a","spd":0.25}
  • 223: This command is CMD_APPEND_STEP_FB. Using this command, the robotic arm will set its current position as the target position, generate a JSON command to move to the current position and add this command to the end of the mission file.
  • name: the mission file name to be edited.
  • spd: the speed for the robotic arm moving to the target position.

After inputting this command, the robotic arm will output the current position, and the new content of the JSON command is added to the mission file.

Add the New Delay Command at the End of the Mission File

{"T":224,"name":"mission_a","delay":3000}
  • 224: This command is CMD_APPEND_DELAY for delaying the steps of the mission file.
  • name: The mission file name to be edited.
  • delay: Set the delay time in ms.

After inputting this command, a new delay command will be added at the end of the mission file.

Insert the New JSON Command in the Mission File

{"T":225,"name":"mission_a","stepNum":3,"step":"{\"T\":114,\"led\":255}"}
  • 225: this command is CMD_INSERT_STEP_JSON, which means inserting the new JSON command at the specified step in the mission file.
  • name: the mission file name to be edited.
  • stepNum: the specified step numbers. For example, by setting stepNum as 3, the new command will be inserted at step 3, and executed at step 3.
  • step: the new JSON command to be inserted. The above case adds the command {"T":114,"led":255}. Note that each new command should be added "\" before ". For the format to be added, you can refer to the above case.

Note: In this command and the following commands, the given stepNum value is the step numbers of JSON command to be executed rather than the line numbers, that is, the JSON command to be executed at step 3 of the mission file is displayed as line 4.

Insert the JSON Command of Moving to the Current Position In the File

{"T":226,"name":"mission_a","stepNum":3,"spd":0.25}
  • 226: This command is CMD_INSERT_STEP_FB. Using this command, the robotic arm will set the current position as the target position and generate a JSON command for moving to this current position, which will be inserted in the specified step of the mission file.
  • name: the mission file name to be edited.
  • stepNum: specify the step number. For example, set stepNum as 3, the new JSON command will be inserted at step 3 and will be executed at step 3.
  • spd: set the speed that the robotic arm moves to this target.

Add New Delay Command in the Mission File

{"T":227,"name":"mission_a","stepNum":3,"spd":3000}
  • 227: This command is CMD_INSERT_DELAY for inserting the new delay command in the specified mission file in the mission file.
  • name: The name of the mission file to be edited.
  • stepNum: Specifies the number of steps. For example, when stepNum is set to 3, a new JSON instruction is inserted at step 3, and the newly inserted delay instruction is executed at step 3.
  • spd: Set delay time in ms.

Replace One Step Command in the Mission File

{"T":228,"name":"mission_a","stepNum":3,"step":"{\"T\":114,\"led\":255}"}
  • 228: This command is CMD_REPLACE_STEP_JSON, which is to replace the specified subsequent line with the new inserting JSON command.
  • name: the mission file name to be edited.
  • stepNum: The specified step numbers. For example, when stepNum is set as 3, the new JSON command will be inserted at step 3, and be executed as step 3.
  • step: The new JSON command to be inserted. The above case adds the command {"T":114,"led":255}. Note that each new JSON command should be added \ before ". For the format to be added, please refer to the above cases.

Replacing a Step in a Task File with a Movement-to-current-position Command

{"T":229,"name":"mission_a","stepNum":3,"spd":0.25}
  • 229: This command is CMD_REPLACE_STEP_FB. Using this command, the robotic arm will automatically set its current position as the target position to generate a new command. It will then replace the content of the specified step in the task file with this new command. You need to set a speed for this position.
  • name: the name of the mission file to be edited.
  • stepNum: the specified step numbers. For example, stepNum is set as 3, and the new JSON command is inserted at step 3 and is executed at step 3.
  • spd: set the speed of the robotic arm moving to the target position.

Replace the Command of One Step with the New Delay Command

{"T":230,"name":"mission_a","stepNum":3,"delay":3000}
  • 230: This command is CMD_REPLACE_DELAY, which is used to replace the content of the specified step in the mission file with the new delay command.
  • name: the name of the mission file to be edited.
  • stepNum: Specify the step numbers. For example, when stepNum is set to 3,
  • delay: delay time in ms.

Delete One Step In the Mission File

{"T":231,"name":"mission_a","stepNum":3}
  • 231: This command is CMD_DELETE_STEP for deleting one step in the mission file.
  • name: The name of the mission file to be edited.
  • stepNum: The specified step numbers.

Execute the Comamnd of One Step in the Mission File

{"T":241,"name":"mission_a","stepNum":3}
  • 241: This command is CMD_MOVE_TO_STEP for executing the specified step in the mission file.
  • name: The name of the mission file to be edited.
  • stepNum: The specified step number to be executed.

Note: Whether this function causes blocking depends on the specific commands. If you execute inverse kinematics control that causes blocking, then this function will cause blocking.

Play the Mission

{"T":242,"name":"mission_a","times":3}
  • 242: This command is CMD_MISSION_PLAY for playing all the JSON commands in the mission file, and can be run in loops.
  • name: the name of the mission file to be played.
  • times: The number of loops to be played, is infinite when the value is -1.

During playback, the process can exit as soon as the serial port receives any new signal and the currently executing command is completed.

RoArm-M2-S Tutorial Directory

RoArm-M2-S User Tutorial

RoArm-M2-S ROS2 Basic Tutorial