Commit 959e9b94 张东亮

关闭加载监控相机

1 个父辈 52a58a0b
...@@ -55,11 +55,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -55,11 +55,15 @@ namespace OnlineStore.DeviceLibrary
equipsMap.Add(3, robotEquip); equipsMap.Add(3, robotEquip);
//先初始化设备 //先初始化设备
// RFIDManager.Open(); // RFIDManager.Open();
//LogUtil.info("准备加载板卡配置");
HCBoardManager.InitConfig(); HCBoardManager.InitConfig();
// LogUtil.info("准备加载IO");
IOManager.Init(); IOManager.Init();
// LogUtil.info("准备加载轴");
AxisManager.Init(); AxisManager.Init();
//LogUtil.info("准备开卡");
AxisManager.instance.OpenCard(); AxisManager.instance.OpenCard();
// LogUtil.info("准备加载相机配置");
//初始化摄像机配置 //初始化摄像机配置
CodeManager.LoadConfig(); CodeManager.LoadConfig();
......
...@@ -24,16 +24,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -24,16 +24,16 @@ namespace OnlineStore.DeviceLibrary
{ {
if (loadCameraState) if (loadCameraState)
return; return;
string path = @".\Config\Camera.json"; //string path = @".\Config\Camera.json";
if (!File.Exists(path)) //if (!File.Exists(path))
{ //{
LogUtil.error(Name + "找不到监控相机配置文件" + path); // LogUtil.error(Name + "找不到监控相机配置文件" + path);
} //}
camera = new Asa.Camera.VisionLib(path); //camera = new Asa.Camera.VisionLib(path);
camerathread = new Thread[2]; //camerathread = new Thread[2];
//pictureBox1.Image = bmp; ////pictureBox1.Image = bmp;
StartCamera(); //StartCamera();
loadCameraState = true; loadCameraState = true;
} }
void StartCamera() void StartCamera()
...@@ -51,36 +51,36 @@ namespace OnlineStore.DeviceLibrary ...@@ -51,36 +51,36 @@ namespace OnlineStore.DeviceLibrary
void startMonitor(object obj) void startMonitor(object obj)
{ {
if (!loadCameraState) //if (!loadCameraState)
{ //{
LogUtil.error(Name + "监控相机初始化失败,无法开启"); // LogUtil.error(Name + "监控相机初始化失败,无法开启");
return; // return;
} //}
string name = (string)obj; //string name = (string)obj;
while (IsOpen) //while (IsOpen)
{ //{
Bitmap bmp = AcqImage(name); // Bitmap bmp = AcqImage(name);
if (bmp != null) // if (bmp != null)
{ // {
camera_event?.Invoke(new CameraArgs(name, bmp)); // camera_event?.Invoke(new CameraArgs(name, bmp));
} // }
//if (MoveInfo != null) // //if (MoveInfo != null)
//{ // //{
// if (MoveInfo.MoveType.Equals(MoveType.InStore) || MoveInfo.MoveType.Equals(MoveType.OutStore)) // // if (MoveInfo.MoveType.Equals(MoveType.InStore) || MoveInfo.MoveType.Equals(MoveType.OutStore))
// { // // {
// if (CheckASide() && name.Equals("box_A")) // // if (CheckASide() && name.Equals("box_A"))
// { // // {
// SaveImage(name); // // SaveImage(name);
// } // // }
// else // // else
// { // // {
// SaveImage("box_B"); // // SaveImage("box_B");
// } // // }
// } // // }
//} // //}
Thread.Sleep(300); // Thread.Sleep(300);
} //}
} }
void StopCamera() void StopCamera()
{ {
......
...@@ -26,24 +26,7 @@ namespace JAKA ...@@ -26,24 +26,7 @@ namespace JAKA
} }
return false; return false;
} }
/// <summary>
/// 注册机器人出错时的回调函数
/// </summary>
/// <returns></returns>
bool SetErrorHandler()
{
int rtn = jakaAPI.set_error_handler(ref _handle, user_error_handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"SetErrorHandler OK");
return true;
}
else
{
ErrorLog($"SetErrorHandler Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary> /// <summary>
/// 销毁机器人控制句柄 /// 销毁机器人控制句柄
/// </summary> /// </summary>
...@@ -97,23 +80,7 @@ namespace JAKA ...@@ -97,23 +80,7 @@ namespace JAKA
} }
return false; return false;
} }
/// <summary>
/// 机器人关机
/// </summary>
public bool ShutDown()
{
int rtn = jakaAPI.shut_down(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"ShutDown OK");
return true;
}
else
{
ErrorLog($"ShutDown Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary> /// <summary>
/// 机器人上使能 /// 机器人上使能
/// </summary> /// </summary>
...@@ -149,407 +116,305 @@ namespace JAKA ...@@ -149,407 +116,305 @@ namespace JAKA
return false; return false;
} }
/// <summary>
/// 机器人手动模式下运动
/// </summary>
/// <param name="aj_num">关节空间下代表关节号[0-5],笛卡尔下依次为轴 x,y,z,rx,ry,rz</param>
/// <param name="move_mode">机器人运动模式,增量运动或者绝对运动(即持续 jog 运动)</param>
/// <param name="coordType">机器人运动坐标系,工具坐标系,基坐标系(当前的世界/用户坐标系)或关节空间</param>
/// <param name="vel_cmd">指令速度,旋转轴或关节运动单位为 rad/s,移动轴单位为 mm/</param>
/// <param name="pos_cmd">指令位置,旋转轴或关节运动单位为 rad,移动轴单位为 m</param>
/// <returns></returns>
bool Jog(int aj_num,JKTYPE.MoveMode move_mode,JKTYPE.CoordType coordType,double vel_cmd,double pos_cmd)
{
int rtn = jakaAPI.jog(ref _handle,aj_num,move_mode,coordType,vel_cmd,pos_cmd);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"Jog OK");
return true;
}
else
{
ErrorLog($"Jog Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary> /// <summary>
/// 机器人手动模式下运动停止 /// 查询数字输出状态
/// </summary> /// </summary>
/// <param name="num">机械臂轴号 0-5,num为-1时,停止所有轴 </param> /// <param name="iOType"> DO 类型</param>
/// <param name="index">DO 索引(从 0 开始)</param>
/// <param name="value">DO 状态查询结果</param>
/// <returns></returns> /// <returns></returns>
public bool JogStop(int num=-1) public bool GetDigitalOutput(JKTYPE.IOType iOType, int index, out bool result)
{ {
int rtn = jakaAPI.jog_stop(ref _handle,ref num); result = false;
int rtn = jakaAPI.get_digital_output(ref _handle, iOType, index, ref result);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"JogStop OK"); DebugLog($"GetDigitalOutput [{iOType}][{index}={result}] OK");
return true; return true;
} }
else else
{ {
ErrorLog($"JogStop Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"GetDigitalOutput [{iOType}][{index}={result}] Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 机器人关节运动 /// 运行当前加载的作业程序
/// </summary> /// </summary>
/// <param name="jointPos">机器人关节运动目标位置</param> public bool Run()
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="isBlock">设置接口是否为阻塞接口,TRUE 为阻塞接口 FALSE 为非阻塞接口</param>
/// <param name="speed">机器人关节运动速度,单位:rad/s</param>
/// <returns></returns>
bool JointMove(JKTYPE.JointValue jointPos,JKTYPE.MoveMode moveMode,bool isBlock,double speed)
{ {
int rtn = jakaAPI.joint_move(ref _handle,ref jointPos,moveMode,isBlock,speed); int rtn = jakaAPI.program_run(ref _handle);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"JointMove OK"); InfoLog($"Run OK");
return true; return false;
} }
else else
{ {
ErrorLog($"JointMove Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"Run Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 机器人末端直线运动 /// 暂停当前运行的作业程序
/// </summary> /// </summary>
/// <param name="endPos">机器人末端运动目标位置</param> public bool Pause()
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="isBlock">设置接口是否为阻塞接口,TRUE 为阻塞接口 FALSE 为非阻塞接口</param>
/// <param name="speed">机器人直线运动速度,单位:mm/s</param>
/// <returns></returns>
bool LinaerMove(JKTYPE.CartesianPose endPos, JKTYPE.MoveMode moveMode, bool isBlock, double speed)
{ {
int rtn = jakaAPI.linear_move(ref _handle, ref endPos, moveMode, isBlock, speed); int rtn = jakaAPI.program_pause(ref _handle);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"LinaerMove OK"); InfoLog($"Pause OK");
return true; return false;
} }
else else
{ {
ErrorLog($"LinaerMove Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"Pause Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 机器人伺服位置控制模式使能 /// 继续运行当前暂停的作业程序
/// </summary> /// </summary>
/// <param name="enable">TRUE 为进入伺服位置控制模式,FALSE 表示退出该模式</param> public bool Resume()
/// <returns></returns>
public bool ServoMoveEnable(bool enable)
{ {
int rtn = jakaAPI.servo_move_enable(ref _handle,enable); int rtn = jakaAPI.program_resume(ref _handle);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"ServoMoveEnable OK"); InfoLog($"Resume OK");
return true; return false;
} }
else else
{ {
ErrorLog($"ServoMoveEnable Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"Resume Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 机器人关节空间伺服模式运动 /// 终止当前执行的作业程序
/// </summary>
/// <param name="jointPos">机器人关节运动目标位置</param>
/// <param name="moveMode">指定运动模式:绝对运动或相对运动</param>
/// <returns></returns>
bool ServoJ(JKTYPE.JointValue jointPos,JKTYPE.MoveMode moveMode)
{
int rtn = jakaAPI.servo_j(ref _handle,ref jointPos,moveMode);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"ServoJ OK");
return true;
}
else
{
ErrorLog($"ServoJ Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人关节空间伺服模式运动扩展
/// </summary> /// </summary>
/// <param name="jointPos">机器人关节运动目标位置</param> public bool Abort()
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="stepNum">倍分周期,servo_j 运动周期为 step_num*8ms,其中 step_num>=1</param>
/// <returns></returns>
bool ServoJExtend(JKTYPE.JointValue jointPos, JKTYPE.MoveMode moveMode,int stepNum)
{ {
int rtn = jakaAPI.servo_j_extend(ref _handle, ref jointPos, moveMode,stepNum); int rtn = jakaAPI.program_abort(ref _handle);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"ServoJExtend OK"); InfoLog($"Abort OK");
return true; return true;
} }
else else
{ {
ErrorLog($"ServoJExtend Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"Abort Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 机器人笛卡尔空间伺服模式运动 /// 获取机器人作业程序的执行状态
/// </summary> /// </summary>
/// <param name="cartesianPose">机器人笛卡尔空间运动目标位置</param> /// <param name="status">作业程序执行状态查询结果</param>
/// <param name="moveMode">指定运动模式:ABS 代表绝对运动,INCR 代表相对运动</param>
/// <returns></returns> /// <returns></returns>
bool ServoP(JKTYPE.CartesianPose cartesianPose, JKTYPE.MoveMode moveMode) public bool GetProgramState(out JKTYPE.ProgramState status)
{ {
int rtn = jakaAPI.servo_p(ref _handle, ref cartesianPose, moveMode); status = new JKTYPE.ProgramState();
int rtn = jakaAPI.get_program_state(ref _handle,ref status);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"ServoP OK"); DebugLog($"GetProgramState OK");
return true; return false;
} }
else else
{ {
ErrorLog($"ServoP Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"GetProgramState Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 机器人笛卡尔空间伺服模式运动扩展 /// 获取机器人状态监测数据
/// </summary> /// </summary>
/// <param name="jointPos">机器人笛卡尔空间运动目标位置</param> /// <param name="robotStatus"></param>
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="stepNum">倍分周期,servo_p 运动周期为 step_num*8ms,其中 step_num>=1</param>
/// <returns></returns> /// <returns></returns>
bool ServoPExtend(JKTYPE.CartesianPose cartesianPose, JKTYPE.MoveMode moveMode, int stepNum) public bool GetRobotStatus(out JKTYPE.RobotStatus robotStatus)
{ {
int rtn = jakaAPI.servo_p_extend(ref _handle, ref cartesianPose, moveMode, stepNum); robotStatus = new JKTYPE.RobotStatus();
int rtn = jakaAPI.get_robot_status(ref _handle,ref robotStatus);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"ServoPExtend OK"); DebugLog($"GetRobotDtatus OK");
return true; return true;
} }
else else
{ {
ErrorLog($"ServoPExtend Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"GetRobotDtatus Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 设置数字输出变量 /// 机器人运动终止
/// </summary> /// </summary>
/// <param name="iOType"> DO 类型</param>
/// <param name="index">DO 索引(从 0 开始)</param>
/// <param name="value">DO 设置值</param>
/// <returns></returns> /// <returns></returns>
bool SetDigitalOutput(JKTYPE.IOType iOType,int index,bool value) public bool MotionAbort()
{ {
int rtn = jakaAPI.set_digital_output(ref _handle, iOType, index,value); int rtn = jakaAPI.motion_abort(ref _handle);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"SetDigitalOutput [{iOType}][{index}={value}] OK"); DebugLog($"MotionAbort OK");
return true; return true;
} }
else else
{ {
ErrorLog($"SetDigitalOutput [{iOType}][{index}={value}] Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"MotionAbort Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 设置模拟输出变量 /// 设置机器人错误码文件存放路径,
/// 需要使用 get_last_error 接口时需要设置错误码文件路径,如果不使用
///get_last_error 接口,则不需要设置该接口
/// </summary> /// </summary>
/// <param name="iOType"> DO 类型</param> /// <param name="path"></param>
/// <param name="index">DO 索引(从 0 开始)</param>
/// <param name="value">DO 设置值</param>
/// <returns></returns> /// <returns></returns>
bool SetAnalogOutput(JKTYPE.IOType iOType, int index, float value) bool SetErrorCodeFilePath(string path)
{ {
int rtn = jakaAPI.set_analog_output(ref _handle, iOType, index, value); StringBuilder sb = new StringBuilder(path);
int rtn = jakaAPI.set_errorcode_file_path(ref _handle,sb);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"SetAnalogOutput [{iOType}][{index}={value}] OK"); DebugLog($"SetErrorCodeFilePath OK");
return true; return true;
} }
else else
{ {
ErrorLog($"SetAnalogOutput [{iOType}][{index}={value}] Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"SetErrorCodeFilePath Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 查询数字输入状态 /// 获取机器人运行过程中最后一个错误码,当调用 clear_error 时,最后一个错误码会清零
/// </summary> /// </summary>
/// <param name="iOType"> DI 类型</param> /// <param name="errorCode"></param>
/// <param name="index">DI 索引(从 0 开始)</param>
/// <param name="value">DI 状态查询结果</param>
/// <returns></returns> /// <returns></returns>
public bool GetDigitalInput(JKTYPE.IOType iOType, int index,out bool result) public bool GetLastError(ref JKTYPE.ErrorCode errorCode)
{ {
result = false; int rtn = jakaAPI.get_last_error(ref _handle,ref errorCode);
int rtn = jakaAPI.get_digital_input(ref _handle, iOType, index,ref result);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"GetDigitalInput [{iOType}][{index}={result}] OK"); DebugLog($"GetLastError OK");
return true; return true;
} }
else else
{ {
ErrorLog($"GetDigitalInput [{iOType}][{index}={result}] Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"GetLastError Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 查询数字输出状态 /// 清除错误,最后一个错误码会清零
/// </summary> /// </summary>
/// <param name="iOType"> DO 类型</param>
/// <param name="index">DO 索引(从 0 开始)</param>
/// <param name="value">DO 状态查询结果</param>
/// <returns></returns> /// <returns></returns>
public bool GetDigitalOutput(JKTYPE.IOType iOType, int index, out bool result) public bool ClearError()
{ {
result = false; int rtn = jakaAPI.clear_error(ref _handle);
int rtn = jakaAPI.get_digital_output(ref _handle, iOType, index, ref result);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"GetDigitalOutput [{iOType}][{index}={result}] OK"); InfoLog($"ClearError OK");
return true; return true;
} }
else else
{ {
ErrorLog($"GetDigitalOutput [{iOType}][{index}={result}] Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"ClearError Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 运行当前加载的作业程序
/// </summary>
public bool Run()
{
int rtn = jakaAPI.program_run(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"Run OK");
return false;
}
else
{
ErrorLog($"Run Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 暂停当前运行的作业程序
/// </summary>
public bool Pause()
{
int rtn = jakaAPI.program_pause(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"Pause OK");
return false;
}
else
{
ErrorLog($"Pause Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary>
/// 继续运行当前暂停的作业程序
/// </summary>
public bool Resume() void user_error_handle(int error_code)
{ {
int rtn = jakaAPI.program_resume(ref _handle); ErrorLog($"机械臂发生异常,异常码:{error_code}");
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"Resume OK");
return false;
}
else
{
ErrorLog($"Resume Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
} }
#region 未使用
/// <summary> /// <summary>
/// 终止当前执行的作业程序 /// 设置机器人状态数据自动更新时间间隔
/// </summary> /// </summary>
public bool Abort() /// <param name="ms"> 时间参数,单位毫秒</param>
/// <returns></returns>
public bool SetStatusDataUpdateTimeInterval(float ms)
{ {
int rtn = jakaAPI.program_abort(ref _handle); int rtn = jakaAPI.set_status_data_update_time_interval(ref _handle, ms);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
InfoLog($"Abort OK"); DebugLog($"SetStatusDataUpdateTimeInterval OK");
return true; return true;
} }
else else
{ {
ErrorLog($"Abort Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"SetStatusDataUpdateTimeInterval Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 加载指定的作业程序 /// 设置网络异常,机器人终止运动等待时间
/// </summary> /// </summary>
/// <param name="file">加载指定的作业程序 (加载轨迹复现数据,轨迹复现数据的加载需要在文件夹名字前加上 track/)</param> /// <param name="ms">时间参数,单位毫秒</param>
/// <param name="mnt">网络异常时机器人需要进行的动作类型</param>
/// <returns></returns> /// <returns></returns>
public bool Load(string file) public bool SetNetworkExceptionHandle(float ms, JKTYPE.ProcessType mnt)
{ {
int rtn = jakaAPI.program_load(ref _handle,file.ToCharArray()); int rtn = jakaAPI.set_network_exception_handle(ref _handle, ms, mnt);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
InfoLog($"Load OK"); DebugLog($"SetNetworkExceptionHandle OK");
return true; return true;
} }
else else
{ {
ErrorLog($"Load Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"SetNetworkExceptionHandle Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 获取已加载的作业程序的名字 /// 设置 SDK 日志路径
/// </summary> /// </summary>
/// <param name="file">程序文件路径</param> /// <param name="filepath">SDK 日志路径</param>
/// <returns></returns> /// <returns></returns>
public bool GetLoadedProgram(StringBuilder file) public bool SetSDKFilePath(string filepath)
{ {
int rtn = jakaAPI.get_loaded_program(ref _handle,file); char[] chars = filepath.ToCharArray();
int rtn = jakaAPI.set_SDK_filepath(ref _handle, ref chars);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"GetLoadedProgram OK"); DebugLog($"SetSDKFilePath OK");
return true; return true;
} }
else else
{ {
ErrorLog($"GetLoadedProgram Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"SetSDKFilePath Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 获取机器人作业程序的执行状态 /// 设置 SDK 是否开启调试模式
/// </summary> /// </summary>
/// <param name="status">作业程序执行状态查询结果</param> /// <param name="mode"></param>
/// <returns></returns> /// <returns></returns>
public bool GetProgramState(out JKTYPE.ProgramState status) public bool SetDebugMode(bool mode)
{ {
status = new JKTYPE.ProgramState(); int rtn = jakaAPI.set_debug_mode(ref _handle, mode);
int rtn = jakaAPI.get_program_state(ref _handle,ref status);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"GetProgramState OK"); DebugLog($"SetDebugMode OK");
return false; return true;
} }
else else
{ {
ErrorLog($"GetProgramState Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"SetDebugMode Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
...@@ -579,7 +444,7 @@ namespace JAKA ...@@ -579,7 +444,7 @@ namespace JAKA
public bool GetRapidRate(out double rate) public bool GetRapidRate(out double rate)
{ {
rate = 0; rate = 0;
int rtn = jakaAPI.get_rapidrate(ref _handle,ref rate); int rtn = jakaAPI.get_rapidrate(ref _handle, ref rate);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"GetRapidRate OK"); DebugLog($"GetRapidRate OK");
...@@ -617,7 +482,7 @@ namespace JAKA ...@@ -617,7 +482,7 @@ namespace JAKA
public bool IsInDragMode(out bool inDrag) public bool IsInDragMode(out bool inDrag)
{ {
inDrag = false; inDrag = false;
int rtn = jakaAPI.is_in_drag_mode(ref _handle,ref inDrag); int rtn = jakaAPI.is_in_drag_mode(ref _handle, ref inDrag);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"IsInDragMode OK"); DebugLog($"IsInDragMode OK");
...@@ -732,7 +597,7 @@ namespace JAKA ...@@ -732,7 +597,7 @@ namespace JAKA
/// <returns></returns> /// <returns></returns>
public bool SetCollisionLevel(int level) public bool SetCollisionLevel(int level)
{ {
int rtn = jakaAPI.set_collision_level(ref _handle,level); int rtn = jakaAPI.set_collision_level(ref _handle, level);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"SetCollisionLevel OK"); DebugLog($"SetCollisionLevel OK");
...@@ -752,7 +617,7 @@ namespace JAKA ...@@ -752,7 +617,7 @@ namespace JAKA
public bool GetCollisionLevel(out int level) public bool GetCollisionLevel(out int level)
{ {
level = 0; level = 0;
int rtn = jakaAPI.get_collision_level(ref _handle,ref level); int rtn = jakaAPI.get_collision_level(ref _handle, ref level);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"GetCollisionLevel OK"); DebugLog($"GetCollisionLevel OK");
...@@ -771,7 +636,7 @@ namespace JAKA ...@@ -771,7 +636,7 @@ namespace JAKA
/// <returns></returns> /// <returns></returns>
public bool SetPayload(JKTYPE.PayLoad payload) public bool SetPayload(JKTYPE.PayLoad payload)
{ {
int rtn = jakaAPI.set_payload(ref _handle,ref payload); int rtn = jakaAPI.set_payload(ref _handle, ref payload);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"SetPayload OK"); DebugLog($"SetPayload OK");
...@@ -810,7 +675,7 @@ namespace JAKA ...@@ -810,7 +675,7 @@ namespace JAKA
/// <returns></returns> /// <returns></returns>
public bool GetSDKVersion(StringBuilder version) public bool GetSDKVersion(StringBuilder version)
{ {
int rtn = jakaAPI.get_sdk_version(ref _handle,version); int rtn = jakaAPI.get_sdk_version(ref _handle, version);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"GetSDKVersion OK"); DebugLog($"GetSDKVersion OK");
...@@ -822,186 +687,336 @@ namespace JAKA ...@@ -822,186 +687,336 @@ namespace JAKA
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 获取机器人状态监测数据 /// 加载指定的作业程序
/// </summary> /// </summary>
/// <param name="robotStatus"></param> /// <param name="file">加载指定的作业程序 (加载轨迹复现数据,轨迹复现数据的加载需要在文件夹名字前加上 track/)</param>
/// <returns></returns> /// <returns></returns>
public bool GetRobotStatus(out JKTYPE.RobotStatus robotStatus) public bool Load(string file)
{ {
robotStatus = new JKTYPE.RobotStatus(); int rtn = jakaAPI.program_load(ref _handle, file.ToCharArray());
int rtn = jakaAPI.get_robot_status(ref _handle,ref robotStatus);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"GetRobotDtatus OK"); InfoLog($"Load OK");
return true; return true;
} }
else else
{ {
ErrorLog($"GetRobotDtatus Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"Load Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 设置 SDK 是否开启调试模式 /// 获取已加载的作业程序的名字
/// </summary> /// </summary>
/// <param name="mode"></param> /// <param name="file">程序文件路径</param>
/// <returns></returns> /// <returns></returns>
public bool SetDebugMode(bool mode) public bool GetLoadedProgram(StringBuilder file)
{ {
int rtn = jakaAPI.set_debug_mode(ref _handle,mode); int rtn = jakaAPI.get_loaded_program(ref _handle, file);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"SetDebugMode OK"); DebugLog($"GetLoadedProgram OK");
return true; return true;
} }
else else
{ {
ErrorLog($"SetDebugMode Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"GetLoadedProgram Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 机器人运动终止 /// 机器人手动模式下运动
/// </summary> /// </summary>
/// <param name="aj_num">关节空间下代表关节号[0-5],笛卡尔下依次为轴 x,y,z,rx,ry,rz</param>
/// <param name="move_mode">机器人运动模式,增量运动或者绝对运动(即持续 jog 运动)</param>
/// <param name="coordType">机器人运动坐标系,工具坐标系,基坐标系(当前的世界/用户坐标系)或关节空间</param>
/// <param name="vel_cmd">指令速度,旋转轴或关节运动单位为 rad/s,移动轴单位为 mm/</param>
/// <param name="pos_cmd">指令位置,旋转轴或关节运动单位为 rad,移动轴单位为 m</param>
/// <returns></returns> /// <returns></returns>
public bool MotionAbort() bool Jog(int aj_num, JKTYPE.MoveMode move_mode, JKTYPE.CoordType coordType, double vel_cmd, double pos_cmd)
{ {
int rtn = jakaAPI.motion_abort(ref _handle); int rtn = jakaAPI.jog(ref _handle, aj_num, move_mode, coordType, vel_cmd, pos_cmd);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"MotionAbort OK"); DebugLog($"Jog OK");
return true; return true;
} }
else else
{ {
ErrorLog($"MotionAbort Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"Jog Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 设置机器人错误码文件存放路径, /// 机器人手动模式下运动停止
/// 需要使用 get_last_error 接口时需要设置错误码文件路径,如果不使用
///get_last_error 接口,则不需要设置该接口
/// </summary> /// </summary>
/// <param name="path"></param> /// <param name="num">机械臂轴号 0-5,num为-1时,停止所有轴 </param>
/// <returns></returns> /// <returns></returns>
bool SetErrorCodeFilePath(string path) public bool JogStop(int num = -1)
{ {
StringBuilder sb = new StringBuilder(path); int rtn = jakaAPI.jog_stop(ref _handle, ref num);
int rtn = jakaAPI.set_errorcode_file_path(ref _handle,sb);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"SetErrorCodeFilePath OK"); DebugLog($"JogStop OK");
return true; return true;
} }
else else
{ {
ErrorLog($"SetErrorCodeFilePath Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"JogStop Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 获取机器人运行过程中最后一个错误码,当调用 clear_error 时,最后一个错误码会清零 /// 机器人关节运动
/// </summary> /// </summary>
/// <param name="errorCode"></param> /// <param name="jointPos">机器人关节运动目标位置</param>
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="isBlock">设置接口是否为阻塞接口,TRUE 为阻塞接口 FALSE 为非阻塞接口</param>
/// <param name="speed">机器人关节运动速度,单位:rad/s</param>
/// <returns></returns> /// <returns></returns>
public bool GetLastError(ref JKTYPE.ErrorCode errorCode) bool JointMove(JKTYPE.JointValue jointPos, JKTYPE.MoveMode moveMode, bool isBlock, double speed)
{ {
int rtn = jakaAPI.get_last_error(ref _handle,ref errorCode); int rtn = jakaAPI.joint_move(ref _handle, ref jointPos, moveMode, isBlock, speed);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"GetLastError OK"); DebugLog($"JointMove OK");
return true; return true;
} }
else else
{ {
ErrorLog($"GetLastError Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"JointMove Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 清除错误,最后一个错误码会清零 /// 机器人末端直线运动
/// </summary> /// </summary>
/// <param name="endPos">机器人末端运动目标位置</param>
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="isBlock">设置接口是否为阻塞接口,TRUE 为阻塞接口 FALSE 为非阻塞接口</param>
/// <param name="speed">机器人直线运动速度,单位:mm/s</param>
/// <returns></returns> /// <returns></returns>
public bool ClearError() bool LinaerMove(JKTYPE.CartesianPose endPos, JKTYPE.MoveMode moveMode, bool isBlock, double speed)
{ {
int rtn = jakaAPI.clear_error(ref _handle); int rtn = jakaAPI.linear_move(ref _handle, ref endPos, moveMode, isBlock, speed);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
InfoLog($"ClearError OK"); DebugLog($"LinaerMove OK");
return true; return true;
} }
else else
{ {
ErrorLog($"ClearError Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"LinaerMove Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 设置 SDK 日志路径 /// 机器人伺服位置控制模式使能
/// </summary> /// </summary>
/// <param name="filepath">SDK 日志路径</param> /// <param name="enable">TRUE 为进入伺服位置控制模式,FALSE 表示退出该模式</param>
/// <returns></returns> /// <returns></returns>
public bool SetSDKFilePath(string filepath) public bool ServoMoveEnable(bool enable)
{ {
char[] chars = filepath.ToCharArray(); int rtn = jakaAPI.servo_move_enable(ref _handle, enable);
int rtn = jakaAPI.set_SDK_filepath(ref _handle, ref chars);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"SetSDKFilePath OK"); DebugLog($"ServoMoveEnable OK");
return true; return true;
} }
else else
{ {
ErrorLog($"SetSDKFilePath Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"ServoMoveEnable Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 设置网络异常,机器人终止运动等待时间 /// 机器人关节空间伺服模式运动
/// </summary> /// </summary>
/// <param name="ms">时间参数,单位毫秒</param> /// <param name="jointPos">机器人关节运动目标位置</param>
/// <param name="mnt">网络异常时机器人需要进行的动作类型</param> /// <param name="moveMode">指定运动模式:绝对运动或相对运动</param>
/// <returns></returns> /// <returns></returns>
public bool SetNetworkExceptionHandle(float ms,JKTYPE.ProcessType mnt) bool ServoJ(JKTYPE.JointValue jointPos, JKTYPE.MoveMode moveMode)
{ {
int rtn = jakaAPI.set_network_exception_handle(ref _handle,ms,mnt); int rtn = jakaAPI.servo_j(ref _handle, ref jointPos, moveMode);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"SetNetworkExceptionHandle OK"); DebugLog($"ServoJ OK");
return true; return true;
} }
else else
{ {
ErrorLog($"SetNetworkExceptionHandle Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"ServoJ Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 设置机器人状态数据自动更新时间间隔 /// 机器人关节空间伺服模式运动扩展
/// </summary> /// </summary>
/// <param name="ms"> 时间参数,单位毫秒</param> /// <param name="jointPos">机器人关节运动目标位置</param>
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="stepNum">倍分周期,servo_j 运动周期为 step_num*8ms,其中 step_num>=1</param>
/// <returns></returns> /// <returns></returns>
public bool SetStatusDataUpdateTimeInterval(float ms) bool ServoJExtend(JKTYPE.JointValue jointPos, JKTYPE.MoveMode moveMode, int stepNum)
{ {
int rtn = jakaAPI.set_status_data_update_time_interval(ref _handle, ms); int rtn = jakaAPI.servo_j_extend(ref _handle, ref jointPos, moveMode, stepNum);
if (rtn == RtnCode.ERR_SUCC) if (rtn == RtnCode.ERR_SUCC)
{ {
DebugLog($"SetStatusDataUpdateTimeInterval OK"); DebugLog($"ServoJExtend OK");
return true; return true;
} }
else else
{ {
ErrorLog($"SetStatusDataUpdateTimeInterval Fail:{RtnCode.GetStrByCode(rtn)}"); ErrorLog($"ServoJExtend Fail:{RtnCode.GetStrByCode(rtn)}");
} }
return false; return false;
} }
void user_error_handle(int error_code) /// <summary>
/// 机器人笛卡尔空间伺服模式运动
/// </summary>
/// <param name="cartesianPose">机器人笛卡尔空间运动目标位置</param>
/// <param name="moveMode">指定运动模式:ABS 代表绝对运动,INCR 代表相对运动</param>
/// <returns></returns>
bool ServoP(JKTYPE.CartesianPose cartesianPose, JKTYPE.MoveMode moveMode)
{ {
ErrorLog($"机械臂发生异常,异常码:{error_code}"); int rtn = jakaAPI.servo_p(ref _handle, ref cartesianPose, moveMode);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"ServoP OK");
return true;
}
else
{
ErrorLog($"ServoP Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人笛卡尔空间伺服模式运动扩展
/// </summary>
/// <param name="jointPos">机器人笛卡尔空间运动目标位置</param>
/// <param name="moveMode">指定运动模式:增量运动或绝对运动</param>
/// <param name="stepNum">倍分周期,servo_p 运动周期为 step_num*8ms,其中 step_num>=1</param>
/// <returns></returns>
bool ServoPExtend(JKTYPE.CartesianPose cartesianPose, JKTYPE.MoveMode moveMode, int stepNum)
{
int rtn = jakaAPI.servo_p_extend(ref _handle, ref cartesianPose, moveMode, stepNum);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"ServoPExtend OK");
return true;
}
else
{
ErrorLog($"ServoPExtend Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置数字输出变量
/// </summary>
/// <param name="iOType"> DO 类型</param>
/// <param name="index">DO 索引(从 0 开始)</param>
/// <param name="value">DO 设置值</param>
/// <returns></returns>
bool SetDigitalOutput(JKTYPE.IOType iOType, int index, bool value)
{
int rtn = jakaAPI.set_digital_output(ref _handle, iOType, index, value);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetDigitalOutput [{iOType}][{index}={value}] OK");
return true;
}
else
{
ErrorLog($"SetDigitalOutput [{iOType}][{index}={value}] Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 设置模拟输出变量
/// </summary>
/// <param name="iOType"> DO 类型</param>
/// <param name="index">DO 索引(从 0 开始)</param>
/// <param name="value">DO 设置值</param>
/// <returns></returns>
bool SetAnalogOutput(JKTYPE.IOType iOType, int index, float value)
{
int rtn = jakaAPI.set_analog_output(ref _handle, iOType, index, value);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"SetAnalogOutput [{iOType}][{index}={value}] OK");
return true;
}
else
{
ErrorLog($"SetAnalogOutput [{iOType}][{index}={value}] Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 查询数字输入状态
/// </summary>
/// <param name="iOType"> DI 类型</param>
/// <param name="index">DI 索引(从 0 开始)</param>
/// <param name="value">DI 状态查询结果</param>
/// <returns></returns>
public bool GetDigitalInput(JKTYPE.IOType iOType, int index, out bool result)
{
result = false;
int rtn = jakaAPI.get_digital_input(ref _handle, iOType, index, ref result);
if (rtn == RtnCode.ERR_SUCC)
{
DebugLog($"GetDigitalInput [{iOType}][{index}={result}] OK");
return true;
}
else
{
ErrorLog($"GetDigitalInput [{iOType}][{index}={result}] Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 注册机器人出错时的回调函数
/// </summary>
/// <returns></returns>
bool SetErrorHandler()
{
int rtn = jakaAPI.set_error_handler(ref _handle, user_error_handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"SetErrorHandler OK");
return true;
}
else
{
ErrorLog($"SetErrorHandler Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
}
/// <summary>
/// 机器人关机
/// </summary>
public bool ShutDown()
{
int rtn = jakaAPI.shut_down(ref _handle);
if (rtn == RtnCode.ERR_SUCC)
{
InfoLog($"ShutDown OK");
return true;
}
else
{
ErrorLog($"ShutDown Fail:{RtnCode.GetStrByCode(rtn)}");
}
return false;
} }
#endregion
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!