HTTP Service
WARNING
This feature will be deprecated soon.
Both requests and responses of the HTTP service are in application/json format, encoded in utf-8.
| Response Parameter | Type | Description |
|---|---|---|
code | int | Error code. 0 means success, in which case the format of data varies by request, see the documentation below. Any other value means failure, see Error codes. |
params | string[] | Error parameters, which vary by error code. Generally no handling is needed. |
data | any | The object defined by the interface on a successful response. When handling, check code first, then parse data. |
Response example:
{
"code": 0,
"params": [],
"data": null
}
Run a Scene or Task
- Request method:
POST - Request URL:
/public/task
| Request Parameter | Type | Description |
|---|---|---|
scene_id | int | Scene ID. It can be found on the scene list card in "Expert Mode", and in the browser address bar after entering the scene editor. |
execute_count | int | Number of executions. 0 means run in an infinite loop until explicitly stopped. |
clear | int | Whether to stop other running tasks and directly run the new task. 0 means ignore if another task is currently running, 1 means force-stop other tasks and run. If no other task is running, the task will run regardless of the value. |
task_id | int | Defaults to 0, meaning the scene executes normally. If it is a task ID, it means re-running the historical task record corresponding to that task ID, in which case scene_id is ignored. The task ID can be obtained from the task list. |
| Response Parameter | Type | Description |
|---|---|---|
id | int | Task ID. It can be used to query the task execution status. |
Request example: run scene 10001 in an infinite loop, force-stopping any other running task.
curl --location --request POST 'http://10.20.17.1/public/task' \
--header 'Content-Type: application/json' \
--data-raw '{
"scene_id": 10001,
"execute_count": 0,
"clear": 1
}'
Response example: the scene is added to the task queue and starts running, the task ID is 10104.
{
"data": {
"id": 10104
},
"code": 0
}
Execute a Lua Script
- Request method:
POST - Request URL:
/public/executor/lua
This interface is used to directly execute a bare Lua program. The request body is Lua code rather than JSON, so set the HTTP request header to Content-Type: text/plain.
This interface is called asynchronously. Whether execution has completed must be determined and returned in the Lua code, see the Lua Socket service interface.
Using this interface does not require adding program_begin/program_end at the beginning and end of the program, and supports querying the execution status via the task ID.
| Request Parameter | Type | Description |
|---|---|---|
name | string | Task name. Needs to be encoded with URLEncode(). |
execute_count | int | Number of task executions. 0: loop execution. If not 0, e.g. 3 means execute 3 times. |
clear | int | Whether to stop the running task and directly run the new task. 0: no, 1: yes. |
| Response Parameter | Type | Description |
|---|---|---|
id | int | Task ID. |
Request example: execute a Lua program with the task name test_name, loop 1 time, and skip execution if another task is running.
curl --location --request POST 'http://10.20.17.1/public/executor/lua?name=test_name&execute_count=1&clear=0' \
--header 'Content-Type: text/plain' \
--data-raw 'local p = kinematics_inverse({12,12,1,2,1,1})
for k,v in ipairs(p) do
print(k,v)
end
print(p["ok"])
'
Response example: the task has started executing, the task ID is 10113.
{
"data": {
"id": 10113
},
"code": 0
}
Response example: another task is running. Stop the current task in the task history before retrying.
{
"data": null,
"code": 2036
}
Task Status and Details
- Request method:
GET - Request URL:
/public/task
| Request Parameter | Type | Description |
|---|---|---|
id | int | Task ID |
| Response Parameter | Type | Description |
|---|---|---|
id | int | Task ID |
scene_id | int | Scene ID |
execute_count | int | Number of executions |
executed_count | int | Number of executions already done |
name | int | Task name |
status | int | Task status. 0: idle, 1: running, 2: paused, 3: ran successfully, 4: stopped by user, 5: stopped abnormally, 6: robot shut down or DS stopped |
comment | string | Comment |
start_time | string | Task start time |
end_time | string | Task end time |
consume_time | int | Task duration, excluding the time the task was paused, in seconds |
create_time | string | Creation time |
update_time | string | Update time |
Request example: get the execution status and details of the task with ID 10104.
curl --location --request GET 'http://10.20.17.1/public/task?id=10104'
Response example:
{
"data": {
"id": 10104,
"scene_id": 10001,
"execute_count": 0,
"executed_count": 3777,
"name": "Return to zero",
"status": 6,
"comment": "",
"start_time": "2021-03-31T16:19:04.073161049+08:00",
"end_time": null,
"consume_time": 0
},
"code": 0
}
Task List
- Request method:
GET - Request URL:
/public/tasks
| Request Parameter | Type | Description |
|---|---|---|
pi | int | Page number. |
ps | int | Number of entries per page. |
Request example: get the 10 most recently executed tasks.
curl --location --request GET 'http://10.20.17.1/public/tasks?pi=1&ps=10'
Response example: the scene is added to the task queue and starts running, the task ID is 10104.
{
"data": {
"pi": 1,
"ps": 10,
"total": 112,
"records": [
{
"id": 10106,
"scene_id": 10001,
"execute_count": 0,
"executed_count": 1,
"name": "Return to zero",
"end_lua": null,
"lua_data": null,
"status": 5,
"comment": null,
"start_time": "2021-04-01T14:56:44.674861588+08:00",
"end_time": "2021-04-01T14:56:44.836186966+08:00",
"consume_time": 0,
"first_pose_json": null,
"mode": 0,
"trigger_way": null,
"is_deleted": null,
"create_time": "2021-04-01T14:56:44.675868104+08:00",
"update_time": "2021-04-01T14:56:44.880620629+08:00",
"scene_type": 3,
"first_pose": null
},
...
],
"task_status": 0,
"task_id": null
},
"code": 0
}
Call a Command
POST /public/robot/action
When calling a motion command, this interface does not wait for the command to finish executing before returning; the developer needs to handle the completion logic themselves. When calling a query command, a result in a certain format is returned. See the command reference for details.
| Request Parameter | Type | Description |
|---|---|---|
cmd | string | Robot command |
data | object | Robot command parameters |
Request example:
curl --location --request POST 'http://10.20.17.1/public/robot/action' \
--header 'Content-Type: application/json' \
--data-raw '{
"cmd": "movej",
"data": {
"pose_to": [
0,
0,
0,
0,
0,
0
],
"is_joint_angle": true,
"acceleration": 1,
"velocity": 2
}
}'
Response example:
{
"data": {
"task_id": 1
},
"code": 0
}
get_task_status
Get the current task
Response Result
| Return Value | Type | Description |
|---|---|---|
| task_id | int | Task ID |
data.task_status | int | Task status, 0: idle, 1: running, 2: paused, 3: ran successfully, 4: ran with failure |
{"cmd":"get_task_status"}
{"data":{"task_status":0,"task_id":null},"code":0}
