4.3 Robot Program Operation Class
Overview
The Execution class provides a unified scheduling interface for robot programs and motion tasks. It can start/stop/pause/resume teach-pendant programs, manage the list of concurrently running tasks, and execute BAS scripts or other custom workflows. Leveraging the connection and motion capabilities of Arm and Motion, Execution is responsible for triggering and controlling program flow in the controller from the host side.
4.3.1 Execute a Specified Program
| Method Name | execution.start( program_name : str) -> StatusCodeEnum |
|---|---|
| Description | Execute a specified program. |
| Request Parameters | program_name : str The name of the program to be executed. |
| Return Value | StatusCodeEnum: The result of the function execution. |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
4.3.2 Stop the Currently Executing Program
| Method Name | execution.stop( program_name : str = '') -> StatusCodeEnum |
|---|---|
| Description | Stop the currently executing program or stop the robot's current motion. |
| Request Parameters | program_name : str The name of the program to be stopped. Default is an empty string, indicating stopping the currently running program or motion command. |
| Return Value | StatusCodeEnum: The result of the function execution. |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
4.3.3 Return Detailed Information of All Running Programs
| Method Name | execution.all_running_programs() -> tuple[list, StatusCodeEnum] |
|---|---|
| Description | Return detailed information of all running programs, including thread ID, program name, xpath, program status, and program type. |
| Request Parameters | None |
| Return Value | list: A list of running program details, where each element contains thread_id , program_name , xpath , program_status , program_type , etc. StatusCodeEnum: The result of the function execution. |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
4.3.4 Pause Program Execution
| Method Name | execution.pause( program_name : str = '') -> StatusCodeEnum |
|---|---|
| Description | Pause the currently executing program or the robot's current motion. |
| Request Parameters | program_name : str The name of the program to be paused. Default is an empty string, indicating pausing the currently running program or motion command. |
| Return Value | StatusCodeEnum: The result of the function execution. |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
4.3.5 Resume Program Execution
| Method Name | execution.resume( program_name : str = '') -> StatusCodeEnum |
|---|---|
| Description | Continue running a program that is in a paused state. |
| Request Parameters | program_name : str The name of the program to be resumed. Default is an empty string, indicating resuming the currently paused program or motion command. |
| Return Value | StatusCodeEnum: The result of the function execution. |
| Compatible robot software version | Collaborative (Copper): v7.5.0.0+ Industrial (Bronze): v7.5.0.0+ |
Example Code
#!python
"""
Copyright © 2016 Agilebot Robotics Ltd. All rights reserved.
Instruction: 自定义程序使用示例 / Example of custom program usage
"""
import time
from Agilebot import Arm, StatusCodeEnum
# [ZH] 初始化捷勃特机器人
# [EN] Initialize the Agilebot robot
arm = Arm()
# [ZH] 连接捷勃特机器人
# [EN] Connect to the Agilebot robot
ret = arm.connect("10.27.1.254")
# [ZH] 检查是否连接成功
# [EN] Check if the connection is successful
if ret == StatusCodeEnum.OK:
print("机器人连接成功 / Robot connection successful")
else:
print(f"机器人连接失败,错误代码 / Robot connection failed, error code: {ret.errmsg}")
arm.disconnect()
exit(1)
program_name = "test"
# [ZH] 执行程序
# [EN] Execute program
ret = arm.execution.start(program_name)
if ret == StatusCodeEnum.OK:
print("程序启动成功 / Program start successful")
else:
print(f"程序启动失败,错误代码 / Program start failed, error code: {ret.errmsg}")
arm.disconnect()
exit(1)
# [ZH] 获取所有正在运行的程序
# [EN] Get all running programs
programs_list, ret = arm.execution.all_running_programs()
if ret == StatusCodeEnum.OK:
print("获取运行程序列表成功 / Get running programs list successful")
else:
print(f"获取运行程序列表失败,错误代码 / Get running programs list failed, error code: {ret.errmsg}")
arm.disconnect()
exit(1)
for program in programs_list:
print(f"正在运行的程序名:{program}")
time.sleep(2)
# [ZH] 暂停程序
# [EN] Pause program
ret = arm.execution.pause(program_name)
if ret == StatusCodeEnum.OK:
print("程序暂停成功 / Program pause successful")
else:
print(f"程序暂停失败,错误代码 / Program pause failed, error code: {ret.errmsg}")
arm.disconnect()
exit(1)
time.sleep(2)
# [ZH] 恢复程序
# [EN] Resume program
ret = arm.execution.resume(program_name)
if ret == StatusCodeEnum.OK:
print("程序恢复成功 / Program resume successful")
else:
print(f"程序恢复失败,错误代码 / Program resume failed, error code: {ret.errmsg}")
arm.disconnect()
exit(1)
time.sleep(2)
# [ZH] 停止程序
# [EN] Stop program
ret = arm.execution.stop(program_name)
if ret == StatusCodeEnum.OK:
print("程序停止成功 / Program stop successful")
else:
print(f"程序停止失败,错误代码 / Program stop failed, error code: {ret.errmsg}")
arm.disconnect()
exit(1)
# [ZH] 断开捷勃特机器人连接
# [EN] Disconnect from the Agilebot robot
arm.disconnect()
print("机器人断开连接成功 / Robot disconnected successfully")4.3.6 Execute BAS Script Program
| Method Name | execution.execute_bas_script( bas_script : BasScript | list[str]) -> StatusCodeEnum | |-------------|---------------------------| | Description | Execute a user-defined BAS script program. | | Request Parameters | bas_script : BasScript or list[str] The user-defined BAS script program. | | Return Value | StatusCodeEnum: The result of the function execution. | | Note | The pause, resume, and stop methods for BAS script programs are the same as for regular programs. | | Compatible robot software version | Collaborative (Copper): v7.5.2.0+
Industrial (Bronze): v7.6.0.0+ |
#!python
"""
Copyright © 2016 Agilebot Robotics Ltd. All rights reserved.
Instruction: Bas脚本创建和使用示例 / Example of Bas script creation and usage
"""
from Agilebot import *
# [ZH] 初始化Arm类
# [EN] Initialize the Arm class
arm = Arm()
# [ZH] 连接控制器
# [EN] Connect to the controller
ret = arm.connect("10.27.1.254")
if ret == StatusCodeEnum.OK:
print("机器人连接成功 / Robot connected successfully")
else:
print(f"机器人连接失败,错误代码 / Robot connection failed, error code: {ret.errmsg}")
arm.disconnect()
exit(1)
# [ZH] 创建BasScript对象
# [EN] Create BasScript object
bs = BasScript(name="bas_test")
ret = bs.assign_value(AssignType.R, 1, OtherType.VALUE, 10)
ret = bs.move_joint(
pose_type=MovePoseType.PR,
pose_index=1,
speed_type=SpeedType.VALUE,
speed_value=100,
smooth_type=SmoothType.SMOOTH_DISTANCE,
smooth_distance=200.5,
)
ret = bs.wait_time(ValueType.VALUE, 10)
if ret == StatusCodeEnum.OK:
print("创建BasScript对象成功 / Create BasScript object successfully")
else:
print(f"创建BasScript对象失败,错误代码 / Create BasScript object failed, error code: {ret.errmsg}")
arm.disconnect()
exit(1)
# [ZH] 执行脚本
# [EN] Execute script
ret = arm.execution.execute_bas_script(bs)
if ret == StatusCodeEnum.OK:
print("执行脚本成功 / Execute script successfully")
else:
print(f"执行脚本失败,错误代码 / Execute script failed, error code: {ret.errmsg}")
arm.disconnect()
exit(1)
# [ZH] 结束后断开机器人连接
# [EN] Disconnect from the robot after completion
arm.disconnect()
print("机器人断开连接成功 / Robot disconnected successfully")