Skip to content

JSON-RPC API User Guide

1. JSON-RPC Protocol Description

1.1 Overview

JSON-RPC (JavaScript Object Notation Remote Procedure Call) is a remote procedure call protocol. It uses JSON as the data format and can communicate between clients and servers via transmission protocols such as TCP Socket, HTTP, WebSocket, etc. The JSON-RPC protocol features simplicity, lightweight, cross-language, cross-platform, and support for multiple transmission protocols.

JSON-RPC uses a request-response model to implement remote procedure calls between clients and servers. The client sends a JSON-formatted request to the server, such as {"jsonrpc":"2.0","method":"getRobotNames","params":[],"id":1}. The server receives the request, parses the JSON object, and extracts the values of fields like “method”, “params”, and “id”. The server executes the method corresponding to "method" using the provided parameters. Based on the execution result, the server generates a response object and serializes it into JSON format, such as {"id":1,"jsonrpc":"2.0","result":["rob1"]}, and then sends the JSON-formatted response back to the client. Finally, the client receives the response sent by the server.

1.2 Supported Transmission Protocols and Port Numbers

JSON-RPC supports HTTP, WebSocket, and TCP Socket transmission protocols with the following corresponding port numbers:

ProtocolPort Number
HTTP9012
WebSocket9012
TCP Socket30004

1.3 JSON-RPC 2.0 Specification

Request Object

The RPC request object contains the following members:

  • jsonrpc: Specifies the version of the JSON-RPC protocol, must be 2.0
  • method: Specifies the name of the method being called, which is a string
  • params: Specifies the parameter values, which is a structured value
  • id: Identifier

For example, {"jsonrpc":"2.0","method":"getRobotNames","params":[],"id":1}.

Response Object

There are two cases for RPC responses: success and error.

  1. When the RPC call is successful, the RPC response object contains the following members:

    • jsonrpc: Specifies the version of the JSON-RPC protocol, must be 2.0
    • result: Specifies the return value of the function executed
    • id: Specifies the identifier, which must be the same as the identifier in the request object

    For example, {"id":1,"jsonrpc":"2.0","result":["rob1"]}.

  2. When there is an error in the RPC call, the RPC response object contains the following members:

    • jsonrpc: Specifies the version of the JSON-RPC protocol, must be 2.0
    • error: Specifies the error object, which contains the following members
      • code: Indicates the error code
      • message: Provides a brief description of the error
      • data: Provides additional information about the error, which may be ignored.
    • id: Specifies the identifier, which must be the same as the identifier in the request object

    For example, {"error":{"code":-32601,"message":"method not found: RobotManage.poweron"},"id":1038,"jsonrpc":"2.0"}.

Error Codes

Error CodeMessageDescription
-32700Parse error.The server received invalid JSON. An error occurred while parsing JSON text.
-32600Invalid Request.The sent JSON is not a valid request object.
-32601Method not found.The method does not exist or is unavailable.
-32602Invalid params.Invalid method parameters.
-32603Internal error.JSON-RPC internal error.
-32099..-32000Server error.Reserved for implementation-defined server errors.

2. API Framework Description

  1. AuboApi Module: Manages robot API, providing methods to access different functional modules such as mathematical interfaces, system information, runtime interfaces, register control, robot list, etc.
  2. Math Module: Mathematical method interfaces, such as pose addition and subtraction, pose transformations, etc.
  3. RegisterControl Module: Register and Modbus operation interfaces, such as reading and writing registers, adding and deleting Modbus signals, etc.
  4. RobotInterface Module: Provides access to robot force control, IO control, motion control, robot algorithms, robot configuration, etc.
    • ForceControl Module: Force control interfaces.
    • IoControl Module: IO control interfaces.
    • MotionControl Module: Motion control interfaces, such as joint motion, linear motion, spline motion, etc.
    • RobotAlgorithm Module: External interfaces related to robot algorithms, such as end-effector load identification, Euler angles and quaternion conversions, etc.
    • RobotConfig Module: Interfaces for setting and getting robot configurations, such as setting and getting TCP offsets, etc.
    • RobotManage Module: Robot management interfaces, such as power on/off, drag teaching, etc.
    • RobotState Module: Interfaces for getting robot status, such as retrieving robot status, firmware version, etc.
  5. RuntimeMachine Module: Runtime interfaces, such as starting, pausing, or stopping script interpreter execution, etc.
  6. SystemInfo Module: Interfaces for retrieving system information, such as controller version, interface version, etc.
  7. Trace Module: Log system interfaces, such as modifying the format of controller logs, etc.

3. Typical API Description

3.1 Get Robot Names List

Function Name: getRobotNames

Function: Retrieves the list of robot names

Parameters: None

Returns: List of robot names

Example:

  • Request:

    {"jsonrpc":"2.0","method":"getRobotNames","params":[],"id":1}

    This request calls the method named getRobotNames.

  • Response:

    {"id":1,"jsonrpc":"2.0","result":["rob1"]}

    In this example, the retrieved robot name is rob1.

3.2 Get Version Information

3.2.1 Get Controller Version

Function Name: getControlSoftwareVersionCode

Function: Retrieves the controller version number

Parameters: None

Returns: Controller version number

Example:

  • Request:

    {"jsonrpc":"2.0","method":"SystemInfo.getControlSoftwareVersionCode","params":[],"id":2}

    This request calls the method named getControlSoftwareVersionCode, which belongs to the SystemInfo object.

  • Response:

    {"id":2,"jsonrpc":"2.0","result":28000}

    In this example, the retrieved controller version number is 0.28.0.

3.2.2 Get Interface Version

Function Name: getInterfaceVersionCode

Function: Retrieves the interface version number

Parameters: None

Returns: Interface version number

Example:

  • Request:

    {"jsonrpc":"2.0","method":"SystemInfo.getInterfaceVersionCode","params":[],"id":3}

    This request calls the method named getInterfaceVersionCode, which belongs to the SystemInfo object.

  • Response:

    {"id":3,"jsonrpc":"2.0","result":22002}

    In this example, the retrieved interface version number is 0.22.2.

3.2.3 Get Master Board Firmware Version

Function Name: getMasterBoardFirmwareVersion

Function: Retrieves the master board firmware version number

Parameters: None

Returns: Master board firmware version number

Example:

  • Request:

    {"jsonrpc":"2.0","method":"rob1.RobotState.getMasterBoardFirmwareVersion","params":[],"id":4}

    This request calls the method named getMasterBoardFirmwareVersion, which belongs to the RobotState object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface.

  • Response:

    {"id":4,"jsonrpc":"2.0","result":9000004}

    In this example, the retrieved master board firmware version is 9.0.4.

3.2.4 Get Slave Board Firmware Version

Function Name: getSlaveBoardFirmwareVersion

Function: Retrieves the slave board firmware version number

Parameters: None

Returns: Slave board firmware version number

Example:

  • Request:

    {"jsonrpc":"2.0","method":"rob1.RobotState.getSlaveBoardFirmwareVersion","params":[],"id":5}

    This request calls the method named getSlaveBoardFirmwareVersion, which belongs to the RobotState object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface.

  • Response:

    {"id":5,"jsonrpc":"2.0","result":9000003}

    In this example, the retrieved slave board firmware version is 9.0.3.

3.2.5 Get Joint Firmware Versions

Function Name: getJointFirmwareVersions

Function: Retrieves the firmware version numbers for the six joints

Parameters: None

Returns: Firmware version numbers for the six joints

Example:

  • Request:

    {"jsonrpc":"2.0","method":"rob1.RobotState.getJointFirmwareVersions","params":[],"id":6}

    This request calls the method named getJointFirmwareVersions, which belongs to the RobotState object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface.

  • Response:

    {"id":6,"jsonrpc":"2.0","result":[4002003,4002003,4002003,4002003,4002003,4002003]}

    In this example, the firmware version numbers for the six joints are all 4.2.3.

3.2.6 Get Tool Firmware Version

Function Name: getToolFirmwareVersion

Function: Retrieves the tool firmware version number

Parameters: None

Returns: Tool firmware version number

Example:

  • Request:

    {"jsonrpc":"2.0","method":"rob1.RobotState.getToolFirmwareVersion","params":[],"id":7}

    This request calls the method named getToolFirmwareVersion, which belongs to the RobotState object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface.

  • Response:

    {"id":7,"jsonrpc":"2.0","result":1002000}

    In this example, the retrieved tool firmware version is 1.2.0.

3.2.7 Get Pedestal Firmware Version

Function Name: getPedestalFirmwareVersion

Function: Retrieves the pedestal firmware version number

Parameters: None

Returns: Pedestal firmware version number

Example:

  • Request:

    
    {"jsonrpc":"2.0","method":"rob1.RobotState.getPedestalFirmwareVersion","params":[],"id":8}

    This request calls the method named getPedestalFirmwareVersion, which belongs to the RobotState object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface.

  • Response:

    {"id":8,"jsonrpc":"2.0","result":2004005}

    In this example, the retrieved pedestal firmware version is 2.4.5.

3.3 Robot Power Control

3.3.1 Get Current Robot Status

Function Name: getRobotModeType

Function: Retrieves the current robot status

Parameters: None

Returns: The current robot status

Robot StatusDescription
NoControllerFor use by the teach pendant; shown if the aubo_control process crashes
DisconnectedNot connected to the robot body (controller and interface board disconnected or EtherCAT bus disconnected)
ConfirmSafetySafety configuration is in progress, in power-off state
BootingThe robot body is powering up and initializing
PowerOffThe robot body is in a powered-off state
PowerOnThe robot is successfully powered on, brakes are engaged, and joint states have not been initialized
IdleThe robot is powered on, brakes are engaged, motors are not powered, and joint states are initialized
BrakeReleasingThe robot is powered on, and brakes are releasing
BackDriveBackdrive: brakes are released, motors are not powered
RunningThe robot brakes are released, and it is in running mode; control has been transferred from hardware to software
MaintainceMaintenance mode: including firmware upgrades, parameter writing, etc.
Error

Example:

  • Request:

    {"jsonrpc":"2.0","method":"rob1.RobotState.getRobotModeType","params":[],"id":9}

    This request calls the method named getRobotModeType, which belongs to the RobotState object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface.

  • Response:

    {"id":9,"jsonrpc":"2.0","result":"Idle"}

    In this example, the current robot status retrieved is Idle.

3.3.2 Power On

Function Name: poweron

Function: Powers on the robot

Parameters: None

Returns: If the interface call is successful, it returns 0.

Example:

  • Request:

    {"jsonrpc":"2.0","method":"rob1.RobotManage.poweron","params":[],"id":10}

    This request calls the method named poweron, which belongs to the RobotManage object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface.

  • Response:

    {"id":10,"jsonrpc":"2.0","result":0}

    In this example, the poweron interface call was successful.

    Note: When the robot's status becomes Idle, it indicates that the robot has powered on successfully. The robot's status can be obtained using the getRobotModeType interface or viewed on the teach pendant interface.

    image-20231020183638911

3.3.3 Startup and Release Brake

Function Name: startup

Function: Startup and release the brake

Parameters: None

Returns: If the interface call is successful, it returns 0.

Example:

  • Request:

    {"jsonrpc":"2.0","method":"rob1.RobotManage.startup","params":[],"id":11}

    This request calls the method named startup, which belongs to the RobotManage object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface.

  • Response:

    {"id":11,"jsonrpc":"2.0","result":0}

    In this example, the startup interface call was successful.

    Note: When the robot's status becomes Running, it indicates that the brake has been released successfully. The robot's status can be obtained using the getRobotModeType interface or viewed on the teach pendant interface.

    image-20231020183735830

3.3.3 Power Off

{"jsonrpc":"2.0","method":"robot_name.RobotManage.poweroff","params":[],"id":id}

Function Name: poweroff

Function: Powers off the robot

Parameters: None

Returns: If the interface call is successful, it returns 0.

Example:

  • Request:

    {"jsonrpc":"2.0","method":"rob1.RobotManage.poweroff","params":[],"id":12}

    This request calls the method named poweroff, which belongs to the RobotManage object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface.

  • Response:

    {"id":12,"jsonrpc":"2.0","result":0}

    In this example, the poweroff interface call was successful.

    Note: When the robot's status becomes PowerOff, it indicates that the robot has successfully powered off. The robot's status can be obtained using the getRobotModeType interface or viewed on the teach pendant interface.

    image-20231020183530236

3.4 Robot Motion

3.4.1 Joint Motion

Function Name: moveJoint

Function: Joint motion

Parameters:

"params": ["q": q, "a": a, "v": v, "blend_radius": blend_radius, "duration": duration]
  • q: Target joint angles, in radians
  • a: Acceleration, in rad/s^2
  • v: Velocity, in rad/s
  • blend_radius: Blending radius, in meters
  • duration: Time duration, in seconds

Returns: If the interface call is successful, it returns 0.

Example:

  • Request:

    {"jsonrpc":"2.0","method":"rob1.MotionControl.moveJoint","params":[[-2.05177, -0.400292, 1.19625,0.0285152, 1.57033, -2.28774],0.3,0.3,0,0],"id":13}

    This request calls the method named moveJoint, which belongs to the MotionControl object and is associated with the robot named rob1. The robot's name can be obtained through the getRobotNames interface. The target joint angles are [-2.05177, -0.400292, 1.19625,0.0285152, 1.57033, -2.28774], with both acceleration and velocity set to 0.3.

  • Response:

    {"id":13,"jsonrpc":"2.0","result":0}

    In this example, the moveJoint interface call was successful.

3.4.2 Linear Motion

Function Name: moveLine

Function: Linear motion

Parameters:

"params": ["pose": pose, "a": a, "v": v, "blend_radius": blend_radius, "duration": duration]
  • pose: Target position and orientation in the form of [x, y, z, rx, ry, rz], where position is in meters and orientation is in radians
  • a: Acceleration (if the position change is less than 1mm and the orientation change is greater than 1e-4 rad, this will be considered angular acceleration, in rad/s^2; otherwise, it will be linear acceleration, in m/s^2)
  • v: Velocity (if the position change is less than 1mm and the orientation change is greater than 1e-4 rad, this will be considered angular velocity, in rad/s; otherwise, it will be linear velocity, in m/s)
  • blend_radius: Blending radius, in meters
  • duration: Time duration, in seconds


**Returns**: If the interface call is successful, it returns 0.

**Example**:

- Request:

	```
	{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[0.54887, -0.12150, 0.43752, 3.142, 0.000, 1.571],0.3,0.3,0,0],"id":14}
	```

	This request calls the method named `moveLine`, which belongs to the `MotionControl` object and is associated with the robot named `rob1`. The robot's name can be obtained through the `getRobotNames` interface. The target position and orientation are `[0.54887, -0.12150, 0.43752, 3.142, 0.000, 1.571]`, with both acceleration and velocity set to 0.3.

- Response:

	```
	{"id":14,"jsonrpc":"2.0","result":0}
	```

	In this example, the `moveLine` interface call was successful.

#### 3.4.3 Joint Spline Motion

**Function Name**: moveSpline

**Function**: Joint spline motion

**Parameters**:

"params": ["q": q, "a": a, "v": v, duration": duration]


- q: Target joint angles, in radians. When the joint angles are empty, the robot starts spline motion.
- a: Acceleration, in rad/s^2
- v: Velocity, in rad/s
- duration: Time duration, in seconds

**Returns**: If the interface call is successful, it returns 0.

**Example**:

- Request:


	```
	{"jsonrpc":"2.0","method":"rob1.MotionControl.moveSpline","params":[[-2.05177, -0.400292, 1.19625,0.0285152, 1.57033,   -2.28774],0.3,0.3,0],"id":15}
	```

	This request calls a method named `moveSpline`, which belongs to the `MotionControl` object, and this object is associated with a robot named `rob1`. The robot's name can be retrieved using the `getRobotNames` interface. The target joint angles are [-2.05177, -0.400292, 1.19625, 0.0285152, 1.57033, -2.28774], with both acceleration and velocity set to 0.3.

	```
	{"jsonrpc":"2.0","method":"rob1.MotionControl.moveSpline","params":[[],0.3,0.3,0],"id":16}
	```

	In this request, the `moveSpline` interface is passed with empty joint angles, and the robot begins spline motion.

- Response:

	```
	{"id":15,"jsonrpc":"2.0","result":0}
	```

	```
	{"id":16,"jsonrpc":"2.0","result":0}
	```

	In this example, the return value is 0, indicating that the `moveSpline` interface call was successful.

## 4. Examples based on the HTTP communication protocol

### 4.1 curl command method

curl is a command-line tool and library used for data transfer on various operating systems. It supports HTTP network protocols, and by using curl, HTTP requests can be sent from the command line to receive responses from servers.

Before using the curl command, ensure that it is installed on your operating system. You can run the command `curl --version` in a terminal or command prompt to verify the installation.

The following is an example of sending a POST request using curl:

```bash
curl --request POST 'http://localhost:9012/jsonrpc' --data '{"jsonrpc":"2.0","method":"getRobotNames","params":[],"id":1}'
  • --request POST: This option specifies that curl will send a request using the POST method. In the HTTP protocol, the POST method is used to submit data to the server. By using this option, curl will send the request as a POST method, allowing the server to receive the data included in the request body.

  • http://localhost:9012/jsonrpc: This is the target URL that represents the server address and endpoint to which the request will be sent.

    http://localhost:9012 specifies the location of the server. localhost is the robot's IP address, and 9012 is the RPC port number.

    /jsonrpc is the specific endpoint path used to identify the resource or service on the server that handles JSON-RPC requests.

  • --data: This is used to specify the content of the request body. In this example, the request body is a JSON-formatted string that retrieves the list of robot names.

4.2 Apifox Web method

  1. Apifox Web version URL: https://app.apifox.com/user/login?redirect=https://app.apifox.com/main

  2. After logging in, click New Project.

    image-20231020161845873

  3. Select the project type as HTTP, input the project name, and click Create.

    image-20231020162037958

  4. Click Quick Request.

    image-20231020162319123

  5. Select POST, input the URL address, choose Body for the parameters, set the parameter format to raw, input the json-rpc request content, and click Send.

    In the Body section below, you can see the response information.

    image-20231020163322734




## 5. WebSocket Communication Protocol Example

### WebSocket Online Testing Tool Method

WebSocket is a communication protocol used to establish bidirectional real-time communication between clients and servers. It allows for full-duplex communication over a persistent connection without requiring new connections for each request and response.

Here are the steps to invoke the JSON-RPC interface using a WebSocket online testing tool:

1. WebSocket Online Testing Website: [WEBSOCKET Online Testing Tool](http://wstool.jackxiang.com/)

2. Connection address: `ws://localhost:9012`. `localhost` is the robot's IP address, and `9012` is the JSON-RPC port number.

3. In the `Service Address` field, enter the connection address and click `Start Connection`.

   ![image-20231020140127142](./pics/image-20231020140127142.png)

   Once connected, the `Server Configuration Status` will show a successful connection.

   ![image-20231020140603530](./pics/image-20231020140603530.png)

4. Enter the JSON-RPC request, then click `Send to Server`.

   ![image-20231020141115926](./pics/image-20231020141115926.png)

5. You can view the sent JSON-RPC request and the response in the `Message Log`.

   ![image-20231020141204402](./pics/image-20231020141204402.png)

## 6. TCP Socket Communication Protocol Example

### TCP Debugging Assistant Testing Method

Here are the steps to invoke the JSON-RPC interface using the TCP Debugging Assistant:

1. Open the TCP Debugging Assistant and create a `TCP Client`.

   ![image-20231027174533541](./pics/image-20231027174533541.png)

2. Enter the `Robot Arm IP Address` and `Port Number`, and click `Confirm`.

   ![image-20231027174653871](./pics/image-20231027174653871.png)

3. Click `Connect`.

   ![image-20231027174740046](./pics/image-20231027174740046.png)

   Once connected, the `Socket Status` will change to `Connected`.

   ![image-20231027174845332](./pics/image-20231027174845332.png)

4. After entering the JSON-RPC string request, click `Send Data`.

   ![image-20231027175108684](./pics/image-20231027175108684.png)

5. The JSON-RPC response is shown as in the image below.

   ![image-20231027175250694](./pics/image-20231027175250694.png)

## 7. JSON-RPC Application Example

### 7.1 Power On/Off the Robot Arm

This example describes how to power on and off the robot arm using JSON-RPC strings. The steps are as follows:

1. **Get the current robot names**

	- Request:

		```
		{"jsonrpc":"2.0","method":"getRobotNames","params":[],"id":1}
		```

	- Response:

		```
		{"id":1,"jsonrpc":"2.0","result":["rob1"]}
		```

		The robot name obtained is `rob1`.

2. **Set Payload**

	- Request: Set the payload to 4kg with the center of gravity (Cx, Cy, Cz) as (0m, 0.1m, 0.068m).

		```
		{"jsonrpc":"2.0","method":"rob1.RobotConfig.setPayload","params":[4.0,[0,0.1,0.068],[0,0,0],[0,0,0,0,0,0] ],"id":2}
		```

	- Response:

		```
		{"id":2,"jsonrpc":"2.0","result":0}
		```

3. **Power On**

	- Request:

		```
		{"jsonrpc":"2.0","method":"rob1.RobotManage.poweron","params":[],"id":3}
		```

	- Response:

		```
		{"id":3,"jsonrpc":"2.0","result":0}
		```

		After powering on, the robot arm's status changes to `Idle`.

		![image-20231020183638911](./pics/image-20231020183638911.png)

4. **Release Brakes**

	- Request:

		```
		{"jsonrpc":"2.0","method":"rob1.RobotManage.startup","params":[],"id":4}
		```

	- Response:

		```
		{"id":4,"jsonrpc":"2.0","result":0}
		```

		After releasing the brakes, the robot arm's status changes to `Running`.

		![image-20231020183735830](./pics/image-20231020183735830.png)

5. **Power Off**

	- Request:

		```
		{"jsonrpc":"2.0","method":"rob1.RobotManage.poweroff","params":[],"id":5}
		```

	- Response:

		```
		{"id":5,"jsonrpc":"2.0","result":0}
		```

		After powering off, the robot arm's status changes to `Power Off`.

		![image-20231020183530236](./pics/image-20231020183530236.png)

### 7.2 Joint and Linear Motion
**Note**: This example is written for the i5 model robot.

**Note**: Before moving the robot, you must first set the payload, power on the robot, and release the brakes.


1. Get the name of the current robot.

	- Request:

		```
		{"jsonrpc":"2.0","method":"getRobotNames","params":[],"id":1}
		```

	- Response:

		```
		{"id":1,"jsonrpc":"2.0","result":["rob1"]}
		```

		The retrieved robot name is `rob1`.

2. Set the TCP (relative to the flange center) offset, which is the tool center point.

	- Request: Set the tool center point (x, y, z, Rx, Ry, Rz) to (0, 0.1, 0.068, 0, 0, 0). x, y, z are in meters, Rx, Ry, Rz are in radians.

		```
		{"jsonrpc":"2.0","method":"rob1.RobotConfig.setTcpOffset","params":[[0,0.1,0.068,0,0,0]],"id":2}
		```

	- Response:

		```
		{"id":2,"jsonrpc":"2.0","result":0}
		```

3. Set the movement speed ratio.

	- Request: Set the movement speed ratio to 0.75, which is 75%.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.setSpeedFraction","params":[0.75],"id":3}
		```

	- Response:

		```
		{"id":3,"jsonrpc":"2.0","result":0}
		```

		The speed ratio in the scope interface is set to 75%.

		![image-20231030165153946](./pics/image-20231030165153946.png)

4. Move the joints to the initial position.

	- Request: Move the joints to the target joint angles [0, -0.2618, 1.74533, 0.436333, 1.570797, 0], with an acceleration of 1.4 rad/s^2 and a velocity of 1.05 rad/s.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveJoint","params":[[0,-0.2618,1.74533,0.436333,1.570797,0],1.4,1.05,0,0],"id":4}
		```

	- Response:


		```
		{"id":4,"jsonrpc":"2.0","result":0}
		```
5. Move Line to Waypoint 1

	- Request: Move line to target position `[0.64887, -0.12151, 0.46613, -3.14, 0.0, 1.571]`, with acceleration of 1.2 m/s² and speed of 0.25 m/s.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[0.64887, -0.12151, 0.46613, -3.14, 0.0, 1.571], 1.2, 0.25, 0, 0],"id":5}
		```

	- Response:

		```
		{"id":5,"jsonrpc":"2.0","result":0}
		```

6. Move Line to Waypoint 2

	- Request: Move line to target position `[0.64887, 0.17755, 0.46613, -3.14, 0.0, 1.571]`, with acceleration of 1.2 m/s² and speed of 0.25 m/s.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[0.64887, 0.17755, 0.46613, -3.14, 0.0, 1.571], 1.2, 0.25, 0, 0],"id":6}
		```

	- Response:

		```
		{"id":6,"jsonrpc":"2.0","result":0}
		```

7. Move Line to Waypoint 3

	- Request: Move line to target position `[0.59639, 0.17753, 0.21115, -3.14, 0.0, 1.571]`, with acceleration of 1.2 m/s² and speed of 0.25 m/s.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[0.59639, 0.17753, 0.21115, -3.14, 0.0, 1.571], 1.2, 0.25, 0, 0],"id":7}
		```

	- Response:

		```
		{"id":7,"jsonrpc":"2.0","result":0}
		```

### 7.3 Runtime + Joint/Line Motion

**Note**: To enable blending for line movements, RuntimeMachine must be enabled.

**Note**: This example is written for the i5 model of the robot arm.

**Note**: Before moving the robot arm, you must first set the load, power on, and release the brakes.

This example describes how to achieve blending effects for line movements using json-rpc strings, with the following steps:

1. Retrieve the current name of the robot

1. Get Robot Names

	- Request:


		```
		{"jsonrpc":"2.0","method":"getRobotNames","params":[],"id":1}
		```


	- Response:

		```
		{"id":1,"jsonrpc":"2.0","result":["rob1"]}
		```


	The robot name obtained is rob1.

2. Set TCP (Tool Center Point) Offset Relative to Base Coordinate System

	- Request: Set the tool center point (x, y, z, Rx, Ry, Rz) to (0, 0.1, 0.068, 0, 0, 0). x, y, z are in meters, Rx, Ry, Rz are in radians.
		```
		{"jsonrpc":"2.0","method":"rob1.RobotConfig.setTcpOffset","params":[[0,0.1,0.068,0,0,0]],"id":2}
		```

	- Response:

		```
		{"id":2,"jsonrpc":"2.0","result":0}
		```

3. Set Motion Speed Fraction

	- Request: Set the motion speed fraction to 0.75, which is 75%.


		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.setSpeedFraction","params":[0.75],"id":3}
		```

	- Response:

		```
		{"id":3,"jsonrpc":"2.0","result":0}
		```

	The speed fraction in the scope interface is set to 75%.

	![image-20231030165153946](./pics/image-20231030165153946.png)
4. Start Runtime

	- Request:

		```
		{"jsonrpc":"2.0","method":"RuntimeMachine.start","params":[],"id":4}
		```

	- Response:

		```
		{"id":4,"jsonrpc":"2.0","result":0}
		```

5. Get the Current Runtime Context

	- Request: When the parameter is -1, it indicates fetching the runtime context of the currently running thread.

		```
		{"jsonrpc":"2.0","method":"RuntimeMachine.getPlanContext","params":[-1],"id":5}
		```

	- Response: The first parameter in the result indicates the current thread ID, the second parameter indicates the line number, and the third parameter represents the context content.

		```
		{"id":5,"jsonrpc":"2.0","result":[47,-1,""]}
		```

6. Create a New Thread (Note: If the thread ID obtained from `getPlanContext` is a positive integer, this step can be omitted)

	- Request:

		```
		{"jsonrpc":"2.0","method":"RuntimeMachine.newTask","params":[false],"id":6}
		```

	- Response: The return value is the current thread ID, which is 48.

		```
		{"id":6,"jsonrpc":"2.0","result":48}
		```

7. Set the Context for Current Runtime

	- Request: The first parameter indicates the current thread ID, the second parameter indicates the line number, and the third parameter indicates the context content.

		```
		{"jsonrpc":"2.0","method":"RuntimeMachine.setPlanContext","params":[48,-1,""],"id":7}
		```

	- Response:

		```
		{"id":7,"jsonrpc":"2.0","result":0}
		```

8. Initial Joint Position for Movement

	- Request: Move the joints to the target joint angles `[-0.000003,-0.127267,-1.321124,0.37694,-1.570796,-0.000008]`, with acceleration of `3.14 rad/s^2` and velocity of `3.14 rad/s`.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveJoint","params":[[-0.000003,-0.127267,-1.321124,0.37694,-1.570796,-0.000008],3.14,3.14,0,0],"id":8}
		```

	- Response:

		```
		{"id":8,"jsonrpc":"2.0","result":0}
		```

9. Move in a Straight Line to Waypoint 1

	- Request: Move in a straight line to the target position `[-0.400318,0.064315,0.547598,3.14,0.0,-2.63782]`, with acceleration of `2 m/s^2` and velocity of `1 m/s`.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[-0.400318,0.064315,0.547598,3.14,0.0,-2.63782],2,1,0,0],"id":9}
		```

	- Response:

		```
		{"id":9,"jsonrpc":"2.0","result":0}
		```

10. Move in a Straight Line to Waypoint 2

	- Request: Move in a straight line to the target position `[-0.400318,0.064315,0.379989,3.14,0.0,-2.63782]`, with acceleration of `2 m/s^2` and velocity of `1 m/s`.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[-0.400318,0.064315,0.379989,3.14,0.0,-2.63782],2,1,0,0],"id":10}
		```

	- Response:

		```
		{"id":10,"jsonrpc":"2.0","result":0}
		```

11. Move in a Straight Line to Waypoint 3

	- Request: Move in a straight line to the target position `[-0.400318,0.064315,0.547598,3.14,0.0,-2.63782]`, with acceleration of `2 m/s^2` and velocity of `1 m/s`.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[-0.400318,0.064315,0.547598,3.14,0.0,-2.63782],2,1,0,0],"id":11}
		```

	- Response:

		```
		{"id":11,"jsonrpc":"2.0","result":0}
		```

12. Move in a straight line to waypoint 4

	- Request: Move in a straight line to the target position `[-0.400319,-0.298610, 0.547598,3.14,0.435471,-1.57]`, with acceleration of 2 m/s², velocity of 1 m/s, and blend radius of 0.02 m.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[-0.400319,-0.298610, 0.547598,3.14,0.435471,-1.57],2,1,0.02,0],"id":12}
		```

	- Response:

		```
		{"id":12,"jsonrpc":"2.0","result":0}
		```

13. Move in a straight line to waypoint 5

	- Request: Move in a straight line to the target position `[-0.400319,-0.243865, 0.429931,3.14,0.435471,-1.57]`, with acceleration of 2 m/s² and velocity of 1 m/s.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[-0.400319,-0.243865, 0.429931,3.14,0.435471,-1.57],2,1,0,0],"id":13}
		```

	- Response:

		```
		{"id":13,"jsonrpc":"2.0","result":0}
		```

14. Move in a straight line to waypoint 6

	- Request: Move in a straight line to the target position `[-0.400319,-0.298610,0.547598,3.14,0.435471,-1.57]`, with acceleration of 2 m/s², velocity of 1 m/s, and blend radius of 0.02 m.

		```
		{"jsonrpc":"2.0","method":"rob1.MotionControl.moveLine","params":[[-0.400319,-0.298610,0.547598,3.14,0.435471,-1.57],2,1,0.02,0],"id":14}
		```

	- Response:

		```
		{"id":14,"jsonrpc":"2.0","result":0}
		```

15. Delete thread

	- Request: Parameter is the current thread id

		```
		{"jsonrpc":"2.0","method":"RuntimeMachine.deleteTask","params":[48],"id":15}
		```

	- Response:

		```
		{"id":15,"jsonrpc":"2.0","result":0}
		```

16. Stop runtime

	- Request:

		```
		{"jsonrpc":"2.0","method":"RuntimeMachine.stop","params":[],"id":16}
		```

	- Response:

		```
		{"id":16,"jsonrpc":"2.0","result":0}
		```



## 8. Based on the TCP Socket communication protocol

The port number for sending script strings or script files via TCP Socket is **30002**.

Below is an explanation of how to send script strings and files using a TCP debugging tool.

The example script string is as follows:

```lua
--[[
    Function: Joint motion
    Description: Perform joint motion sequentially through 3 waypoints.
]]
return function(api)
    local _ENV = require('aubo').sched.select_robot(1)
    local sched = require('aubo').sched
    sched.sleep(0)
    
    pi = 3.14159265358979323846
 
    -- The waypoints are represented by joint angles in radians.
    waypoint0_q = {0.0/180*pi, -15/180*pi, 100/180*pi, 25/180*pi, 90.0/180*pi, 0.0/180*pi}
    waypoint1_q = {35.92/180*pi, -11.28/180*pi, 59.96/180*pi, -18.76/180*pi, 90.0/180*pi, 35.92/180*pi}
    waypoint2_q = {41.04/180*pi, -7.65/180*pi, 98.80/180*pi, 16.44/180*pi, 90.0/180*pi, 11.64/180*pi}

    -- Set the speed ratio of the robot arm. 
    setSpeedFraction(0.75)

    -- Joint motion.
    moveJoint(waypoint0_q, 80/180*pi, 60/180*pi, 0, 0)

    moveJoint(waypoint1_q, 80/180*pi, 60/180*pi, 0, 0)

    moveJoint(waypoint2_q, 80/180*pi, 60/180*pi, 0, 0)
end

8.1 Sending Script Strings via TCP Debugging Tool

Here are the steps to send a script string using the TCP debugging tool:

  1. Select TCP Client, enter the robot's IP address and port number 30002, and then click Connect.

    establish_connection

  2. Once connected successfully, the interface should look like the image below.

    connection_successful

  3. Input the script string, press Enter twice at the end of the script, and click Send.

    Note: Script strings sent to the robot controller via TCP Socket protocol must end with \r\n\r\n. \r\n represents a newline character. Therefore, after pasting the script into the TCP debugging tool, press Enter at least twice at the end.

    send_script_str

  4. After the script runs successfully, the data reception information will appear as shown below.

    script_execution_successful

8.2 Sending Script Files via TCP Debugging Tool

Here are the steps to send a script file using the TCP debugging tool:

  1. Select TCP Client, enter the robot's IP address and port number 30002, and then click Connect.

    establish_connection

  2. Once connected successfully, the interface should look like the image below.

    connection_successful

  3. Check Start File Data Source.

    select_box

  4. Open the script file.

    open_file

  5. Click Send.

    send_script_file

  6. After the script runs successfully, the data reception information will appear as shown below.

    script_file_execution_successful