15. CNDE
15.1. Configure Robot CNDE Data List and Update Period
1/**
2* @brief Configure the data list and update period for robot real-time status feedback (overwrites previous configuration)
3* @param [in] states List of status enums to subscribe to, the order determines the arrangement order in the data packet
4* @param [in] period Data update period, unit milliseconds, value range [8, 1000]
5* @return Returns 0 on success; returns a negative error code on failure (e.g., ERR_STATE_INVALID, ERR_PARAM_VALUE, etc.)
6*/
7public int SetRobotRealtimeStateConfig(List<RobotState> states, int period)
15.2. Add a Status Item to the Existing Status Feedback List
1/**
2* @brief Add a status item to the existing status feedback list
3* @param [in] state Status enum value to add
4* @return Returns 0 on success; returns a negative error code on failure (e.g., ERR_STATE_ALREADY_EXISTS, ERR_STATE_INVALID, etc.)
5*/
6public int AddRobotRealtimeState(RobotState state)
15.3. Delete a Status Item from the Existing Status Feedback List
1/**
2* @brief Delete a status item from the existing status feedback list (at least one status must remain)
3* @param [in] state Status enum value to delete
4* @return Returns 0 on success; returns a negative error code on failure (e.g., ERR_STATE_INVALID, ERR_NEED_AT_LEAST_ONE_STATE)
5*/
6public int DeleteRobotRealtimeState(RobotState state)
15.4. Modify Only the Update Period of Status Feedback
1 /**
2* @brief Modify only the update period of status feedback without changing the status list
3* @param [in] period New update period, unit milliseconds, value range [8, 1000]
4* @return Returns 0 on success; returns a negative error code on failure (e.g., ERR_PARAM_VALUE)
5*/
6public int SetRobotRealtimeStatePeriod(int period)
15.5. Get the Currently Configured Status Feedback List and Update Period
1/**
2* @brief Get the currently configured status feedback list and update period
3* @param [out] states Output the currently subscribed status enum list
4* @param [out] period Output the current data update period, unit milliseconds
5* @return Returns 0 on success; returns a negative error code on failure
6*/
7public int GetRobotRealtimeStateConfig(out List<RobotState> states, out int period)
15.7. CNDE Add/Delete Configuration Status and Set Communication Period SDK Code Example
1private async void TestAddDeleteCNDE()
2{
3 List<RobotState> finalStates;
4 int finalPeriod;
5 // Initial configuration: request no status (default configuration)
6 List<RobotState> emptyStates = new List<RobotState>();
7 int ret = robot.SetRobotRealtimeStateConfig(emptyStates, 20);
8
9 robot.SetRobotRealtimeStatePeriod(10);
10 // Delete two statuses
11 ret = robot.DeleteRobotRealtimeState(RobotState.JointCurPos);
12 Console.WriteLine($"Delete JointCurPos result: {ret}");
13 ret = robot.DeleteRobotRealtimeState(RobotState.ToolCurPos);
14 Console.WriteLine($"Delete ToolCurPos result: {ret}");
15 // Add one status
16 ret = robot.AddRobotRealtimeState(RobotState.CollisionLevel);
17 Console.WriteLine($"Add CollisionLevel result: {ret}");
18
19 // Get the current configuration list and resend
20 List<RobotState> currentStates;
21 int currentPeriod;
22 robot.GetRobotRealtimeStateConfig(out currentStates, out currentPeriod);
23 Console.WriteLine($"Current configuration status count: {currentStates.Count}");
24 ret = robot.SetRobotRealtimeStateConfig(currentStates, currentPeriod);
25 Console.WriteLine($"Apply new configuration result: {ret}"); Console.WriteLine($"Initial configuration result: {ret}");
26 robot.GetRobotRealtimeStateConfig(out finalStates, out finalPeriod);
27 Console.WriteLine($"Configuration status count: {finalStates.Count}");
28 foreach (var s in finalStates) Console.WriteLine($" {s}");
29 Console.WriteLine($"Period: {finalPeriod} ms");
30
31 Thread.Sleep(1000);
32 // Establish RPC connection (automatically connects to CNDE internally)
33 robot.SetReconnectParam(true, 100, 1000);
34 ret = robot.RPC("192.168.58.2");
35 if (ret != 0)
36 {
37 Console.WriteLine($"RPC connection failed: {ret}");
38 return;
39 }
40
41 // Loop to print deleted and added statuses, deleted statuses print as 0, added statuses can retrieve real-time values normally
42 DateTime lastTime = DateTime.Now;
43 int frameCount = 0;
44 DateTime startTime = DateTime.Now;
45 while ((DateTime.Now - startTime).TotalSeconds < 10)
46 {
47 ROBOT_STATE_PKG pkg = new ROBOT_STATE_PKG();
48 robot.GetRobotRealTimeState(ref pkg);
49 DateTime now = DateTime.Now;
50 double interval = (now - lastTime).TotalMilliseconds;
51 lastTime = now;
52 frameCount++;
53
54 if (pkg.jt_cur_pos != null && pkg.jt_cur_pos.Length >= 6)
55 {
56 Console.WriteLine($" Joint positions(°): J1={pkg.jt_cur_pos[0]:F2}, J2={pkg.jt_cur_pos[1]:F2}, J3={pkg.jt_cur_pos[2]:F2}, J4={pkg.jt_cur_pos[3]:F2}, J5={pkg.jt_cur_pos[4]:F2}, J6={pkg.jt_cur_pos[5]:F2}");
57 }
58 if (pkg.tl_cur_pos != null && pkg.tl_cur_pos.Length >= 6)
59 {
60 Console.WriteLine($" TCP pose(mm/°): X={pkg.tl_cur_pos[0]:F2}, Y={pkg.tl_cur_pos[1]:F2}, Z={pkg.tl_cur_pos[2]:F2}, RX={pkg.tl_cur_pos[3]:F2}, RY={pkg.tl_cur_pos[4]:F2}, RZ={pkg.tl_cur_pos[5]:F2}");
61 }
62 // Collision level
63 if (pkg.collisionLevel != null && pkg.collisionLevel.Length >= 6)
64 Console.WriteLine($"Collision level: J1={pkg.collisionLevel[0]}, J2={pkg.collisionLevel[1]}, J3={pkg.collisionLevel[2]}, J4={pkg.collisionLevel[3]}, J5={pkg.collisionLevel[4]}, J6={pkg.collisionLevel[5]}");
65
66 await Task.Delay(50);
67 }
68 //Disconnect
69 robot.CloseRPC();
70 Console.WriteLine("Test completed.");
71}