5. Blockly
Blockly is a graphical programming tool that can be programmed to control the robotic arm by dragging and dropping code blocks without the need to write the code manually.
5.1 Interface Overview

- Run: Run the Blockly program.
- Pause: Pause the Blockly program.
- Convert to Python:Convert to Python code.
- Save:Save change to Blockly code.
- Zoom Log:Zoom in/out the log page.
- Zoom 3D Models:Zoom in/out the 3D models page.
- File Operation:new, import, download, copy, paste, rename, delete.
5.2 Blockly Workspace
![]()
- Reset Workspace: Reset to default workspace.
- Zoom In: Zoom in the code block.
- Zoom Out: Zoom out the code block.
Right Click Mouse Event in the Workspace
Right-click on the blank workspace of the non-code block, the function is mainly for all code blocks: 
- Undo: Undo the previous operation.
- Redo: Restore the last undo operation.
- Collapse Blocks: Collapse all code blocks.
- Expand Blocks: Display all collapsed commands.
- Delete 14 Blocks: Delete all code blocks.
Move/Wait/Edit
For some common functions of the motion commands:
- Move: The robotic arm will move to the current position
- Edit: The robotic arm will move to the current position and jump to the live control page.
- Wait (true/false): indicating whether to wait for the execution of a command before sending the next one.
5.3 Blockly Code Block
5.3.1 Settings
Set TCP speed: Set the speed of the linear motion in mm/s.
Set TCP acceleration: Set the acceleration of the linear motion in mm/s².
Set joint speed: Set the speed of joint movement in °/s.
Set joint acceleration: Set the acceleration of joint motion in °/s2. The default speed and acceleration values in the code block are the speed and acceleration values set currently, which can be modified manually.
Set tcp load() weigh() XYZ: Set the load of the current project, refer Settings-TCP Payload from the drop-down list.
Set tcp offset() XYZRPY: Set the end offset of the current project, reference Settings-TCP Offset from the drop-down list.
Set coordinate system offset() XYZRPY: Set the base coordinate offset of the current project. The drop-down list refers to the data of the Setting-Base Coordinate Offset.
Set collision sensitivity: Set collision detection sensitivity level.
Counter reset: This command resets the counter in the control box to 0.
Counter plus: Each time the command is run, the counter of the control box will be incremented by 1. It can be used to calculate the number of times the program actually cycles.
Get counter: Get the value of counter.
When counter (>)0 do: Execute when event.
5.3.2 Motion

Motion: With this command, operators can set the state of the robotic arm (movement, pause, stop). It is used to control the state of the robotic arm. It is mainly used in condition-triggered programs.
Emergency stop: The robotic arm immediately stops moving and clears the command cache.
Zero position: The robotic arm returns to a posture where the joint value are 0.
Align: Align the head.
Joint motion: Set each joint value for the joint movement, with the unit of degree.
Linear motion: Set the Cartesian coordinate target value of the linear motion and the TCP rotation angle in mm and °.
Move (forward)()mm wait(): Indicates that the robotic arm makes relative linear motion forward/backward/left/right based on the current position, in mm.
Move tool line XYZRPY: This command is a relative motion relative to TCP coordinates.
Get position(Euler Angle)(): Get the current TCP position of the robotic arm. The first dropdown menu selects the orientation representation: Euler angles or axis-angle representation. The second dropdown menu selects the component to retrieve: X, Y, Z, Roll, Pitch, and Yaw for Euler angles, or X, Y, Z, Rx, Ry, and Rz for axis-angle representation. The position is expressed in mm, and the orientation is expressed in °.
Get joint angle(): Get the current angle of the specified joint. Select the joint whose angle you want to retrieve. The angle is expressed in °.
Move circle: From current position, the whole circle is determined by current position and position1 and positon2, 'center angle'”' specifies how much of the circle to execute.
center angle:Indicates the degree of the circle. When it is set to 360, a whole circle can be completed, and it can be greater than or less than 360; (Note: To achieve smooth track motion, you need to set Wait = false).
Motion with Variable: The command passes through the Cartesian motion and supports variable values. 
5.3.3 IO
5.3.3.1 Controller IO
The IO interface is made up of a control box interface and an end tool interface, which can be used to acquire, set, and monitor IO interface operations.
The control box has 16 digital input, 16 digital output, 2 analog input and 2 analog output.
The end tool has 2 digital input, 2 digital output, 2 analog input and 2 analog output.
The control box digital IO is low-level-triggered.
The end tool digital IO is high-level-triggered.

Get CI(0): Get the value of CI0–CI7. Returns: 0 or 1.
Get DI(0): Get the value of DI0–DI7. Returns: 0 or 1.
Set CO(0) to (LOW), Sync (True): Set CO0–CO7 to LOW or HIGH. Click Set to execute the command individually. Parameter: Sync is used to set the synchronous or asynchronous execution mode of digital and analog output commands. When set to True, the IO command is executed synchronously: it is added to the command sequence and executed in order. When set to False, the IO command is executed asynchronously and takes effect immediately. The default value is True.
Set DO(0) to (LOW), Sync (True): Set DO0–DO7 to LOW or HIGH. Click Set to execute the command individually. Parameter: Sync is used to set the synchronous or asynchronous execution mode of digital and analog output commands. When set to True, the IO command is executed synchronously: it is added to the command sequence and executed in order. When set to False, the IO command is executed asynchronously and takes effect immediately. The default value is True.
Get AI(0): Get the value of AI0 and AI1. Returns: 0–3 V.
Set AO(0), Sync (True): Set the values of AO0 and AO1. Range: 0–10 V. Parameter: Sync is used to set the synchronous or asynchronous execution mode of digital and analog output commands. When set to True, the IO command is executed synchronously: it is added to the command sequence and executed in order. When set to False, the IO command is executed asynchronously and takes effect immediately. The default value is True.
CI0–CI7 are (HIGH/LOW), timeout (3): Check the values of CI0–CI7. When the specified conditions are met, execute the event. If the conditions are still not met after the timeout period of 3 s, execute the next code block.
DI0–DI7 are (HIGH/LOW), timeout (3): Check the values of DI0–DI7. When the specified conditions are met, execute the event. If the conditions are still not met after the timeout period of 3 s, execute the next code block.
Position Trigger:
set I/O when(X, Y, Z, tolerance): When the robotic arm reaches the specified position (the area of the sphere specified with the trigger position point (X, Y, Z) as the center (the radius of the sphere is the tolerance radius)), IO is triggered. This command can be used to trigger IO at a specific location. X, Y, Z represent the coordinate value of the specified position to be reached by the robot arm, with the unit of mm. The digital IO is triggered as soon as the system detects that the TCP position enters a spherical area centered at (X, Y, Z) with the specified radius. If the tolerance radius is not set, when the robotic arm passes the specified point at a speed other than 0, it may miss the trigger because it cannot be accurately detected.
Event:
When the analog IO value satisfies the set condition do: When the monitored analog IO value meets the condition, the commands contained in the code block will be executed, and the condition are =, ≠, >, ≥, <, ≤.
5.3.3.2 Tool IO
Similar to Controller IO.
5.3.4 Tool
Gripper
Set the position and the opening and closing speed of the gripper. 

Gripper G2
Set the position and the opening and closing speed and the force of the gripper g2.position: -10-850, speed: 1000-5000, force: 1-100 
BIO Gripper
Initialize the BIO Gripper, set BIO Gripper, object is picked by BIO Gripper.
The gripper must be initialized before use. Speed: 200-2400 
BIO Gripper G2
Initialize the BIO Gripper G2, set BIO Gripper G2, set BIO Gripper G2 (variable), object is picked by BIO Gripper G2.
The gripper must be initialized before use. position: 71-150, speed: 500-4000, force: 1-100 
Robotiq Gripper
Initialize Robotiq gripper, set robotiq gripper pos and force. 
Vacuum Gripper
Get Vacuum gripper state: 0/1. 0: Picked 1: Release Object is (picked) timeout(): wait until timeout 
DH-PGC Gripper
Initialize the DH-PGC gripper, set DH-PGC gripper, object is picked by DH-PGC gripper.
The gripper must be initialized before use. position: 0-1000, speed: 1-100, force: 20-100 
INS-RH56DFX
Set INS-RH56DFX Hand, set INS-RH56DFX Finger.
Position: 0-1000, speed: 0-1000, force: 0-1000 
5.3.5 Externals
Direct Drive Linear Motor
Set Linear Motor: Speed, position. 
Modbus RTU
Get/Set Standard Modbus RTU command: Robot Arm, Control Box, it will add CRC automatically. 
For example: Set xArm Gripper to pos=600, and get the current pos. 
Transparent Transmission
Get/Set RS-485 port transparent command: the Robot Arm or Control Box communicates with the connected device over RS-485, and the data is only forwarded, not processed. 
For example: control the gripper, and get the current position. 
Torque Sensor
Get/Set torque sensor force control. Direction: Fx, Fy, Fz, Tx, Ty, Tz Value: Fx(-105,105), Fy(-105,105), Fz(-140,140) TxTyTz(-2.8,2.8)
Modbus TCP
Definition of register please refer to: Modbus TCP. Set holding register address () to (): write a value to the holding register at the specified address, click 'set' to run the command.
Get holding register address () Data Type (): get the value of the holding register at the specified address. The data type determines how the returned value is parsed. The default value is HEX.
- HEX: output the raw register data in hexadecimal, 2 bytes, e.g. FF FE.
- INT 16(DEC): parse as a signed 16-bit integer, range -32768~32767, e.g. FF FE is displayed as -2.
- UINT 16(DEC): parse as an unsigned 16-bit integer, range 0~65535, e.g. FF FE is displayed as 65534.
When holding register address () is () do: the event is triggered when a change of the value of the register address is detected.
For example, set register address 01 A0 as 12 34, it will trigger linear motion. 
5.3.6 Import
Import the trajectory/Blockly file and set the times of executions. Copy Blockly Codes. 
5.3.7 Logic
Wait: Wait seconds and send next commands. 
If() do():
- Click the setting button on the command block, then the command block will pop up a selection box;
- At this point, drag the 'else' code block to the bottom of the 'if' code block, and combine the two code blocks;
- Click the setting button, the selection box is retracted, if/else sentence setting is completed.

5.3.8 Loop
Forever: The command contained in the loop will be executed in infinite loop.
Repeat() times do: The command contained in the loop will be executed X times.
Repeat while/until do: When the condition is not met, it jumps out of the loop.
Break: Terminate the loop. 
5.3.9 Math
You can use the above code block to do some complex operations such as addition, subtraction, multiplication, and division, exponential operations.
5.3.10 Advance
Text
Remark: Remark the code block, which serves as an indicator and can change the color.
Message type: Types available are: (information/success/warning/error), duration indicates the time interval the message is displayed, the unit is in second; the message indicates the content of the prompt message.
String printing[]: Users can print the entered string below and set the font and the color.
Variable printing: Users can print the added variable and set the font and the color.
Date: The date and time on which the command was run can be output.
Python Code: You can write custom python code to turn it into a block in Blockly and use it in your program
Variable
New variables can be added. After adding a variable, there are three commands by default (set the value of the variable, change the value of the variable by adding or subtracting, variable).
Function
to (do something): Users can define a new function without a return value.
to (do something) return []: Users can define a new function with a return value.
if [] return []: Conditional judgment sentence that can only be placed in the built-in function.
Note: The defined function should be placed in front of the main programs.
5.4 Python IDE
Python IDE is a Python development integration environment that can directly use xArm-Python-SDK API and check the Blockly projects converted into Python code. 