Skip to content

Commit 3ab2d66

Browse files
committed
Fix acceleration limiting bug
1 parent f0f8a50 commit 3ab2d66

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

include/ctrl_utils/control.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ inline typename Derived1::PlainObject PdControl(
7575
if (x_err_sq_norm > ddx_max_sq) {
7676
x_err *= ddx_max / std::sqrt(x_err_sq_norm);
7777
}
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-
}
8278
}
8379

8480
return x_err + dx_err;
@@ -120,11 +116,10 @@ inline typename Derived1::PlainObject PdControl(
120116

121117
// Limit maximum error
122118
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);
128123
}
129124
}
130125

@@ -196,10 +191,6 @@ inline typename Derived1::PlainObject PdControl(
196191
if (ori_err_sq_norm > dw_max_sq) {
197192
ori_err *= dw_max / std::sqrt(ori_err_sq_norm);
198193
}
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-
}
203194
}
204195

205196
return ori_err + w_err;
@@ -235,11 +226,10 @@ inline typename Derived1::PlainObject PdControl(
235226

236227
// Limit maximum error
237228
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);
243233
}
244234
}
245235

0 commit comments

Comments
 (0)