04 机械臂流式控制接口
流式控制接口用于运动目标在执行前未知,在执行过程中由上位机实时下发的场景。流式控制的核心是通过 start_streaming 获取一个流式控制句柄(Handle),然后通过句柄不断设置新的运动/控制目标。同时也提供了基于共享对象的方式,通过线程安全的共享变量来传递目标。
使用方式
流式控制有两种使用方式:
方式一:句柄模式
通过 start_streaming() 获取句柄,然后通过句柄下发运动目标。
方式二:共享对象模式
通过 move_to_target() 等方法获取线程安全的共享对象,在其他线程中修改目标值。
ArmStreamingMotion 接口
pub trait ArmStreamingMotion<const N: usize>: Arm<N> {
type Handle: ArmStreamingHandle<N>;
fn start_streaming(&mut self) -> RobotResult<Self::Handle>;
fn end_streaming(&mut self) -> RobotResult<()>;
fn move_to_target(&mut self) -> Arc<Mutex<Option<MotionType<N>>>>;
fn control_with_target(&mut self) -> Arc<Mutex<Option<ControlType<N>>>>;
}
ArmStreamingMotionExt 扩展接口
扩展接口提供各种具体类型的共享对象访问:
pub trait ArmStreamingMotionExt<const N: usize>: ArmStreamingMotion<N> {
fn move_joint_target(&mut self) -> Arc<Mutex<Option<[f64; N]>>>;
fn move_joint_vel_target(&mut self) -> Arc<Mutex<Option<[f64; N]>>>;
fn move_joint_acc_target(&mut self) -> Arc<Mutex<Option<[f64; N]>>>;
fn move_cartesian_target(&mut self) -> Arc<Mutex<Option<Pose>>>;
fn move_cartesian_vel_target(&mut self) -> Arc<Mutex<Option<[f64; 6]>>>;
fn move_cartesian_euler_target(&mut self) -> Arc<Mutex<Option<[f64; 6]>>>;
fn move_cartesian_quat_target(&mut self) -> Arc<Mutex<Option<na::Isometry3<f64>>>>;
fn move_cartesian_homo_target(&mut self) -> Arc<Mutex<Option<[f64; 16]>>>;
fn control_tau_target(&mut self) -> Arc<Mutex<Option<[f64; N]>>>;
}
class ArmStreamingMotionExt:
def move_joint_target(self) -> object: ...
def move_joint_vel_target(self) -> object: ...
def move_joint_acc_target(self) -> object: ...
def move_cartesian_target(self) -> object: ...
def move_cartesian_vel_target(self) -> object: ...
def move_cartesian_euler_target(self) -> object: ...
def move_cartesian_quat_target(self) -> object: ...
def move_cartesian_homo_target(self) -> object: ...
def control_tau_target(self) -> object: ...
流式控制句柄
ArmStreamingHandle 是流式控制的操作句柄,提供上一帧运动/控制目标的读取和新目标的设置: