7. Robot safety settings

7.1. Set collision level

1/**
2* @brief Set collision level
3* @param  [in]  mode  0-level, 1-percentage
4* @param  [in]  level Collision threshold. Level range: [1-10 corresponds to levels 1-10, 100-disabled]. Percentage range: [0~10 corresponds to 0% - 100%]
5* @param  [in]  config 0-Do not update config file, 1-Update config file
6* @return  Error code
7*/
8int SetAnticollision(int mode, Object[] level, int config);

7.2. Set post-collision strategy

1/**
2* @brief  Set post-collision strategy
3* @param  [in] strategy  0-Report error and stop, 1-Continue running
4* @param  [in] safeTime  Safe stop time [1000 - 2000]ms
5* @param  [in] safeDistance  Safe stop distance [1-150]mm
6* @param  [in] safetyMargin  J1-J6 safety coefficients [1-10]
7* @return  Error code
8*/
9int SetCollisionStrategy(int strategy, int safeTime, int safeDistance, int safetyMargin[]);

7.3. Custom collision detection threshold function start

Added in version Java: SDK-v1.0.3-3.8.0

1/**
2* @brief  Start custom collision detection threshold function. Set collision detection thresholds for joints and TCP
3* @param  [in] flag 1-Joint detection only; 2-TCP detection only; 3-Both joint and TCP detection
4* @param  [in] jointDetectionThreshould  Joint collision detection thresholds for J1-J6
5* @param  [in] tcpDetectionThreshould  TCP collision detection thresholds for xyzabc
6* @param  [in] block 0-Non-blocking; 1-Blocking
7* @return  Error code
8*/
9public int CustomCollisionDetectionStart(int flag, double[] jointDetectionThreshould, double[] tcpDetectionThreshould, int block);

7.4. Custom collision detection threshold function end

Added in version Java: SDK-v1.0.3-3.8.0

1/**
2* @brief  End custom collision detection threshold function
3* @return  Error code
4*/
5public int CustomCollisionDetectionEnd();

7.5. Robot collision level setting code example

 1public static int TestCollision(Robot robot)
 2{
 3    int mode = 0;
 4    int config = 1;
 5    Object[] level1 = new Object[]{ 1.0,2.0,3.0,4.0,5.0,6.0 };
 6    Object[] level2 = new Object[]{ 50.0,20.0,30.0,40.0,50.0,60.0 };
 7
 8    int rtn = robot.SetAnticollision(mode, level1, config);
 9    System.out.println("SetAnticollision mode 0 rtn is: "+ rtn);
10    mode = 1;
11    rtn = robot.SetAnticollision(mode, level2, config);
12    System.out.println("SetAnticollision mode 1 rtn is :"+ rtn);
13
14    JointPos p1Joint=new JointPos(-11.904, -99.669, 117.473, -108.616, -91.726, 74.256);
15    JointPos p2Joint=new JointPos(-45.615, -106.172, 124.296, -107.151, -91.282, 74.255);
16
17    DescPose p1Desc=new DescPose(-419.524, -13.000, 351.569, -178.118, 0.314, 3.833);
18    DescPose p2Desc=new DescPose(-321.222, 185.189, 335.520, -179.030, -1.284, -29.869);
19
20    ExaxisPos exaxisPos=new ExaxisPos(0.0, 0.0, 0.0, 0.0);
21    DescPose offdese=new DescPose(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
22    robot.MoveL(p2Joint, p2Desc, 0, 0, 100, 100, 100, 2,0, exaxisPos, 0, 0, offdese,0,10);
23    robot.ResetAllError();
24    int[] safety = new int[]{ 5,5,5,5,5,5 };
25    rtn = robot.SetCollisionStrategy(3, 1000, 150, 250, safety);
26    System.out.println("SetCollisionStrategy rtn is:"+ rtn);
27
28    double[] jointDetectionThreshould = new double[]{ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 };
29    double[] tcpDetectionThreshould =new double[] { 60,60,60,60,60,60 };
30    rtn = robot.CustomCollisionDetectionStart(3, jointDetectionThreshould, tcpDetectionThreshould, 0);
31    System.out.println("CustomCollisionDetectionStart rtn is :"+ rtn);
32
33    robot.MoveL(p1Joint, p1Desc, 0, 0, 100, 100, 100, -1,0, exaxisPos, 0, 0, offdese,0,10);
34    robot.MoveL(p2Joint, p2Desc, 0, 0, 100, 100, 100, -1,0, exaxisPos, 0, 0, offdese,0,10);
35    rtn = robot.CustomCollisionDetectionEnd();
36    System.out.println("CustomCollisionDetectionEnd rtn is: "+ rtn);
37    return 0;
38}

7.6. Set positive limit

1/**
2* @brief  Set positive limit
3* @param  [in] limit Six joint positions in deg
4* @return  Error code
5*/
6int SetLimitPositive(Object[] limit);

7.7. Set negative limit

1/**
2* @brief  Set negative limit
3* @param  [in] limit Six joint positions in deg
4* @return  Error code
5*/
6int SetLimitNegative(Object[] limit);

7.8. Get joint soft limit angles

1/**
2* @brief  Get joint soft limit angles
3* @param  [in] flag 0-Blocking, 1-Non-blocking
4* @param  [out] negative  Negative limit angles in deg
5* @param  [out] positive  Positive limit angles in deg
6* @return  Error code
7*/
8int GetJointSoftLimitDeg(int flag, Object[] negative, Object[] positive);

7.9. Robot limit setting code example

 1public static int TestLimit(Robot robot)
 2{
 3    Object[] plimit =new Object[] { 170.0,80.0,150.0,80.0,170.0,160.0 };
 4    robot.SetLimitPositive(plimit);
 5    Object[] nlimit =new Object[] { -170.0,-260.0,-150.0,-260.0,-170.0,-160.0 };
 6    robot.SetLimitNegative(nlimit);
 7
 8    Object[] neg_deg =new Object[] {0, 0 , 0, 0, 0, 0}, pos_deg = new Object[]{0, 0 , 0, 0, 0, 0};
 9    robot.GetJointSoftLimitDeg(1,  neg_deg,  pos_deg);
10    System.out.println("neg limit deg:"+ neg_deg[0]+","+ neg_deg[1]+","+ neg_deg[2]+","+ neg_deg[3]+","+ neg_deg[4]+","+ neg_deg[5]);
11    System.out.println("pos limit deg:"+pos_deg[0]+","+ pos_deg[1]+","+ pos_deg[2]+","+ pos_deg[3]+","+ pos_deg[4]+","+pos_deg[5]);
12    return 0;
13}

7.10. Set robot collision detection method

Changed in version Java: SDK-v1.0.5-3.8.2

1/**
2* @brief Set robot collision detection method
3* @param [in] method Collision detection method: 0-Current mode; 1-Dual encoder; 2-Both current and dual encoder
4* @param [in] thresholdMode Collision level threshold method: 0-Fixed threshold; 1-Custom collision detection threshold
5* @return Error code
6*/
7int SetCollisionDetectionMethod(int method,int thresholdMode)

7.11. Set static collision detection on/off

1/**
2* @brief Set static collision detection on/off
3* @param  [in] status 0-Off; 1-On
4* @return  Error code
5*/
6public int SetStaticCollisionOnOff(int status)

7.12. Robot collision detection method code example

 1public static int TestCollisionMethod(Robot robot)
 2{
 3    int rtn = robot.SetCollisionDetectionMethod(0);
 4
 5    rtn = robot.SetStaticCollisionOnOff(1);
 6    System.out.println("SetStaticCollisionOnOff On rtn is:"+ rtn);
 7    robot.Sleep(5000);
 8    rtn = robot.SetStaticCollisionOnOff(0);
 9    System.out.println("SetStaticCollisionOnOff Off rtn is:"+ rtn);
10
11    robot.CloseRPC();
12    return 0;
13}

7.13. Joint torque power detection

1/**
2* @brief Joint torque power detection
3* @param  [in] status 0-Off; 1-On
4* @param  [in] power Set maximum power (W)
5* @return  Error code
6*/
7public int SetPowerLimit(int status, double power)

7.14. Joint torque power detection code example

 1public static int TestPowerLimit(Robot robot)
 2{
 3    robot.DragTeachSwitch(1);
 4    robot.SetPowerLimit(1, 200);
 5    List<Number> joint_toq=new ArrayList<>();
 6    joint_toq=robot.GetJointTorques(1);
 7
 8    int count = 100;
 9    robot.ServoJTStart(); //   #servoJT start
10    int error = 0;
11    while (count > 0)
12    {
13        count = count - 1;
14        robot.Sleep(1);
15    }
16    error = robot.ServoJTEnd();
17    robot.DragTeachSwitch(0);
18
19    robot.CloseRPC();
20    return 0;
21}

7.15. Set Safety Speed Parameters

1/**
2* @brief Set safety speed parameters
3* @param enable 0-off; 1-enabled in manual mode; 2-enabled in all modes (automatic speed limiting not supported)
4* @param maxTCPVel Maximum TCP speed limit; [0-1000] mm/s
5* @param strategy Strategy after overspeed; 0-stop with alarm; 1-automatic speed limiting; 2-stop with alarm and disable
6* @param maxJointVel Maximum speed for 6 joints (°/s), default 45°/s
7* @return Error code
8*/
9public int SetVelReducePara(int enable, double maxTCPVel, int strategy, double[] maxJointVel)

7.16. SDK Code Example for Setting Safety Speed Parameters

 1public static int TestSetVelReducePara(Robot robot) {
 2    int rtn = 0;
 3
 4    JointPos j1 = new JointPos(0, -90, 90, 0, 0, 0);
 5    JointPos j2 = new JointPos(90, -90, 90, 0, 0, 0);
 6    ExaxisPos epos = new ExaxisPos(0, 0, 0, 0);
 7    DescPose offset_pos = new DescPose(0, 0, 0, 0, 0, 0);
 8
 9    robot.SetSpeed(80);
10    rtn = robot.SetVelReducePara(2, 30, 1);
11    System.out.printf("SetVelReducePara param error rtn is %d\n", rtn);
12
13    rtn = robot.SetVelReducePara(0, 30, 1);
14    System.out.printf("SetVelReducePara disable reduce vel rtn is %d\n", rtn);
15    robot.MoveJ(j1, 0, 0, 100, 100, 100.0, epos, -1.0, 0, offset_pos);
16    robot.MoveJ(j2, 0, 0, 100, 100, 100.0, epos, -1.0, 0, offset_pos);
17
18    rtn = robot.SetVelReducePara(1, 30, 1);
19    System.out.printf("SetVelReducePara reduce vel rtn is %d\n", rtn);
20    robot.MoveJ(j1, 0, 0, 100, 100, 100.0, epos, -1.0, 0, offset_pos);
21    robot.MoveJ(j2, 0, 0, 100, 100, 100.0, epos, -1.0, 0, offset_pos);
22
23    rtn = robot.SetVelReducePara(2, 30, 2);
24    System.out.printf("SetVelReducePara disable robot rtn is %d\n", rtn);
25    robot.MoveJ(j1, 0, 0, 100, 100, 100.0, epos, -1.0, 0, offset_pos);
26    robot.MoveJ(j2, 0, 0, 100, 100, 100.0, epos, -1.0, 0, offset_pos);
27
28    robot.Sleep(2000);
29    robot.ResetAllError();
30    robot.RobotEnable(1);
31    robot.Sleep(1000);
32
33    rtn = robot.SetVelReducePara(2, 30, 0);
34    System.out.printf("SetVelReducePara report error rtn is %d\n", rtn);
35    robot.MoveJ(j1, 0, 0, 100, 100, 100.0, epos, -1.0, 0, offset_pos);
36    robot.MoveJ(j2, 0, 0, 100, 100, 100.0, epos, -1.0, 0, offset_pos);
37
38    robot.Sleep(1000);
39    return 0;
40}

7.17. Code Example for Setting Robot Joint Safety Speed

 1public static int TestSetJointVelReducePara(Robot robot) {
 2    ROBOT_STATE_PKG pkg = new ROBOT_STATE_PKG();
 3
 4    JointPos j1 = new JointPos(10.220, -11.121, -118.086, -46.739, 82.036, 131.503);
 5    JointPos j2 = new JointPos(89.782, -11.122, -118.086, -46.740, 82.036, 131.504);
 6    ExaxisPos epos = new ExaxisPos(0, 0, 0, 0);
 7    DescPose offset_pos = new DescPose(0, 0, 0, 0, 0, 0);
 8    robot.SetSpeed(20);
 9
10    double[] maxJointVelA = {100.0, 100.0, 100.0, 100.0, 100.0, 100.0};
11    int rtn = robot.SetVelReducePara(2, 200, 0, maxJointVelA);
12    System.out.printf("SetVelReducePara param error rtn is %d\n", rtn);
13    robot.MoveJ(j1, 1, 2, 100, 100, 100, epos, -1, 0, offset_pos);
14    robot.MoveJ(j2, 1, 2, 100, 100, 100, epos, -1, 0, offset_pos);
15
16    double[] maxJointVelB = {20.0, 20.0, 20.0, 20.0, 20.0, 20.0};
17    rtn = robot.SetVelReducePara(2, 200, 0, maxJointVelB);
18    System.out.printf("SetVelReducePara reduce vel rtn is %d\n", rtn);
19    robot.MoveJ(j1, 1, 2, 100, 100, 100, epos, -1, 0, offset_pos);
20    robot.MoveJ(j2, 1, 2, 100, 100, 100, epos, -1, 0, offset_pos);
21
22    robot.Sleep(2000);
23    return 0;
24}

7.18. Get Safety Configuration Parameter Checksum

1/**
2* @brief Get safety configuration parameter checksum
3* @param status Verification status, 0-valid, 1-verifying, 2-verification failed
4* @param checksum Checksum, 8-digit hexadecimal
5* @return Error code
6*/
7public int GetSafetyParamsCheckSum(int[] status, long[] checksum)

7.19. Safety Operation Password Verification

1/**
2* @brief Safety operation password verification
3* @param status Verification, 0-enable, 1-disable
4* @param password Password
5* @return Error code
6*/
7public int SafetyOPPasswordCheck(int status, String password)

7.20. Get Safety Configuration Parameter Checksum and Safety Operation Password Verification Code Example

 1public static void TestSafetyParamsCheckSum(Robot robot)
 2{
 3    int[] status = new int[1];
 4    long[] checksum = new long[1];
 5
 6    int error = robot.GetSafetyParamsCheckSum(status, checksum);
 7    System.out.println(String.format("GetSafetyParamsCheckSum: error=%d, status=%d, hex_code=%08X",
 8        error, status[0], checksum[0]));
 9
10    try {
11        Thread.sleep(3000);
12    } catch (InterruptedException e) {
13        Thread.currentThread().interrupt();
14    }
15
16    error = robot.SafetyOPPasswordCheck(0, "12345678");
17    System.out.println(String.format("SafetyOPPasswordCheck: error=%d", error));
18
19    if (error == 0)
20    {
21        Object[] level = {2.0, 2.0, 2.0, 2.0, 2.0, 2.0};
22        error = robot.SetAnticollision(0, level, 1);
23        System.out.println(String.format("SetAnticollision: error=%d", error));
24
25        error = robot.SetCollisionStrategy(0, 1000, 150, 0, new int[]{10, 10, 10, 10, 10, 10});
26        System.out.println(String.format("SetCollisionStrategy: error=%d", error));
27    }
28
29    try {
30        Thread.sleep(1000);
31    } catch (InterruptedException e) {
32        Thread.currentThread().interrupt();
33    }
34
35    error = robot.GetSafetyParamsCheckSum(status, checksum);
36    System.out.println(String.format("GetSafetyParamsCheckSum(again): error=%d, status=%d, hex_code=%08X",
37        error, status[0], checksum[0]));
38}

7.21. Set mTLS Encryption Enablement and Certificate Path

1//mTLS master switch: default false; set false before RPC initialization to force plaintext mode
2public bool EnableMtls = false;
3
4/**
5* @brief Set the TLS encryption certificate path
6* @param [in] certPath  Certificate path; if empty, the default is the certificate in the directory where the executable file is located; certificate names: ca.crt; client.crt; client.key
7* @return Error code
8*/
9public MtlsLink(String certDir)

7.22. Code Example for Setting the TLS Encryption Certificate Path

 1public static void TestSendModeTcp(Robot robot)
 2{
 3    String program_name = "mtls.lua";
 4    String[] loaded_name = {""};
 5    int[] state = {0};
 6    int[] line = {0};
 7
 8    System.out.println("========== Mode Command TCP 8080 Channel Verification ==========");
 9    System.out.println(robot.IsEncryptEnabled() ? "[Status] mTLS enabled" : "[Status] Plaintext mode (control)");
10
11    robot.SetTcpFrameListener(frame ->
12            System.out.println("[TCP response] " + frame));
13
14    String mode0 = "/f/bIII52III236III7IIIMode(0)III/b/f";
15    String mode1 = "/f/bIII52III236III7IIIMode(1)III/b/f";
16
17    System.out.println("[Send] " + mode0);
18    robot.SendTCPFrame(mode0);
19    robot.Sleep(1000);
20    System.out.println("[Send] " + mode1);
21    robot.SendTCPFrame(mode1);
22    robot.Sleep(1000);
23    System.out.println("[Send] " + mode0);
24    robot.SendTCPFrame(mode0);
25
26    robot.Mode(0);
27    robot.LoadDefaultProgConfig(0, program_name);
28    robot.ProgramLoad(program_name);
29
30    robot.SetSpeedInstant(50);
31
32    robot.ProgramRun();
33    robot.Sleep(5000);
34    robot.PauseMotion();
35    robot.GetProgramState(state);
36    System.out.println("program state:" + state[0]);
37    java.util.List<Integer> lineRtn = robot.GetCurrentLine();
38    System.out.println("current line:" + lineRtn.get(1));
39    robot.GetLoadedProgram(loaded_name);
40    System.out.println("program name:" + loaded_name[0]);
41
42    robot.ResumeMotion();
43    robot.Sleep(2000);
44    robot.PauseMotion();
45    robot.Sleep(2000);
46}