@@ -183,7 +183,8 @@ GTEST_TEST(SapPdControllerConstraint, MakeDataNearRigidRegime) {
183
183
184
184
const double dt = 0.015 ;
185
185
const double large_Kp = 1e8 ;
186
- const double large_Kd = 1e7 ;
186
+ const double tau = 0.13 ;
187
+ const double large_Kd = tau * large_Kp;
187
188
const double effort_limit = 0.3 ;
188
189
const Parameters p{large_Kp, large_Kd, effort_limit};
189
190
// The configuration is irrelevant for this test.
@@ -193,19 +194,85 @@ GTEST_TEST(SapPdControllerConstraint, MakeDataNearRigidRegime) {
193
194
const VectorXd w = Vector1d::Constant (1.6 );
194
195
195
196
const double Rnr = kBeta * kBeta / (4.0 * M_PI * M_PI) * w (0 );
196
- // Expected near-rigid parameters.
197
- const double Kp_nr = 1.0 / Rnr / (2.0 * dt * dt );
198
- const double Kd_nr = dt * Kp_nr;
197
+ // Expected near-rigid parameters. Time scale tau is kept constant.
198
+ const double Kp_nr = 1.0 / Rnr / (dt * ( dt + tau) );
199
+ const double Kd_nr = tau * Kp_nr;
199
200
200
201
// Verify that gains were clamped to be in the near-rigid regime.
201
202
auto abstract_data = c.MakeData (dt, w);
202
203
const auto & data =
203
204
abstract_data->get_value <SapPdControllerConstraintData<double >>();
204
- EXPECT_NEAR (data.Kp_eff (), Kp_nr, kEps );
205
+ EXPECT_NEAR (data.Kp_eff (), Kp_nr, kEps * large_Kp);
206
+ EXPECT_NEAR (data.Kd_eff (), Kd_nr, kEps * large_Kd);
207
+ EXPECT_EQ (data.time_step (), dt); // not affected.
208
+ }
209
+
210
+ // Verify the effective gains within the near-rigid regime when the user sets
211
+ // the position gain Kp to zero. In particular, the effective position gain
212
+ // should remain zero to respect the user's desire to do velocity control only.
213
+ GTEST_TEST (SapPdControllerConstraint, MakeDataNearRigidRegimeWithZeroKp) {
214
+ // This value of near-rigid parameter is the one internally used by
215
+ // SapPdControllerConstraint and they must remain in sync.
216
+ constexpr double kBeta = 0.1 ;
217
+
218
+ const double dt = 0.015 ;
219
+ const double Kp = 0.0 ;
220
+ const double large_Kd = 1.0e8 ;
221
+ const double effort_limit = 0.3 ;
222
+ const Parameters p{Kp, large_Kd, effort_limit};
223
+ // The configuration is irrelevant for this test.
224
+ const Configuration k = MakeArbitraryConfiguration ();
225
+ const SapPdControllerConstraint<double > c (k, p);
226
+ // Arbitrary value for the Delassus operator.
227
+ const VectorXd w = Vector1d::Constant (1.6 );
228
+
229
+ const double Rnr = kBeta * kBeta / (4.0 * M_PI * M_PI) * w (0 );
230
+ // Expected near-rigid parameters. The user wants velocity control, and we
231
+ // should respect that.
232
+ const double Kd_nr = 1.0 / (dt * Rnr);
233
+
234
+ // Verify that gains were clamped to be in the near-rigid regime.
235
+ auto abstract_data = c.MakeData (dt, w);
236
+ const auto & data =
237
+ abstract_data->get_value <SapPdControllerConstraintData<double >>();
238
+ EXPECT_EQ (data.Kp_eff (), 0.0 );
205
239
EXPECT_NEAR (data.Kd_eff (), Kd_nr, kEps );
206
240
EXPECT_EQ (data.time_step (), dt); // not affected.
207
241
}
208
242
243
+ // Verify the effective gains within the near-rigid regime when the user sets
244
+ // the derivative gain Kd to zero. In particular, the effective derivate gain
245
+ // should remain zero to respect the user's desire to do position control only.
246
+ GTEST_TEST (SapPdControllerConstraint, MakeDataNearRigidRegimeWithZeroKd) {
247
+ // This value of near-rigid parameter is the one internally used by
248
+ // SapPdControllerConstraint and they must remain in sync.
249
+ constexpr double kBeta = 0.1 ;
250
+
251
+ const double dt = 0.015 ;
252
+ const double large_Kp = 1e8 ;
253
+ const double Kd = 0.0 ;
254
+ const double effort_limit = 0.3 ;
255
+ const Parameters p{large_Kp, Kd, effort_limit};
256
+ // The configuration is irrelevant for this test.
257
+ const Configuration k = MakeArbitraryConfiguration ();
258
+ const SapPdControllerConstraint<double > c (k, p);
259
+ // Arbitrary value for the Delassus operator.
260
+ const VectorXd w = Vector1d::Constant (1.6 );
261
+
262
+ const double Rnr = kBeta * kBeta / (4.0 * M_PI * M_PI) * w (0 );
263
+ // Expected near-rigid parameters. The user wants position control, and we
264
+ // should respect that.
265
+ const double Kp_nr = 1.0 / (dt * dt * Rnr);
266
+
267
+ // Verify that gains were clamped to be in the near-rigid regime.
268
+ auto abstract_data = c.MakeData (dt, w);
269
+ const auto & data =
270
+ abstract_data->get_value <SapPdControllerConstraintData<double >>();
271
+ EXPECT_NEAR (data.Kp_eff (), Kp_nr, kEps );
272
+ EXPECT_EQ (data.Kd_eff (), 0.0 );
273
+ EXPECT_EQ (data.time_step (), dt); // not affected.
274
+ }
275
+
209
276
// This method validates analytical gradients implemented by
210
277
// SapPdControllerConstraint using automatic differentiation.
211
278
void ValidateGradients (double v) {
0 commit comments