pub struct JointDynamicState {
pub group_timestamp_us: u64,
pub joint_vel: [f64; 6],
pub joint_current: [f64; 6],
pub timestamps: [u64; 6],
pub valid_mask: u8,
}Expand description
关节动态状态(独立帧,但通过缓冲提交保证一致性)
更新频率:500Hz 大小:< 150 字节,Clone 开销低 同步机制:Buffered Commit(收集 6 个关节的速度帧,集齐或超时后一次性提交) 时间同步性:通过 Group Commit 机制,保证 6 个关节数据来自同一 CAN 传输周期
Fields§
§group_timestamp_us: u64整个组的大致时间戳(最新一帧的时间,微秒)
注意:存储的是硬件时间戳(来自 PiperFrame.timestamp_us),不是 UNIX 时间戳。
硬件时间戳是设备相对时间,用于帧间时间差计算,不能直接与系统时间戳比较。
joint_vel: [f64; 6]关节速度(rad/s)[J1, J2, J3, J4, J5, J6]
joint_current: [f64; 6]关节电流(A)[J1, J2, J3, J4, J5, J6]
注意:扭矩可以通过 get_torque(joint_index) 方法从电流值实时计算得到。
- 关节 1-3 (J1, J2, J3):
torque = current * COEFFICIENT_1_3(1.18125) - 关节 4-6 (J4, J5, J6):
torque = current * COEFFICIENT_4_6(0.95844)
timestamps: [u64; 6]每个关节的具体更新时间(用于调试或高阶插值)
valid_mask: u8有效性掩码(Bit 0-5 对应 Joint 1-6)
- 1 表示本周期内已更新
- 0 表示未更新(可能是丢帧)
Implementations§
Source§impl JointDynamicState
impl JointDynamicState
Sourcepub const COEFFICIENT_1_3: f64 = 1.18125
pub const COEFFICIENT_1_3: f64 = 1.18125
关节 1-3 的力矩系数(CAN ID: 0x251~0x253)
根据官方参考实现,关节 1、2、3 使用此系数计算力矩。 公式:torque = current * COEFFICIENT_1_3
Sourcepub const COEFFICIENT_4_6: f64 = 0.95844
pub const COEFFICIENT_4_6: f64 = 0.95844
关节 4-6 的力矩系数(CAN ID: 0x254~0x256)
根据官方参考实现,关节 4、5、6 使用此系数计算力矩。 公式:torque = current * COEFFICIENT_4_6
Sourcepub fn calculate_torque(joint_index: usize, current: f64) -> f64
pub fn calculate_torque(joint_index: usize, current: f64) -> f64
Sourcepub fn get_torque(&self, joint_index: usize) -> f64
pub fn get_torque(&self, joint_index: usize) -> f64
Sourcepub fn get_all_torques(&self) -> [f64; 6]
pub fn get_all_torques(&self) -> [f64; 6]
获取所有关节的扭矩(N·m)
一次性计算并返回所有6个关节的扭矩值,比多次调用 get_torque() 更高效。
§返回值
包含所有关节扭矩的数组 [J1, J2, J3, J4, J5, J6](N·m)
§示例
let mut state = JointDynamicState::default();
state.joint_current = [1.0, 2.0, 0.5, 1.0, 2.0, 0.5];
let all_torques = state.get_all_torques();
// all_torques[0] = 1.0 * 1.18125 = 1.18125 N·m (J1)
// all_torques[3] = 1.0 * 0.95844 = 0.95844 N·m (J4)Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
检查所有关节是否都已更新(valid_mask == 0x3F)
Sourcepub fn missing_joints(&self) -> Vec<usize>
pub fn missing_joints(&self) -> Vec<usize>
获取未更新的关节索引(用于调试)
Trait Implementations§
Source§impl Clone for JointDynamicState
impl Clone for JointDynamicState
Source§fn clone(&self) -> JointDynamicState
fn clone(&self) -> JointDynamicState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for JointDynamicState
impl Debug for JointDynamicState
Source§impl Default for JointDynamicState
impl Default for JointDynamicState
Source§fn default() -> JointDynamicState
fn default() -> JointDynamicState
Auto Trait Implementations§
impl Freeze for JointDynamicState
impl RefUnwindSafe for JointDynamicState
impl Send for JointDynamicState
impl Sync for JointDynamicState
impl Unpin for JointDynamicState
impl UnwindSafe for JointDynamicState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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