Skip to main content

MitController

Struct MitController 

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

MIT 模式高层控制器

核心特性

  • ✅ Option 模式:允许安全提取 Piper
  • ✅ 循环锚点:消除累积漂移,保证精确 200Hz
  • ✅ 容错性:允许最多连续 5 帧丢帧
  • ✅ 状态流转:park() 返还 Piper<Standby>

Implementations§

Source§

impl MitController

Source

pub fn new(piper: Piper<Active<MitMode>>, config: MitControllerConfig) -> Self

创建新的 MIT 控制器

§参数
  • piper: 已使能 MIT 模式的 Piper
  • config: 控制器配置
§示例
let config = MitControllerConfig::default();
Source

pub fn move_to_position( &mut self, target: [Rad; 6], threshold: Rad, timeout: Duration, ) -> Result<bool, ControlError>

阻塞式运动到目标位置

循环锚点机制

  • ✅ 使用绝对时间锚点,消除累积漂移
  • ✅ 无论 CAN 通信耗时多少,频率都锁定在 200Hz
  • ✅ 自动处理任务超时(Overrun)
§容错性

控制循环具有容错性:允许偶尔的 CAN 通信错误(最多连续 5 帧)。

§参数
  • target: 目标关节位置(弧度)
  • threshold: 到达阈值(弧度)
  • timeout: 超时时间
§返回
  • Ok(true): 到达目标
  • Ok(false): 超时未到达
  • Err(ControlError::ConsecutiveFailures): 连续错误超过阈值
§示例
// 运动到目标位置,5秒超时
Source

pub fn relax_joints(&mut self)

放松关节(发送零力矩命令)

注意:此方法只发送一次零力矩命令,不会阻塞。 如果需要让关节自然下垂,应该多次调用或在循环中调用。

§软降级

如果发送失败,只记录警告,不返回错误(软降级策略)。

§示例
controller.relax_joints();
Source

pub fn park(self, config: DisableConfig) -> Result<Piper<Standby>>

停车(失能并返还 Piper<Standby>

资源管理

  • ✅ 返还 Piper<Standby>,支持继续使用
  • ✅ 使用 Option 模式,安全提取 Piper
§安全保证

显式调用 park()(推荐):

  • 提取 Piper,调用 disable(),等待完成
  • 返回 Piper<Standby> 可继续使用
  • 不会触发 Piper 的 Drop

忘记调用 park()(安全网):

  • MitController 被 drop 时,Piper<Active>::drop() 自动触发
  • 发送 disable 命令(不等待确认)
  • 电机被安全失能
§示例

// 方式 1:显式停车(推荐)
let piper_standby = controller.park(DisableConfig::default())?;
// 现在 piper_standby 可以重新使能或做其他操作

// 方式 2:直接丢弃(触发自动安全失能)
// drop(controller);  // 自动调用 Piper::drop(),发送 disable 命令
Source

pub fn observer(&self) -> &Observer

获取 Observer(只读)

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