@@ -75,10 +75,6 @@ inline typename Derived1::PlainObject PdControl(
75
75
if (x_err_sq_norm > ddx_max_sq) {
76
76
x_err *= ddx_max / std::sqrt (x_err_sq_norm);
77
77
}
78
- const double dx_err_sq_norm = dx_err.squaredNorm ();
79
- if (dx_err_sq_norm > ddx_max_sq) {
80
- dx_err *= ddx_max / std::sqrt (dx_err_sq_norm);
81
- }
82
78
}
83
79
84
80
return x_err + dx_err;
@@ -120,11 +116,10 @@ inline typename Derived1::PlainObject PdControl(
120
116
121
117
// Limit maximum error
122
118
if (ddx_max > 0 .) {
123
- if (x_err.norm () > ddx_max) {
124
- x_err = ddx_max * x_err.normalized ();
125
- }
126
- if (dx_err.norm () > ddx_max) {
127
- dx_err = ddx_max * dx_err.normalized ();
119
+ const double x_err_sq_norm = x_err.squaredNorm ();
120
+ const double ddx_max_sq = ddx_max * ddx_max;
121
+ if (x_err_sq_norm > ddx_max_sq) {
122
+ x_err *= ddx_max / std::sqrt (x_err_sq_norm);
128
123
}
129
124
}
130
125
@@ -196,10 +191,6 @@ inline typename Derived1::PlainObject PdControl(
196
191
if (ori_err_sq_norm > dw_max_sq) {
197
192
ori_err *= dw_max / std::sqrt (ori_err_sq_norm);
198
193
}
199
- const double w_err_sq_norm = w_err.squaredNorm ();
200
- if (w_err_sq_norm > dw_max_sq) {
201
- w_err *= dw_max / std::sqrt (w_err_sq_norm);
202
- }
203
194
}
204
195
205
196
return ori_err + w_err;
@@ -235,11 +226,10 @@ inline typename Derived1::PlainObject PdControl(
235
226
236
227
// Limit maximum error
237
228
if (dw_max > 0 .) {
238
- if (ori_err.norm () > dw_max) {
239
- ori_err = dw_max * ori_err.normalized ();
240
- }
241
- if (w_err.norm () > dw_max) {
242
- w_err = dw_max * w_err.normalized ();
229
+ const double ori_err_sq_norm = ori_err.squaredNorm ();
230
+ const double dw_max_sq = dw_max * dw_max;
231
+ if (ori_err_sq_norm > dw_max_sq) {
232
+ ori_err *= dw_max / std::sqrt (ori_err_sq_norm);
243
233
}
244
234
}
245
235
0 commit comments