robot_description_builder/joint/smartjointbuilder/smartparams/
limit.rs1use crate::joint::{
2 joint_data,
3 jointbuilder::JointBuilder,
4 smartjointbuilder::{smart_joint_datatraits, SmartJointBuilder},
5};
6
7pub trait LimitAllowed {}
10
11#[derive(Debug, Default, Clone)]
13pub struct NoLimit;
14impl smart_joint_datatraits::LimitDataType for NoLimit {}
15
16#[derive(Debug, Default, Clone)]
17pub struct WithLimit {
18 lower: Option<f32>,
20 upper: Option<f32>,
22 effort: f32,
24 velocity: f32,
26}
27
28impl From<WithLimit> for joint_data::LimitData {
29 fn from(value: WithLimit) -> Self {
30 Self {
31 lower: value.lower,
32 upper: value.upper,
33 effort: value.effort,
34 velocity: value.velocity,
35 }
36 }
37}
38
39impl smart_joint_datatraits::LimitDataType for WithLimit {
40 fn simplify(&self, joint_builder: &mut JointBuilder, is_continous: bool) {
41 joint_builder.with_limit_data(joint_data::LimitData {
42 lower: match is_continous {
43 true => None,
44 false => self.lower,
45 },
46 upper: match is_continous {
47 true => None,
48 false => self.upper,
49 },
50 effort: self.effort,
51 velocity: self.velocity,
52 })
53 }
54}
55
56impl<Type, Axis, Calibration, Dynamics, Mimic, SafetyController>
57 SmartJointBuilder<Type, Axis, Calibration, Dynamics, NoLimit, Mimic, SafetyController>
58where
59 Type: LimitAllowed,
60 Axis: smart_joint_datatraits::AxisDataType,
61 Calibration: smart_joint_datatraits::CalibrationDataType,
62 Dynamics: smart_joint_datatraits::DynamicsDataType,
63 Mimic: smart_joint_datatraits::MimicDataType,
64 SafetyController: smart_joint_datatraits::SafetyControllerDataType,
65{
66 pub fn with_limit(
67 self,
68 effort: f32,
69 velocity: f32,
70 ) -> SmartJointBuilder<Type, Axis, Calibration, Dynamics, WithLimit, Mimic, SafetyController> {
71 SmartJointBuilder {
72 name: self.name,
73 joint_type: self.joint_type,
74 transform: self.transform,
75 axis: self.axis,
76 calibration: self.calibration,
77 dynamics: self.dynamics,
78 limit: WithLimit {
79 lower: None,
80 upper: None,
81 effort,
82 velocity,
83 },
84 mimic: self.mimic,
85 safety_controller: self.safety_controller,
86 }
87 }
88}
89
90impl<Type, Axis, Calibration, Dynamics, Mimic, SafetyController>
91 SmartJointBuilder<Type, Axis, Calibration, Dynamics, WithLimit, Mimic, SafetyController>
92where
93 Type: LimitAllowed,
94 Axis: smart_joint_datatraits::AxisDataType,
95 Calibration: smart_joint_datatraits::CalibrationDataType,
96 Dynamics: smart_joint_datatraits::DynamicsDataType,
97 Mimic: smart_joint_datatraits::MimicDataType,
98 SafetyController: smart_joint_datatraits::SafetyControllerDataType,
99{
100 pub fn set_effort(mut self, effort: f32) -> Self {
101 self.limit.effort = effort;
102 self
103 }
104
105 pub fn effort(&self) -> f32 {
106 self.limit.effort
107 }
108
109 pub fn set_velocity(mut self, velocity: f32) -> Self {
111 self.limit.velocity = velocity;
112 self
113 }
114
115 pub fn velocity(&self) -> f32 {
117 self.limit.velocity
118 }
119}
120
121impl<Type, Axis, Calibration, Dynamics, Mimic, SafetyController>
123 SmartJointBuilder<Type, Axis, Calibration, Dynamics, WithLimit, Mimic, SafetyController>
124where
125 Type: LimitAllowed + smart_joint_datatraits::SmartJointTypeTrait<false>,
126 Axis: smart_joint_datatraits::AxisDataType,
127 Calibration: smart_joint_datatraits::CalibrationDataType,
128 Dynamics: smart_joint_datatraits::DynamicsDataType,
129 Mimic: smart_joint_datatraits::MimicDataType,
130 SafetyController: smart_joint_datatraits::SafetyControllerDataType,
131{
132 pub fn set_upper_limit(mut self, upper_limit: f32) -> Self {
134 self.limit.upper = Some(upper_limit);
135 self
136 }
137
138 pub fn upper_limit(&self) -> Option<f32> {
140 self.limit.upper
141 }
142
143 pub fn set_lower_limit(mut self, lower_limit: f32) -> Self {
145 self.limit.lower = Some(lower_limit);
146 self
147 }
148
149 pub fn lower_limit(&self) -> Option<f32> {
151 self.limit.lower
152 }
153}