Skip to main content

franka/robot/
options.rs

1//! Connect-time options and the value types the FCI v5 getters return.
2
3use crate::realtime::RealtimeConfig;
4use crate::wire::robot::codec::FciVersion;
5
6use super::DEFAULT_LOG_SIZE;
7
8/// How [`crate::Robot`] decides which FCI protocol version to speak.
9///
10/// The two supported versions are not distinguishable before the `Connect` handshake, so the
11/// default probes: FCI v10 first, then FCI v5 if the server rejects it *and* reports version 5.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
13pub enum VersionPolicy {
14    /// Connect as FCI v10 (FR3). If the server answers `kIncompatibleLibraryVersion` reporting
15    /// version 5, close both sockets and reconnect once as FCI v5 (FER). Any other server
16    /// version is reported as [`crate::error::FrankaError::IncompatibleVersion`].
17    #[default]
18    Auto,
19    /// Connect as exactly this version and never retry; a mismatch is
20    /// [`crate::error::FrankaError::IncompatibleVersion`].
21    Exact(FciVersion),
22}
23
24/// Everything [`crate::Robot::with_options`] can be told at connect time.
25///
26/// The defaults are [`crate::Robot::new`]'s: [`RealtimeConfig::Enforce`] is *not* assumed — the field
27/// has no libfranka default and must be chosen — so [`RobotOptions::new`] takes it and the
28/// [`Default`] impl uses [`RealtimeConfig::Enforce`], matching `franka::Robot`'s default
29/// argument.
30#[derive(Debug, Clone)]
31pub struct RobotOptions {
32    /// Realtime priority policy, as [`crate::Robot::new`]'s second argument.
33    pub realtime_config: RealtimeConfig,
34    /// Which FCI version to speak.
35    pub version: VersionPolicy,
36    /// Size of the control log attached to a [`crate::error::ControlException`]; `0` disables
37    /// logging.
38    pub log_size: usize,
39}
40
41impl Default for RobotOptions {
42    fn default() -> Self {
43        RobotOptions {
44            realtime_config: RealtimeConfig::Enforce,
45            version: VersionPolicy::Auto,
46            log_size: DEFAULT_LOG_SIZE,
47        }
48    }
49}
50
51impl RobotOptions {
52    /// Options with `realtime_config`, [`VersionPolicy::Auto`] and [`DEFAULT_LOG_SIZE`].
53    pub fn new(realtime_config: RealtimeConfig) -> RobotOptions {
54        RobotOptions {
55            realtime_config,
56            ..RobotOptions::default()
57        }
58    }
59
60    /// Sets the version policy.
61    pub fn with_version(mut self, version: VersionPolicy) -> RobotOptions {
62        self.version = version;
63        self
64    }
65
66    /// Sets the control log size.
67    pub fn with_log_size(mut self, log_size: usize) -> RobotOptions {
68        self.log_size = log_size;
69        self
70    }
71}
72
73/// Parameters of a cuboid used as a virtual wall (`franka::VirtualWallCuboid`,
74/// libfranka 0.9.2 `include/franka/command_types.h`).
75///
76/// Returned by [`crate::Robot::virtual_wall`], which is FCI v5 only.
77#[derive(Debug, Clone, Copy, PartialEq)]
78pub struct VirtualWallCuboid {
79    /// ID of the virtual wall.
80    pub id: i32,
81    /// Corner point of the cuboid in the world frame, in \[m\].
82    pub object_world_size: [f64; 3],
83    /// 4x4 transformation matrix, column-major.
84    pub p_frame: [f64; 16],
85    /// `true` if this Cartesian limit is active.
86    pub active: bool,
87}