### Full Robot Communication Example in Java Source: https://context7.com/seer-robotics/seersdk4j/llms.txt This Java code demonstrates a complete workflow for interacting with a robot using the Seer SDK. It includes steps for client connection, status checks, control commands, navigation requests, configuration retrieval, and resource cleanup. The example utilizes the RbkClient class and handles API requests with JSON payloads and timeouts. ```java import com.seer.sdk.rbk.RbkClient; import com.seer.sdk.rbk.RbkResult; import com.seer.sdk.rbk.RbkResultKind; import org.json.JSONObject; public class RobotController { public static void main(String[] args) { // 第一步: 创建客户端连接 RbkClient rbkClient = new RbkClient("192.168.8.114"); try { // 第二步: 查询机器人状态 (API 1007) RbkResult statusResult = rbkClient.request(1007, "{\"simple\": true}", 10000); if (RbkResultKind.Ok.equals(statusResult.getKind())) { JSONObject status = new JSONObject(statusResult.getResStr()); if (status.getInt("ret_code") == 0) { System.out.println("电量: " + status.getFloat("battery_level") + "%"); } } // 第三步: 发送控制指令 (API 2000-2999 范围) String controlJson = "{\"action\": \"move\", \"distance\": 1.0}"; RbkResult controlResult = rbkClient.request(2001, controlJson, 15000); if (RbkResultKind.Ok.equals(controlResult.getKind())) { System.out.println("控制指令响应: " + controlResult.getResStr()); } // 第四步: 导航请求 (API 3000-3999 范围) String navJson = "{\"target\": \"station_A\"}"; RbkResult navResult = rbkClient.request(3001, navJson, 20000); if (RbkResultKind.Ok.equals(navResult.getKind())) { System.out.println("导航响应: " + navResult.getResStr()); } // 第五步: 配置查询 (API 4000-5999 范围) RbkResult configResult = rbkClient.request(4001, "", 10000); if (RbkResultKind.Ok.equals(configResult.getKind())) { System.out.println("配置信息: " + configResult.getResStr()); } } finally { // 第六步: 释放所有连接资源 rbkClient.dispose(); } } } ``` -------------------------------- ### Initialize and Request RBK TCP Client Source: https://github.com/seer-robotics/seersdk4j/blob/master/README.md Demonstrates how to instantiate the RbkClient with a target IP address, execute a request with a specific command ID and timeout, and properly dispose of the connection to free resources. ```java public class Main { public static void main(String[] args) { RbkClient rbkClient = new RbkClient("192.168.8.114"); RbkResult request = rbkClient.request(1000, "", 10000); rbkClient.dispose(); // 释放连接资源 } } ``` -------------------------------- ### Initialize RBK Client Source: https://context7.com/seer-robotics/seersdk4j/llms.txt Creates a new instance of the RbkClient to establish communication with a specific robot IP address. The client automatically manages connections to various functional ports (19204-19210). ```java import com.seer.sdk.rbk.RbkClient; // 创建 RBK 客户端,连接到指定 IP 地址的机器人 RbkClient rbkClient = new RbkClient("192.168.8.114"); ``` -------------------------------- ### Handle Request Results and Status Source: https://context7.com/seer-robotics/seersdk4j/llms.txt Demonstrates how to inspect the RbkResult object and handle various request statuses using the RbkResultKind enumeration. ```java RbkResult result = rbkClient.request(1007, "", 10000); switch (result.getKind()) { case Ok: System.out.println("请求成功: " + result.getResStr()); break; case ConnectFail: System.out.println("连接失败: " + result.getErrMsg()); break; case Timeout: System.out.println("请求超时"); break; default: System.out.println("请求失败: " + result.getKind()); } ``` -------------------------------- ### Send Robot Request Source: https://context7.com/seer-robotics/seersdk4j/llms.txt Sends a JSON-formatted request to the robot using a specific API number. The SDK automatically routes the request to the appropriate port and returns an RbkResult object. ```java import com.seer.sdk.rbk.RbkClient; import com.seer.sdk.rbk.RbkResult; import com.seer.sdk.rbk.RbkResultKind; import org.json.JSONObject; RbkClient rbkClient = new RbkClient("192.168.8.114"); try { String requestJson = "{\"simple\": true}"; RbkResult result = rbkClient.request(1007, requestJson, 10000); if (RbkResultKind.Ok.equals(result.getKind())) { JSONObject response = new JSONObject(result.getResStr()); if (response.getInt("ret_code") == 0) { float batteryLevel = response.getFloat("battery_level"); System.out.println("机器人电量: " + batteryLevel + "%"); } } } finally { rbkClient.dispose(); } ``` -------------------------------- ### Dispose Client Resources Source: https://context7.com/seer-robotics/seersdk4j/llms.txt Closes all active network connections and releases Netty thread resources. This should be called when the client is no longer needed to prevent memory leaks. ```java try { // Perform operations rbkClient.request(1000, "", 10000); } finally { // Ensure resources are released rbkClient.dispose(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.