robot_description_builder/joint/
smartjointbuilder.rs

1mod smartjointtypes;
2
3pub mod smartparams;
4pub use smartjointtypes::{
5	ContinuousType, FixedType, FloatingType, NoType, PlanarType, PrismaticType, RevoluteType,
6};
7
8use super::joint_tranform_mode::JointTransformMode;
9use crate::{link::LinkShapeData, transform::Transform};
10use smartparams::{NoAxis, NoCalibration, NoDynamics, NoLimit, NoMimic, NoSafetyController};
11
12use self::smartparams::smart_joint_datatraits;
13
14#[cfg(feature = "wrapper")]
15use super::jointbuilder::JointBuilder;
16
17#[derive(Debug, PartialEq, Clone, Default)]
18pub struct SmartJointBuilder<Type, Axis, Calibration, Dynamics, Limit, Mimic, SafetyController>
19where
20	Axis: smart_joint_datatraits::AxisDataType,
21	Calibration: smart_joint_datatraits::CalibrationDataType,
22	Dynamics: smart_joint_datatraits::DynamicsDataType,
23	Limit: smart_joint_datatraits::LimitDataType,
24	Mimic: smart_joint_datatraits::MimicDataType,
25	SafetyController: smart_joint_datatraits::SafetyControllerDataType,
26{
27	name: String,
28	joint_type: Type,
29	/// The transform from the origin of the parent to the origin of this `Joint`.
30	///
31	/// In URDF this field is refered to as `<origin>`.
32	transform: Option<JointTransformMode>,
33	axis: Axis,
34	calibration: Calibration,
35	dynamics: Dynamics,
36	limit: Limit,
37	mimic: Mimic,
38	safety_controller: SafetyController,
39}
40
41impl<Type, Axis, Calibration, Dynamics, Limit, Mimic, SafetyController>
42	SmartJointBuilder<Type, Axis, Calibration, Dynamics, Limit, Mimic, SafetyController>
43where
44	Axis: smart_joint_datatraits::AxisDataType,
45	Calibration: smart_joint_datatraits::CalibrationDataType,
46	Dynamics: smart_joint_datatraits::DynamicsDataType,
47	Limit: smart_joint_datatraits::LimitDataType,
48	Mimic: smart_joint_datatraits::MimicDataType,
49	SafetyController: smart_joint_datatraits::SafetyControllerDataType,
50{
51	/// Renames the current `SmartJointBuilder`.
52	pub fn rename(mut self, name: impl Into<String>) -> Self {
53		self.name = name.into();
54		self
55	}
56
57	pub fn add_transform(mut self, transform: Transform) -> Self {
58		self.transform = Some(transform.into());
59		self
60	}
61
62	pub fn add_dynamic_transform(mut self, func: fn(LinkShapeData) -> Transform) -> Self {
63		self.transform = Some(func.into());
64		self
65	}
66}
67
68impl
69	SmartJointBuilder<NoType, NoAxis, NoCalibration, NoDynamics, NoLimit, NoMimic, NoSafetyController>
70{
71	/// Created a new `JointType`-less `SmartJointBuilder`.
72	pub fn new(
73		name: impl Into<String>,
74	) -> SmartJointBuilder<
75		NoType,
76		NoAxis,
77		NoCalibration,
78		NoDynamics,
79		NoLimit,
80		NoMimic,
81		NoSafetyController,
82	> {
83		SmartJointBuilder {
84			name: name.into(),
85			joint_type: NoType,
86			..SmartJointBuilder::default()
87		}
88	}
89
90	/// Creates a new `SmartJointBuilder` with `JointType::Revolute`.
91	pub fn new_revolute(
92		name: impl Into<String>,
93	) -> SmartJointBuilder<
94		RevoluteType,
95		NoAxis,
96		NoCalibration,
97		NoDynamics,
98		NoLimit,
99		NoMimic,
100		NoSafetyController,
101	> {
102		Self::new(name).revolute()
103	}
104
105	/// Creates a new `SmartJointBuilder` of type `Continuous`.
106	pub fn new_continuous(
107		name: impl Into<String>,
108	) -> SmartJointBuilder<
109		ContinuousType,
110		NoAxis,
111		NoCalibration,
112		NoDynamics,
113		NoLimit,
114		NoMimic,
115		NoSafetyController,
116	> {
117		Self::new(name).continuous()
118	}
119
120	/// Creates a new `SmartJointBuilder` of type `Prismatic`.
121	pub fn new_prismatic(
122		name: impl Into<String>,
123	) -> SmartJointBuilder<
124		PrismaticType,
125		NoAxis,
126		NoCalibration,
127		NoDynamics,
128		NoLimit,
129		NoMimic,
130		NoSafetyController,
131	> {
132		Self::new(name).prismatic()
133	}
134
135	/// Creates a new `SmartJointBuilder` of type `Fixed`.
136	pub fn new_fixed(
137		name: impl Into<String>,
138	) -> SmartJointBuilder<
139		FixedType,
140		NoAxis,
141		NoCalibration,
142		NoDynamics,
143		NoLimit,
144		NoMimic,
145		NoSafetyController,
146	> {
147		Self::new(name).fixed()
148	}
149
150	/// Creates a new `SmartJointBuilder` of type `Floating`.
151	pub fn new_floating(
152		name: impl Into<String>,
153	) -> SmartJointBuilder<
154		FloatingType,
155		NoAxis,
156		NoCalibration,
157		NoDynamics,
158		NoLimit,
159		NoMimic,
160		NoSafetyController,
161	> {
162		Self::new(name).floating()
163	}
164
165	/// Creates a new `SmartJointBuilder` of type `Planar`.
166	pub fn new_planar(
167		name: impl Into<String>,
168	) -> SmartJointBuilder<
169		PlanarType,
170		NoAxis,
171		NoCalibration,
172		NoDynamics,
173		NoLimit,
174		NoMimic,
175		NoSafetyController,
176	> {
177		Self::new(name).planar()
178	}
179
180	// TODO: Maybe move these to a more generic implementation
181	/// Converts this `SmartJointBuilder` to the `Revolute` type.
182	pub fn revolute(
183		self,
184	) -> SmartJointBuilder<
185		RevoluteType,
186		NoAxis,
187		NoCalibration,
188		NoDynamics,
189		NoLimit,
190		NoMimic,
191		NoSafetyController,
192	> {
193		SmartJointBuilder {
194			name: self.name,
195			joint_type: RevoluteType,
196			transform: self.transform,
197			axis: self.axis,
198			calibration: self.calibration,
199			dynamics: self.dynamics,
200			limit: self.limit,
201			mimic: self.mimic,
202			safety_controller: self.safety_controller,
203		}
204	}
205
206	/// Converts this `SmartJointBuilder` to the `Continuous` type.
207	pub fn continuous(
208		self,
209	) -> SmartJointBuilder<
210		ContinuousType,
211		NoAxis,
212		NoCalibration,
213		NoDynamics,
214		NoLimit,
215		NoMimic,
216		NoSafetyController,
217	> {
218		SmartJointBuilder {
219			name: self.name,
220			joint_type: ContinuousType,
221			transform: self.transform,
222			axis: self.axis,
223			calibration: self.calibration,
224			dynamics: self.dynamics,
225			limit: self.limit,
226			mimic: self.mimic,
227			safety_controller: self.safety_controller,
228		}
229	}
230
231	/// Converts this `SmartJointBuilder` to the `Prismatic` type.
232	pub fn prismatic(
233		self,
234	) -> SmartJointBuilder<
235		PrismaticType,
236		NoAxis,
237		NoCalibration,
238		NoDynamics,
239		NoLimit,
240		NoMimic,
241		NoSafetyController,
242	> {
243		SmartJointBuilder {
244			name: self.name,
245			joint_type: PrismaticType,
246			transform: self.transform,
247			axis: self.axis,
248			calibration: self.calibration,
249			dynamics: self.dynamics,
250			limit: self.limit,
251			mimic: self.mimic,
252			safety_controller: self.safety_controller,
253		}
254	}
255
256	// TODO: Maybe move these to a more generic implementation
257	/// Converts this `SmartJointBuilder` to the `Fixed` type.
258	pub fn fixed(
259		self,
260	) -> SmartJointBuilder<
261		FixedType,
262		NoAxis,
263		NoCalibration,
264		NoDynamics,
265		NoLimit,
266		NoMimic,
267		NoSafetyController,
268	> {
269		SmartJointBuilder {
270			name: self.name,
271			joint_type: FixedType,
272			transform: self.transform,
273			axis: self.axis,
274			calibration: self.calibration,
275			dynamics: self.dynamics,
276			limit: self.limit,
277			mimic: self.mimic,
278			safety_controller: self.safety_controller,
279		}
280	}
281
282	// TODO: ADD WARNING
283	/// Converts this `SmartJointBuilder` to the `Floating` type.
284	pub fn floating(
285		self,
286	) -> SmartJointBuilder<
287		FloatingType,
288		NoAxis,
289		NoCalibration,
290		NoDynamics,
291		NoLimit,
292		NoMimic,
293		NoSafetyController,
294	> {
295		SmartJointBuilder {
296			name: self.name,
297			joint_type: FloatingType,
298			transform: self.transform,
299			axis: self.axis,
300			calibration: self.calibration,
301			dynamics: self.dynamics,
302			limit: self.limit,
303			mimic: self.mimic,
304			safety_controller: self.safety_controller,
305		}
306	}
307
308	// TODO: ADD WARNING
309	/// Converts this `SmartJointBuilder` to the `Planar` type.
310	pub fn planar(
311		self,
312	) -> SmartJointBuilder<
313		PlanarType,
314		NoAxis,
315		NoCalibration,
316		NoDynamics,
317		NoLimit,
318		NoMimic,
319		NoSafetyController,
320	> {
321		SmartJointBuilder {
322			name: self.name,
323			joint_type: PlanarType,
324			transform: self.transform,
325			axis: self.axis,
326			calibration: self.calibration,
327			dynamics: self.dynamics,
328			limit: self.limit,
329			mimic: self.mimic,
330			safety_controller: self.safety_controller,
331		}
332	}
333}
334
335#[cfg(feature = "wrapper")]
336impl<Type, Axis, Calibration, Dynamics, Limit, Mimic, SafetyController>
337	SmartJointBuilder<Type, Axis, Calibration, Dynamics, Limit, Mimic, SafetyController>
338where
339	Type: smart_joint_datatraits::JointTypeTrait,
340	Axis: smart_joint_datatraits::AxisDataType,
341	Calibration: smart_joint_datatraits::CalibrationDataType,
342	Dynamics: smart_joint_datatraits::DynamicsDataType,
343	Limit: smart_joint_datatraits::LimitDataType,
344	Mimic: smart_joint_datatraits::MimicDataType,
345	SafetyController: smart_joint_datatraits::SafetyControllerDataType,
346{
347	/// Convert the `SmartJointBuilder` to a normal `JointBuilder`
348	///
349	/// # Safety
350	/// A normal [`JointBuilder`] is not checked for the required fields of its [`JointType`](super::JointType).
351	/// This could result in invalid descriptions.
352	pub unsafe fn as_simple(&self) -> JointBuilder {
353		let mut joint_builder = JointBuilder::new(self.name.clone(), self.joint_type.as_type());
354
355		self.axis.simplify(&mut joint_builder);
356		self.calibration.simplify(&mut joint_builder);
357		self.dynamics.simplify(&mut joint_builder);
358		self.limit.simplify(&mut joint_builder, Type::IS_CONTINOUS);
359		self.mimic.simplify(&mut joint_builder);
360		self.safety_controller.simplify(&mut joint_builder);
361
362		joint_builder
363	}
364}