Skip to content

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

  1. Run: Run the Blockly program.
  2. Pause: Pause the Blockly program.
  3. Convert to Python:Convert to Python code.
  4. Save:Save change to Blockly code.
  5. Zoom Log:Zoom in/out the log page.
  6. Zoom 3D Models:Zoom in/out the 3D models page.
  7. File Operation:new, import, download, copy, paste, rename, delete.

5.2 Blockly Workspace

  1. Reset Workspace: Reset to default workspace.
  2. Zoom In: Zoom in the code block.
  3. 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:

  1. Undo: Undo the previous operation.
  2. Redo: Restore the last undo operation.
  3. Collapse Blocks: Collapse all code blocks.
  4. Expand Blocks: Display all collapsed commands.
  5. Delete 14 Blocks: Delete all code blocks.

Move/Wait/Edit For some common functions of the motion commands:

  1. Move: The robotic arm will move to the current position
  2. Edit: The robotic arm will move to the current position and jump to the live control page.
  3. 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.

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): Acquire the I/O interface data of the code block.
set CO(0): Set the I/O interface of the code block, click 'set' to run the command.

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.

when digital I/O is (High/Low) do: Executes the commands contained in this code block when the condition is met.

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.

BIO Gripper
Open/Close BIo Gripper.

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

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.

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. When detects the value is changed, trigger the event. 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.