15. CNDE
15.1. Configure Robot CNDE Status Feedback
Prototype |
|
|---|---|
Description |
Set CNDE default configuration (call before RPC connection) |
Required Parameters |
|
Default Parameters |
None |
Return Value |
|
15.2. Add Robot Status to CNDE Status Configuration
Prototype |
|
|---|---|
Description |
Add CNDE status list based on existing configuration (supports dynamic maintenance and IP isolation) |
Required Parameters |
|
Default Parameters |
None |
Return Value |
|
15.3. Delete Robot Status from CNDE Status Configuration
Prototype |
|
|---|---|
Description |
Delete CNDE status list based on existing configuration (supports dynamic maintenance and IP isolation) |
Required Parameters |
|
Default Parameters |
None |
Return Value |
|
15.4. Set CNDE Status Feedback Period
Prototype |
|
|---|---|
Description |
Set CNDE status feedback period (supports global or IP-isolated configuration) |
Required Parameters |
|
Default Parameters |
None |
Return Value |
|
15.5. Get Current CNDE Status Feedback All State Set
Prototype |
|
|---|---|
Description |
Get all current state sets |
Required Parameters |
None |
Default Parameters |
None |
Return Value |
|
15.6. CNDE Status Feedback Usage Code Example
1from fairino import Robot
2from fairino.Robot import RobotState, SetRobotRealtimeStateConfig, DEFAULT_CNDE_STATES, AddRobotRealtimeState, DeleteRobotRealtimeState, SetRobotRealtimeStatePeriod
3import time
4
5# ==================== Global Configuration Parameters ====================
6ROBOT_IP = '192.168.58.2' # Robot IP address
7# ========== Test1: CNDE Configuration and Data Acquisition Test =============
8# Test steps:
9# 1. Set CNDE configuration (JointCurPos, ToolCurPos, 20ms period)
10# 2. Establish RPC connection
11# 3. Print robot joint and TCP pose data
12# 4. Get timestamp and verify period
13# 5. Modify configuration (RobotMode, RbtEnableState, 10ms period)
14# 6. Verify new configuration takes effect
15
16def test1_cnde_config_and_data():
17 """Test1: CNDE configuration and data acquisition test - verify configuration settings and data real-time nature"""
18 print_separator("Test1: CNDE configuration and data acquisition test")
19
20 # ===== Step 1: Set CNDE configuration (JointCurPos, ToolCurPos, 20ms) =====
21 print("\n[Step 1] Setting CNDE configuration...")
22 print(" Configuration fields: JointCurPos, ToolCurPos")
23 print(" Feedback period: 20ms")
24
25 custom_states = [
26 RobotState.JointCurPos, # Current joint position
27 RobotState.ToolCurPos, # Current tool (TCP) position
28 ]
29
30 rtn = SetRobotRealtimeStateConfig(custom_states, 20)
31 if rtn != 0:
32 print(f"✗ Configuration setting failed, error code: {rtn}")
33 return None
34 print("✓ CNDE configuration set successfully")
35
36 # ===== Step 2: Establish RPC connection =====
37 print(f"\n[Step 2] Establishing RPC connection ({ROBOT_IP})...")
38 robot = Robot.RPC(ROBOT_IP)
39 time.sleep(0.5) # Wait for connection and data reception
40
41 # Verify configuration
42 config = robot.CNDEGetConfig()
43 if config:
44 states, period = config
45 print(f"✓ Connection successful, current configuration: {len(states)} fields, period {period}ms")
46 else:
47 print("✗ Unable to get CNDE configuration")
48 return robot
49
50 # ===== Step 3: Print robot joint and TCP pose =====
51 print("\n[Step 3] Printing robot joint and TCP pose...")
52 print(" (Tip: Drag the robot to observe data changes)")
53 print(" Press Ctrl+C to stop data printing")
54 print(" (Use Wireshark to capture packets to verify actual data period)\n")
55
56 sample_count = 0
57 try:
58 while sample_count < 100: # Collect 100 samples
59 pkg = robot.robot_state_pkg
60
61 # Print every 10 frames
62 if sample_count % 10 == 0:
63 print(f"--- Sample #{sample_count} ---")
64 print(f" Joint positions (deg): [{', '.join([f'{x:.3f}' for x in pkg.jt_cur_pos])}]")
65 print(f" TCP pose (mm/deg): [{', '.join([f'{x:.3f}' for x in pkg.tl_cur_pos])}]")
66 print(f" Current frame count: {pkg.frame_cnt}")
67 print()
68
69 sample_count += 1
70 time.sleep(0.02) # 20ms
71
72 except KeyboardInterrupt:
73 print("\n User interrupted data printing")
74
75 # Close connection
76 robot.CloseRPC()
77 time.sleep(1)
78
79 # ===== Step 4: Modify configuration and verify =====
80 print("\n[Step 4] Modifying CNDE configuration...")
81 print(" New configuration fields: RobotMode, RbtEnableState")
82 print(" New feedback period: 10ms")
83
84 new_states = [
85 RobotState.RobotMode,
86 RobotState.RbtEnableState,
87 ]
88
89 # Set new configuration
90 rtn = SetRobotRealtimeStateConfig(new_states, 10)
91 if rtn != 0:
92 print(f"✗ New configuration setting failed, error code: {rtn}")
93 return robot
94 print("✓ New configuration set successfully")
95
96 # Reconnect
97 robot = Robot.RPC(ROBOT_IP)
98 time.sleep(0.5)
99
100 # Verify new configuration
101 config = robot.CNDEGetConfig()
102 if config:
103 states, period = config
104 print(f"✓ Current configuration: {[s.name for s in states]}")
105 print(f"✓ Current period: {period}ms")
106
107 if period == 10:
108 print("✓ Configuration modification verification passed (period changed to 10ms)")
109 else:
110 print(f"⚠ Period did not take effect (expected 10ms, actual {period}ms)")
111
112 # Print new data
113 pkg = robot.robot_state_pkg
114 print(f"\n[New Configuration Data]")
115 print(f" robot_mode: {pkg.robot_mode}")
116 print(f" rbtEnableState: {pkg.rbtEnableState}")
117 else:
118 print("✗ Unable to get new configuration")
119
120 print("\n✓ Test1 completed")
121 return robot
122
123
124if __name__ == "__main__":
125 test1_cnde_config_and_data()
126
127
128# ======== Test2: Add/Delete State Field Test ====================
129# Function: Test AddRobotRealtimeState() and DeleteRobotRealtimeState()
130# Test steps:
131# 1. Use AddRobotRealtimeState() to add SpeedScaleManual and SpeedScaleAuto
132# 2. Connect to robot, print manual/automatic mode global speed
133# 3. Modify global speed in WebApp and observe SDK data changes
134# 4. Use DeleteRobotRealtimeState() to delete the added fields
135# 5. Reconnect and verify that speed values are 0 (fields no longer updated)
136
137
138def test2_add_delete_state():
139 """Test2: Add/Delete state field test - verify dynamic addition and deletion of CNDE states"""
140 print_separator("Test2: Add/Delete state field test")
141
142 # ===== Step 1: Add SpeedScaleManual and SpeedScaleAuto fields =====
143 print("\n[Step 1] Using AddRobotRealtimeState() to add speed scale fields...")
144 print(" Adding fields: SpeedScaleManual, SpeedScaleAuto")
145
146 rtn = AddRobotRealtimeState([
147 RobotState.SpeedScaleManual,
148 RobotState.SpeedScaleAuto,
149 ])
150
151 if rtn != 0:
152 print(f"✗ Field addition failed, error code: {rtn}")
153 return None
154 print("✓ Fields added successfully")
155
156 # ===== Step 2: Establish RPC connection and print speed =====
157 print(f"\n[Step 2] Establishing RPC connection ({ROBOT_IP})...")
158 robot = Robot.RPC(ROBOT_IP)
159 time.sleep(0.5) # Wait for connection and data reception
160
161 # Verify configuration
162 config = robot.CNDEGetConfig()
163 if config:
164 states, period = config
165 print(f"✓ Connection successful, current configuration: {len(states)} fields")
166 # Check if added fields are included
167 has_manual = RobotState.SpeedScaleManual in states
168 has_auto = RobotState.SpeedScaleAuto in states
169 if has_manual and has_auto:
170 print("✓ Configuration verification passed: SpeedScaleManual and SpeedScaleAuto have been added")
171 else:
172 print(f"⚠ Configuration verification warning: Manual={has_manual}, Auto={has_auto}")
173 else:
174 print("✗ Unable to get CNDE configuration")
175
176 # Print speed data
177 print("\n[Current Speed Data] (Modify global speed in WebApp to observe changes)")
178 print(" Tip: Enable robot by dragging and switch between manual/auto modes to observe speed values")
179 print(" Press Ctrl+C to stop data printing\n")
180
181 sample_count = 0
182 try:
183 while sample_count < 100: # Collect 100 samples (about 10 seconds at 100ms intervals)
184 pkg = robot.robot_state_pkg
185 print(f" [{sample_count:3d}] SpeedScaleManual: {pkg.speedScaleManual:.2f}, "
186 f"SpeedScaleAuto: {pkg.speedScaleAuto:.2f}, "
187 f"Mode: {pkg.robot_mode}")
188 sample_count += 1
189 time.sleep(0.1) # 100ms interval
190 except KeyboardInterrupt:
191 print("\n User interrupted data printing")
192
193 print(f"\n✓ Data collection completed, total {sample_count} samples")
194
195 # ===== Step 3: Disconnect =====
196 print("\n[Step 3] Disconnecting current connection...")
197 robot.CloseRPC()
198 time.sleep(1.0) # Wait for CNDE to fully close
199
200 # ===== Step 4: Delete added fields =====
201 print("\n[Step 4] Using DeleteRobotRealtimeState() to delete speed scale fields...")
202 rtn = DeleteRobotRealtimeState([
203 RobotState.SpeedScaleManual,
204 RobotState.SpeedScaleAuto,
205 ])
206
207 if rtn != 0:
208 print(f"✗ Field deletion failed, error code: {rtn}")
209 return robot
210 print("✓ Fields deleted successfully")
211
212 # ===== Step 5: Reconnect and verify field values are 0 =====
213 print(f"\n[Step 5] Reconnecting and verifying deleted field values...")
214
215 robot = Robot.RPC(ROBOT_IP)
216 time.sleep(0.5)
217
218 # Read speed values
219 pkg = robot.robot_state_pkg
220 manual_speed = pkg.speedScaleManual
221 auto_speed = pkg.speedScaleAuto
222
223 print(f"\n SpeedScaleManual after deletion: {manual_speed:.2f}")
224 print(f" SpeedScaleAuto after deletion: {auto_speed:.2f}")
225
226 # Verify if they are 0
227 if manual_speed == 0 and auto_speed == 0:
228 print("\n✓ Test2 verification passed: Speed values are 0 after field deletion")
229 else:
230 print(f"\n⚠ Test2 warning: Speed values are non-zero after field deletion")
231
232 print("\n✓ Test2 completed")
233 return robot
234
235if __name__ == "__main__":
236 test2_add_delete_state()