4.1 机器人基础操作
| 方法名 | Arm( string controllerIP , string teachPanelIP = null, bool localProxy = true ) |
|---|---|
| 描述 | 捷勃特机器人类构造函数,包含所有可用的机器人控制接口。需要先初始化并连接机器人后才能使用其他功能 |
| 请求参数 | controllerIP : string 机器人控制器 IP 地址 teachPanelIP : string 可选,示教器侧 IP;不提供时回退到 controllerIP localProxy : bool 是否使用本地控制器代理服务,默认为 true。当为 true 时将在本地启动控制器代理服务;当为 false 时则需要机器人控制器中已安装代理服务(需要机器人软件版本 7.7 及以上) |
| 返回值 | StatusCode: 构造函数执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
4.1.1 连接机器人
| 方法名 | ConnectSync() |
|---|---|
| 描述 | 建立与捷勃特机器人的网络连接。必须先调用 Arm 构造函数初始化机器人实例 |
| 请求参数 | 无参数 |
| 返回值 | StatusCode: 连接操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
4.1.2 判断与机械臂的连接是否有效
| 方法名 | IsConnected() |
|---|---|
| 描述 | 检查与机器人的网络连接状态是否有效 |
| 请求参数 | 无参数 |
| 返回值 | bool: 连接状态,true 表示连接有效,false 表示连接失效或未连接 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
4.1.3 与机器人断开连接
| 方法名 | DisconnectSync() |
|---|---|
| 描述 | 断开与捷勃特机器人的网络连接,释放相关资源 |
| 请求参数 | 无参数 |
| 返回值 | StatusCode: 断开连接操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
示例代码
cs
using Agilebot.IR;
public class Connect
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接到捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
if (code != StatusCode.OK)
{
Console.WriteLine("Connect Robot Failed: " + code.GetDescription());
return code;
}
try
{
// [ZH] 检查连接状态
// [EN] Check the connection status
var state = controller.IsConnected();
Console.WriteLine("Connected: " + state);
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.1.4 获取当前机器人型号
| 方法名 | GetArmModelInfo() |
|---|---|
| 描述 | 获取当前连接的捷勃特机器人型号信息 |
| 请求参数 | 无参数 |
| 返回值 | string: 机器人型号字符串,例如 "GBT-C5A" StatusCode: 获取操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
示例代码
cs
using Agilebot.IR;
public class GetArmModelInfo
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接到捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
if (code != StatusCode.OK)
{
Console.WriteLine("Connect Robot Failed: " + code.GetDescription());
return code;
}
try
{
// [ZH] 获取机器人型号信息
// [EN] Get the robot model information
(string info, code) = controller.GetArmModelInfo();
if (code != StatusCode.OK)
{
Console.WriteLine("Get Robot Model Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("Model: " + info);
}
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.1.5 获取机器人运行状态
| 方法名 | GetRobotState() |
|---|---|
| 描述 | 获取捷勃特机器人的当前运行状态 |
| 请求参数 | 无参数 |
| 返回值 | RobotState: 机器人运行状态枚举值 StatusCode: 获取操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
示例代码
cs
using Agilebot.IR;
using Agilebot.IR.Types;
public class GetRobotState
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
if (code != StatusCode.OK)
{
Console.WriteLine("Connect Robot Failed: " + code.GetDescription());
return code;
}
try
{
// [ZH] 获取机器人运行状态
// [EN] Get the robot running state
(RobotState state, code) = controller.GetRobotState();
if (code != StatusCode.OK)
{
Console.WriteLine("Get RobotState Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("RobotState: " + state);
}
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.1.6 获取当前控制器运行状态
| 方法名 | GetCtrlState() |
|---|---|
| 描述 | 获取捷勃特机器人控制器的当前运行状态 |
| 请求参数 | 无参数 |
| 返回值 | CtrlState: 控制器运行状态枚举值 StatusCode: 获取操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
示例代码
cs
using Agilebot.IR;
using Agilebot.IR.Types;
public class GetCtrlState
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
if (code != StatusCode.OK)
{
Console.WriteLine("Connect Robot Failed: " + code.GetDescription());
return code;
}
try
{
// [ZH] 获取控制器运行状态
// [EN] Get the controller running state
(CtrlState state, code) = controller.GetCtrlState();
if (code != StatusCode.OK)
{
Console.WriteLine("Get CtrlState Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("CtrlState: " + state);
}
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.1.7 获取当前伺服状态
| 方法名 | GetServoState() |
|---|---|
| 描述 | 获取捷勃特机器人伺服系统的当前状态 |
| 请求参数 | 无参数 |
| 返回值 | ServoState: 伺服系统状态枚举值 StatusCode: 获取操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
示例代码
cs
using Agilebot.IR;
using Agilebot.IR.Types;
public class GetServoState
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
if (code != StatusCode.OK)
{
Console.WriteLine("Connect Robot Failed: " + code.GetDescription());
return code;
}
try
{
// [ZH] 获取伺服运行状态
// [EN] Get the servo operating state
(ServoState state, code) = controller.GetServoState();
if (code != StatusCode.OK)
{
Console.WriteLine("Get ServoState Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("ServoState: " + state);
}
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.1.8 获取机器人控制器版本
| 方法名 | GetVersion() |
|---|---|
| 描述 | 获取捷勃特机器人控制器的软件版本信息 |
| 请求参数 | 无参数 |
| 返回值 | string: 控制器软件版本字符串 StatusCode: 获取操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
示例代码
cs
using Agilebot.IR;
public class GetVersion
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
if (code != StatusCode.OK)
{
Console.WriteLine("Connect Robot Failed: " + code.GetDescription());
return code;
}
try
{
// [ZH] 获取机器人控制器版本
// [EN] Get the robot controller version
string version;
(version, code) = controller.GetVersion();
if (code != StatusCode.OK)
{
Console.WriteLine("Get version Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("Version: " + version);
}
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.1.9 设置机器人的 LED 指示灯
| 方法名 | SwitchLedLight( bool mode ) |
|---|---|
| 描述 | 控制捷勃特机器人 LED 指示灯的开关状态 |
| 请求参数 | mode : bool LED 指示灯控制模式,true 表示开启,false 表示关闭 |
| 返回值 | StatusCode: 操作执行结果 |
| 兼容性 | 仅支持协作机器人,需要控制器版本 1.3.6 及以上,工业机器人不支持 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.1.3+ 工业 (Bronze): 不支持 |
示例代码
cs
using Agilebot.IR;
public class SwitchLedLight
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
if (code != StatusCode.OK)
{
Console.WriteLine("Connect Robot Failed: " + code.GetDescription());
return code;
}
try
{
// [ZH] 关闭灯光
// [EN] Turn off the LED light
code = controller.SwitchLedLight(false);
if (code != StatusCode.OK)
{
Console.WriteLine("Switch Led Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("Switch Led Light Off.");
}
Thread.Sleep(2000);
// [ZH] 打开灯光
// [EN] Turn on the LED light
code = controller.SwitchLedLight(true);
if (code != StatusCode.OK)
{
Console.WriteLine("Switch Led Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("Switch Led Light On.");
}
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Disconnect from the robot
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.1.10 机器人伺服启动
| 方法名 | ServoOn() |
|---|---|
| 描述 | 启动捷勃特机器人的伺服系统,使机器人进入可控制状态 |
| 请求参数 | 无参数 |
| 返回值 | StatusCode: 伺服启动操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
4.1.11 机器人伺服关闭
| 方法名 | ServoOff() |
|---|---|
| 描述 | 关闭捷勃特机器人的伺服系统,使机器人进入安全停止状态 |
| 请求参数 | 无参数 |
| 返回值 | StatusCode: 伺服关闭操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
4.1.12 让机器人伺服重置
| 方法名 | ServoReset() |
|---|---|
| 描述 | 重置捷勃特机器人的伺服系统,清除错误状态并准备重新启动 |
| 请求参数 | 无参数 |
| 返回值 | StatusCode: 伺服重置操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
示例代码
cs
using Agilebot.IR;
public class ServoOperation
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
if (code != StatusCode.OK)
{
Console.WriteLine("Connect Robot Failed: " + code.GetDescription());
return code;
}
try
{
// [ZH] 机械臂伺服重置
// [EN] Reset the robot arm servo
code = controller.ServoReset();
if (code != StatusCode.OK)
{
Console.WriteLine("Servo Reset Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("Servo Reset Success.");
}
Thread.Sleep(3000);
// [ZH] 机械臂伺服关闭
// [EN] Turn off the robot arm servo
code = controller.ServoOff();
if (code != StatusCode.OK)
{
Console.WriteLine("Servo Off Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("Servo Off Success.");
}
Thread.Sleep(3000);
// [ZH] 机械臂伺服打开
// [EN] Turn on the robot arm servo
code = controller.ServoOn();
if (code != StatusCode.OK)
{
Console.WriteLine("Servo On Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("Servo On Success.");
}
Thread.Sleep(3000);
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}4.1.13 机器人紧急停止
| 方法名 | Estop() |
|---|---|
| 描述 | 执行捷勃特机器人的紧急停止,立即停止所有运动并进入安全状态 |
| 请求参数 | 无参数 |
| 返回值 | StatusCode: 紧急停止操作执行结果 |
| 兼容的机器人软件版本 | 协作 (Copper): v7.5.0.0+ 工业 (Bronze): v7.5.0.0+ |
示例代码
cs
using Agilebot.IR;
public class Estop
{
public static StatusCode Run(string controllerIP, bool useLocalProxy = true)
{
// [ZH] 初始化捷勃特机器人
// [EN] Initialize the Agilebot robot
Arm controller = new Arm(controllerIP, useLocalProxy);
// [ZH] 连接到捷勃特机器人
// [EN] Connect to the Agilebot robot
StatusCode code = controller.ConnectSync();
if (code != StatusCode.OK)
{
Console.WriteLine("Connect Robot Failed: " + code.GetDescription());
return code;
}
try
{
// [ZH] 触发机器人急停
// [EN] Trigger the robot emergency stop
code = controller.Estop();
if (code != StatusCode.OK)
{
Console.WriteLine("Emergency Stop Failed: " + code.GetDescription());
}
else
{
Console.WriteLine("Emergency Stop Success");
}
}
catch (Exception ex)
{
Console.WriteLine($"执行过程中发生异常/Exception occurred during execution: {ex.Message}");
code = StatusCode.OtherReason;
}
finally
{
// [ZH] 关闭连接
// [EN] Close the connection
StatusCode disconnectCode = controller.Disconnect();
if (disconnectCode != StatusCode.OK)
{
Console.WriteLine(disconnectCode.GetDescription());
if (code == StatusCode.OK)
code = disconnectCode;
}
}
return code;
}
}