robot_description_builder/joint/smartjointbuilder/smartparams/
mimic.rs

1use crate::joint::{
2	joint_data,
3	jointbuilder::JointBuilder,
4	smartjointbuilder::{smart_joint_datatraits, SmartJointBuilder},
5};
6
7/// A trait to label a `SmartJointType` that is allowed to mimic another joint.
8pub trait MimicAllowed {}
9
10/// A type to significy that no [`Mimic`](joint_data::MimicData) was specified.
11#[derive(Debug, Default, Clone)]
12pub struct NoMimic;
13impl smart_joint_datatraits::MimicDataType for NoMimic {}
14
15//  (optional) (New with ROS Groovy. See issue)
16//
17// This tag is used to specify that the defined joint mimics another existing joint. The value of this joint can be computed as value = multiplier * other_joint_value + offset.
18// TODO: Write better docs
19#[derive(Debug, Default, Clone)]
20pub struct WithMimic {
21	/// This specifies the name of the joint to mimic.
22	joint_name: String,
23	/// Specifies the multiplicative factor in the formula above.
24	multiplier: Option<f32>,
25	/// Specifies the offset to add in the formula above. Defaults to 0 (radians for revolute joints, meters for prismatic joints).
26	offset: Option<f32>,
27}
28
29impl From<WithMimic> for joint_data::MimicBuilderData {
30	fn from(value: WithMimic) -> Self {
31		Self {
32			joint_name: value.joint_name,
33			multiplier: value.multiplier,
34			offset: value.offset,
35		}
36	}
37}
38
39impl smart_joint_datatraits::MimicDataType for WithMimic {
40	fn simplify(&self, joint_builder: &mut JointBuilder) {
41		joint_builder.with_mimic_data(self.clone().into())
42	}
43}
44
45impl<Type, Axis, Calibration, Dynamics, Limit, SafetyController>
46	SmartJointBuilder<Type, Axis, Calibration, Dynamics, Limit, NoMimic, SafetyController>
47where
48	Type: MimicAllowed,
49	Axis: smart_joint_datatraits::AxisDataType,
50	Calibration: smart_joint_datatraits::CalibrationDataType,
51	Dynamics: smart_joint_datatraits::DynamicsDataType,
52	Limit: smart_joint_datatraits::LimitDataType,
53	SafetyController: smart_joint_datatraits::SafetyControllerDataType,
54{
55	pub fn with_mimic(
56		self,
57		mimiced_joint_name: impl Into<String>,
58	) -> SmartJointBuilder<Type, Axis, Calibration, Dynamics, Limit, WithMimic, SafetyController> {
59		SmartJointBuilder {
60			name: self.name,
61			joint_type: self.joint_type,
62			transform: self.transform,
63
64			axis: self.axis,
65			calibration: self.calibration,
66			dynamics: self.dynamics,
67			limit: self.limit,
68			mimic: WithMimic {
69				joint_name: mimiced_joint_name.into(),
70				..Default::default()
71			},
72			safety_controller: self.safety_controller,
73		}
74	}
75}
76
77impl<Type, Axis, Calibration, Dynamics, Limit, SafetyController>
78	SmartJointBuilder<Type, Axis, Calibration, Dynamics, Limit, WithMimic, SafetyController>
79where
80	Type: MimicAllowed,
81	Axis: smart_joint_datatraits::AxisDataType,
82	Calibration: smart_joint_datatraits::CalibrationDataType,
83	Dynamics: smart_joint_datatraits::DynamicsDataType,
84	Limit: smart_joint_datatraits::LimitDataType,
85	SafetyController: smart_joint_datatraits::SafetyControllerDataType,
86{
87	pub fn set_mimiced_joint_name(mut self, mimiced_joint_name: impl Into<String>) -> Self {
88		self.mimic.joint_name = mimiced_joint_name.into();
89		self
90	}
91
92	pub fn mimiced_joint_name(&self) -> &String {
93		&self.mimic.joint_name
94	}
95
96	pub fn set_mimic_multiplier(mut self, multiplier: f32) -> Self {
97		self.mimic.multiplier = Some(multiplier);
98		self
99	}
100
101	pub fn mimic_multiplier(&self) -> Option<f32> {
102		self.mimic.multiplier
103	}
104
105	/// Specifies the offset to add in the formula above. Defaults to 0 (radians for revolute joints, meters for prismatic joints).
106	pub fn set_mimic_offset(mut self, offset: f32) -> Self {
107		self.mimic.offset = Some(offset);
108		self
109	}
110
111	pub fn mimic_offset(&self) -> Option<f32> {
112		self.mimic.offset
113	}
114}