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 corresponds to range [], percentage corresponds to range [0~1]
5* @param  [in]  config 0-do not update configuration file, 1-update configuration file
6* @return  Error code
7*/
8int SetAnticollision(int mode, double[] level, int config);

7.2. Set collision post-strategy

 1/**
 2* @brief  Set collision post-strategy
 3* @param  [in] strategy  0 - Pause on error; 1 - Continue running; 2 - Stop on error; 3 - Torque mode; 4 - Oscillation response mode; 5 - Collision rebound mode
 4* @param  [in] safeTime  safe stop time [1000 - 2000]ms
 5* @param  [in] safeDistance  Safe stop distance [1-150] mm
 6* @param  [in] safeVel  TCP safe stop speed [50-250] mm/s
 7* @param  [in] safetyMargin  j1-j6 safety factor [1-10]
 8* @return Error code
 9*/
10int SetCollisionStrategy(int strategy, int safeTime, int safeDistance, int safeVel,int[] safetyMargin);

7.3. Custom collision detection threshold function start

1/**
2* @brief  Custom collision detection threshold function starts, sets the collision detection threshold for the joint end and TCP end
3* @param  [in] flag 1-only joint detection enabled; 2-only TCP detection enabled; 3-joint and TCP detection enabled simultaneously
4* @param  [in] jointDetectionThreshould Joint collision detection threshold j1-j6
5* @param  [in] tcpDetectionThreshould TCP collision detection threshold, xyzabc
6* @param  [in] block 0-non-blocking; 1-blocking
7* @return  Error code
8*/
9int CustomCollisionDetectionStart(int flag, double[] jointDetectionThreshould, double[] tcpDetectionThreshould, int block);

7.4. Custom collision detection threshold function disabled

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

7.5. Robot collision level settings code example

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

7.6. Set positive limit

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

7.7. Set negative limit

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

7.8. Get joint soft limit angles

1/**
2* @brief  Get joint soft limit angles
3* @param  [in] flag 0-block, 1-non-block
4* @param  [out] negative  Negative limit angle, in degrees
5* @param  [out] positive  Positive limit angle, in degrees
6* @return  Error code
7*/
8int GetJointSoftLimitDeg(byte flag, ref double[] negative, ref double[] positive);

7.9. Robot limit setting code example

 1private void btnRobotSafetySet_Click(object sender, EventArgs e)
 2{
 3    double[] plimit = { 170.0f, 80.0f, 150.0f, 80.0f, 170.0f, 160.0f };
 4    robot.SetLimitPositive(plimit);
 5    double[] nlimit = { -170.0f, -260.0f, -150.0f, -260.0f, -170.0f, -160.0f };
 6    robot.SetLimitNegative(nlimit);
 7
 8    double[] neg_deg = new double[6] {0,0,0,0,0,0 };
 9    double[] pos_deg = new double[6] { 0, 0, 0, 0, 0, 0 };
10    robot.GetJointSoftLimitDeg(0, ref neg_deg,ref pos_deg);
11    Console.WriteLine($"neg limit deg:{neg_deg[0]},{neg_deg[1]},{neg_deg[2]},{neg_deg[3]},{neg_deg[4]},{neg_deg[5]}");
12    Console.WriteLine($"pos limit deg:{pos_deg[0]},{pos_deg[1]},{pos_deg[2]},{pos_deg[3]},{pos_deg[4]},{pos_deg[5]}");
13}

7.10. Set robot collision detection method

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

7.11. Set collision detection start/stop in static mode

1/**
2* @brief Set collision detection start/stop in static mode
3* @param  [in] status 0-disabled; 1-enabled
4* @return  Error code
5*/
6int SetStaticCollisionOnOff(int status);

7.12. Code example for setting the robot collision detection method

 1private void button26_Click(object sender, EventArgs e)
 2{
 3    int rtn = robot.SetCollisionDetectionMethod(0, 0);
 4
 5    rtn = robot.SetStaticCollisionOnOff(1);
 6    Console.WriteLine($"SetStaticCollisionOnOff On rtn is {rtn}");
 7    Thread.Sleep(5000);
 8    rtn = robot.SetStaticCollisionOnOff(0);
 9    Console.WriteLine($"SetStaticCollisionOnOff Off rtn is {rtn}");
10}

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*/
7int SetPowerLimit(int status, double power);

7.14. Joint torque power detection code example

 1private void button26_Click(object sender, EventArgs e)
 2{
 3    robot.DragTeachSwitch(1);
 4    robot.SetPowerLimit(1, 200);
 5    double[] torques = { 0, 0, 0, 0, 0, 0 };
 6    robot.GetJointTorques(1, torques);
 7
 8    int count = 100;
 9    robot.ServoJTStart();
10    int error = 0;
11    while (count > 0)
12    {
13        error = robot.ServoJT(torques, 0.001f);
14        count--;
15        Thread.Sleep(1);
16    }
17    error = robot.ServoJTEnd();
18    robot.DragTeachSwitch(0);
19}

7.15. Set Safety Speed Parameters

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

7.16. SDK Code Example for Setting Safety Speed Parameters

 1public int TestSetVelReducePara()
 2{
 3    int rtn = 0;
 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
11    // Test parameter error
12    rtn = robot.SetVelReducePara(2, 30, 1);
13    Console.WriteLine($"SetVelReducePara param error rtn is {rtn}");
14
15    // Disable speed reduction
16    rtn = robot.SetVelReducePara(0, 30, 1);
17    Console.WriteLine($"SetVelReducePara disable reduce vel rtn is {rtn}");
18    robot.MoveJ(j1, 0, 0, 100, 100, 100, epos, -1, 0, offset_pos);
19    robot.MoveJ(j2, 0, 0, 100, 100, 100, epos, -1, 0, offset_pos);
20
21    // Enable speed reduction (manual mode)
22    rtn = robot.SetVelReducePara(1, 30, 1);
23    Console.WriteLine($"SetVelReducePara reduce vel rtn is {rtn}");
24    robot.MoveJ(j1, 0, 0, 100, 100, 100, epos, -1, 0, offset_pos);
25    robot.MoveJ(j2, 0, 0, 100, 100, 100, epos, -1, 0, offset_pos);
26
27    // Enabled in all modes, strategy: stop with alarm and disable
28    rtn = robot.SetVelReducePara(2, 30, 2);
29    Console.WriteLine($"SetVelReducePara disable robot rtn is {rtn}");
30    robot.MoveJ(j1, 0, 0, 100, 100, 100, epos, -1, 0, offset_pos);
31    robot.MoveJ(j2, 0, 0, 100, 100, 100, epos, -1, 0, offset_pos);
32
33    Thread.Sleep(2000);
34    robot.ResetAllError();
35    robot.RobotEnable(1);
36    Thread.Sleep(1000);
37
38    // Enabled in all modes, strategy: stop with alarm (normal parameters)
39    rtn = robot.SetVelReducePara(2, 30, 0);
40    Console.WriteLine($"SetVelReducePara report error rtn is {rtn}");
41    robot.MoveJ(j1, 0, 0, 100, 100, 100, epos, -1, 0, offset_pos);
42    robot.MoveJ(j2, 0, 0, 100, 100, 100, epos, -1, 0, offset_pos);
43
44    Thread.Sleep(1000);
45    return 0;
46}