Skip to main content

PiperBuilder

Struct PiperBuilder 

Source
pub struct PiperBuilder { /* private fields */ }
Expand description

Piper Builder(链式构造)

使用 Builder 模式创建 Piper 实例,支持链式调用。

§Example

use piper_driver::{PiperBuilder, PipelineConfig};

// 使用默认配置
let piper = PiperBuilder::new()
    .build()
    .unwrap();

// 自定义波特率和 Pipeline 配置
let config = PipelineConfig {
    receive_timeout_ms: 5,
    frame_group_timeout_ms: 20,
    velocity_buffer_timeout_us: 20_000,
};
let piper = PiperBuilder::new()
    .baud_rate(500_000)
    .pipeline_config(config)
    .build()
    .unwrap();

Implementations§

Source§

impl PiperBuilder

Source

pub fn new() -> Self

创建新的 Builder

§Example
use piper_driver::PiperBuilder;

let builder = PiperBuilder::new();
Source

pub fn with_driver_type(self, driver_type: DriverType) -> Self

显式指定驱动类型(可选,默认 Auto)

§Example
use piper_driver::{PiperBuilder, DriverType};

// 强制使用 GS-USB
let piper = PiperBuilder::new()
    .with_driver_type(DriverType::GsUsb)
    .build()
    .unwrap();
Source

pub fn interface(self, interface: impl Into<String>) -> Self

设置 CAN 接口(可选,默认自动检测)

§注意
  • Linux: 此参数可以是 SocketCAN 接口名称(如 “can0” 或 “vcan0”)或 GS-USB 设备序列号
    • 如果接口名是 “can0”/“can1” 等,优先使用 SocketCAN(通过 Smart Default)
    • 如果接口名是设备序列号或未提供,使用 GS-USB
  • macOS/Windows (GS-USB): 此参数用作设备序列号,用于区分多个 GS-USB 设备
    • 如果提供序列号,只打开匹配序列号的设备
    • 如果不提供,自动选择第一个找到的设备
§Example
use piper_driver::PiperBuilder;

// 通过序列号指定设备
let piper = PiperBuilder::new()
    .interface("ABC123456")
    .build()
    .unwrap();
Source

pub fn baud_rate(self, baud_rate: u32) -> Self

设置 CAN 波特率(可选,默认 1M)

Source

pub fn pipeline_config(self, config: PipelineConfig) -> Self

设置 Pipeline 配置(可选)

Source

pub fn with_daemon(self, daemon_addr: impl Into<String>) -> Self

使用守护进程模式(可选)

当指定守护进程地址时,使用 GsUsbUdpAdapter 通过守护进程访问 GS-USB 设备。 这解决了 macOS 下 GS-USB 设备重连后无法正常工作的限制。

§参数
  • daemon_addr: 守护进程地址
    • UDS 路径(如 “/tmp/gs_usb_daemon.sock”)
    • UDP 地址(如 “127.0.0.1:8888”)
§Example
use piper_driver::PiperBuilder;

// 使用 UDS 连接守护进程
let piper = PiperBuilder::new()
    .with_daemon("/tmp/gs_usb_daemon.sock")
    .build()
    .unwrap();

// 使用 UDP 连接守护进程(用于跨机器调试)
let piper = PiperBuilder::new()
    .with_daemon("127.0.0.1:8888")
    .build()
    .unwrap();
Source

pub fn build(self) -> Result<Piper, DriverError>

构建 Piper 实例

创建并启动 Piper 实例,启动后台 IO 线程。

§Errors
  • DriverError::Can: CAN 设备初始化失败
§Example
use piper_driver::PiperBuilder;

match PiperBuilder::new().build() {
    Ok(piper) => {
        // 使用 piper 读取状态
        let state = piper.get_joint_position();
    }
    Err(e) => {
        eprintln!("Failed to create Piper: {}", e);
    }
}

Trait Implementations§

Source§

impl Default for PiperBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more