@@ -49,24 +49,58 @@ bool JointSoftLimiter::on_enforce(
4949 {
5050 if (desired.has_position ())
5151 {
52- prev_command_.position = actual.has_position () ? actual.position : desired.position ;
52+ if (actual.has_position ())
53+ {
54+ prev_command_.position = actual.position ;
55+ }
56+ else if (!std::isnan (desired.position .value ()))
57+ {
58+ prev_command_.position = desired.position ;
59+ }
5360 }
5461 if (desired.has_velocity ())
5562 {
56- prev_command_.velocity = actual.has_velocity () ? actual.velocity : desired.velocity ;
63+ if (actual.has_velocity ())
64+ {
65+ prev_command_.velocity = actual.velocity ;
66+ }
67+ else if (!std::isnan (desired.velocity .value ()))
68+ {
69+ prev_command_.velocity = desired.velocity ;
70+ }
5771 }
5872 if (desired.has_effort ())
5973 {
60- prev_command_.effort = actual.has_effort () ? actual.effort : desired.effort ;
74+ if (actual.has_effort ())
75+ {
76+ prev_command_.effort = actual.effort ;
77+ }
78+ else if (!std::isnan (desired.effort .value ()))
79+ {
80+ prev_command_.effort = desired.effort ;
81+ }
6182 }
6283 if (desired.has_acceleration ())
6384 {
64- prev_command_.acceleration =
65- actual.has_acceleration () ? actual.acceleration : desired.acceleration ;
85+ if (actual.has_acceleration ())
86+ {
87+ prev_command_.acceleration = actual.acceleration ;
88+ }
89+ else if (!std::isnan (desired.acceleration .value ()))
90+ {
91+ prev_command_.acceleration = desired.acceleration ;
92+ }
6693 }
6794 if (desired.has_jerk ())
6895 {
69- prev_command_.jerk = actual.has_jerk () ? actual.jerk : desired.jerk ;
96+ if (actual.has_jerk ())
97+ {
98+ prev_command_.jerk = actual.jerk ;
99+ }
100+ else if (!std::isnan (desired.jerk .value ()))
101+ {
102+ prev_command_.jerk = desired.jerk ;
103+ }
70104 }
71105 if (actual.has_data ())
72106 {
@@ -132,7 +166,7 @@ bool JointSoftLimiter::on_enforce(
132166 }
133167 }
134168
135- if (desired.has_position ())
169+ if (desired.has_position () && ! std::isnan (desired. position . value ()) )
136170 {
137171 const auto position_limits = compute_position_limits (
138172 joint_name, hard_limits, actual.velocity , actual.position , prev_command_.position ,
@@ -170,7 +204,7 @@ bool JointSoftLimiter::on_enforce(
170204 desired.position = std::clamp (desired.position .value (), pos_low, pos_high);
171205 }
172206
173- if (desired.has_velocity ())
207+ if (desired.has_velocity () && ! std::isnan (desired. velocity . value ()) )
174208 {
175209 const auto velocity_limits = compute_velocity_limits (
176210 joint_name, hard_limits, desired.velocity .value (), actual.position , prev_command_.velocity ,
@@ -192,7 +226,7 @@ bool JointSoftLimiter::on_enforce(
192226 desired.velocity = std::clamp (desired.velocity .value (), soft_min_vel, soft_max_vel);
193227 }
194228
195- if (desired.has_effort ())
229+ if (desired.has_effort () && ! std::isnan (desired. effort . value ()) )
196230 {
197231 const auto effort_limits =
198232 compute_effort_limits (hard_limits, actual.position , actual.velocity , dt_seconds);
@@ -221,7 +255,7 @@ bool JointSoftLimiter::on_enforce(
221255 desired.effort = std::clamp (desired.effort .value (), soft_min_eff, soft_max_eff);
222256 }
223257
224- if (desired.has_acceleration ())
258+ if (desired.has_acceleration () && ! std::isnan (desired. acceleration . value ()) )
225259 {
226260 const auto limits =
227261 compute_acceleration_limits (hard_limits, desired.acceleration .value (), actual.velocity );
@@ -232,35 +266,14 @@ bool JointSoftLimiter::on_enforce(
232266 std::clamp (desired.acceleration .value (), limits.lower_limit , limits.upper_limit );
233267 }
234268
235- if (desired.has_jerk ())
269+ if (desired.has_jerk () && ! std::isnan (desired. jerk . value ()) )
236270 {
237271 limits_enforced =
238272 is_limited (desired.jerk .value (), -hard_limits.max_jerk , hard_limits.max_jerk ) ||
239273 limits_enforced;
240274 desired.jerk = std::clamp (desired.jerk .value (), -hard_limits.max_jerk , hard_limits.max_jerk );
241275 }
242276
243- if (desired.has_position () && !std::isfinite (desired.position .value ()) && actual.has_position ())
244- {
245- desired.position = actual.position ;
246- limits_enforced = true ;
247- }
248- if (desired.has_velocity () && !std::isfinite (desired.velocity .value ()))
249- {
250- desired.velocity = 0.0 ;
251- limits_enforced = true ;
252- }
253- if (desired.has_acceleration () && !std::isfinite (desired.acceleration .value ()))
254- {
255- desired.acceleration = 0.0 ;
256- limits_enforced = true ;
257- }
258- if (desired.has_jerk () && !std::isfinite (desired.jerk .value ()))
259- {
260- desired.jerk = 0.0 ;
261- limits_enforced = true ;
262- }
263-
264277 update_prev_command (desired, prev_command_);
265278
266279 return limits_enforced;
0 commit comments