unitree_sdk2_rs 0.1.2

Unitree SDK2 的 Rust 封装:msg 驱动的 DDS 类型生成 + CDR 序列化 + 订阅/发布/RPC
docs.rs failed to build unitree_sdk2_rs-0.1.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: unitree_sdk2_rs-0.1.4

unitree_sdk2_rs

Unitree SDK2 的 Rust 绑定。

使用示例

以下是一个 rpc 订阅示例:

use std::time::Duration;
use unitree_sdk2_rs::rpc::RpcClient;

#[tokio::main]
async fn main() {
    unitree_sdk2_rs::init_dds(0, "eth0", "");

    let client = RpcClient::new("rpc_test").expect("创建 RpcClient 失败");
    client.register_api(1001);
    client.register_api(1002);

    let resp = client.call(1001, "hello".to_string()).await.expect("call 1001");
    println!("api=1001 code={} data={}", resp.code, resp.data);

    let resp = client.call(1002, String::new()).await.expect("call 1002");
    println!("api=1002 code={} data={}", resp.code, resp.data);
}

环境变量

构建时获取 unitree_sdk2 C++ SDK(仓库自带预编译库,不做 cmake 编译)。来源按优先级:

环境变量 说明
UNITREE_SDK2_PATH=<目录> 直接用本地已有 SDK(不 clone、不编译)
UNITREE_SDK2_URL=<git 地址> 浅克隆到 UNITREE_SDK2_DIR
默认 从 GitHub 克隆 unitree_sdk2

您可直接 export 设置环境变量,也可在 .cargo/config.toml 下添加,示例如下:

# relative = true:值相对于本配置文件所在目录(项目根),任何目录下运行 cargo 都解析正确
[env]
UNITREE_SDK2_PATH = { value = "unitree_sdk2", relative = true }

优先级:UNITREE_SDK2_PATH > UNITREE_SDK2_URL > 默认 GitHub。克隆目录统一在构建临时目录(OUT_DIR)下,源目录零写入。