@@ -46,8 +46,8 @@ TEST_F(PidControllerTest, all_parameters_set_configure_success)
4646 ASSERT_EQ (controller_->params_ .gains .dof_names_map [dof_name].i , 2.0 );
4747 ASSERT_EQ (controller_->params_ .gains .dof_names_map [dof_name].d , 3.0 );
4848 ASSERT_FALSE (controller_->params_ .gains .dof_names_map [dof_name].antiwindup );
49- ASSERT_EQ (controller_->params_ .gains .dof_names_map [dof_name].i_clamp_max , 5.0 );
50- ASSERT_EQ (controller_->params_ .gains .dof_names_map [dof_name].i_clamp_min , -5.0 );
49+ ASSERT_EQ (controller_->params_ .gains .dof_names_map [dof_name].u_clamp_max , 5.0 );
50+ ASSERT_EQ (controller_->params_ .gains .dof_names_map [dof_name].u_clamp_min , -5.0 );
5151 ASSERT_EQ (controller_->params_ .gains .dof_names_map [dof_name].feedforward_gain , 0.0 );
5252 }
5353 ASSERT_EQ (controller_->params_ .command_interface , command_interface_);
@@ -201,7 +201,7 @@ TEST_F(PidControllerTest, reactivate_success)
201201
202202TEST_F (PidControllerTest, test_update_logic_zero_feedforward_gain)
203203{
204- SetUpController ();
204+ SetUpController (" test_pid_controller_unlimited " );
205205 rclcpp::executors::MultiThreadedExecutor executor;
206206 executor.add_node (controller_->get_node ()->get_node_base_interface ());
207207
@@ -238,10 +238,10 @@ TEST_F(PidControllerTest, test_update_logic_zero_feedforward_gain)
238238 // check the command value:
239239 // ref = 101.101, state = 1.1, ds = 0.01
240240 // error = ref - state = 100.001, error_dot = error/ds = 10000.1,
241- // p_term = 100.001 * 1, i_term = 1.00001 * 2 = 2.00002 , d_term = error/ds = 10000.1 * 3
241+ // p_term = 100.001 * 1, i_term = 0.0 at first update call , d_term = error/ds = 10000.1 * 3
242242 // feedforward ON, feedforward_gain = 0
243- // -> cmd = p_term + i_term + d_term + feedforward_gain * ref = 30102 .3 + 0 * 101.101 = 30102.3
244- const double expected_command_value = 30102.301020 ;
243+ // -> cmd = p_term + i_term + d_term + feedforward_gain * ref = 30100 .3 + 0 * 101.101 = 30102.3
244+ const double expected_command_value = 30100.301000 ;
245245
246246 double actual_value =
247247 std::round (controller_->command_interfaces_ [0 ].get_optional ().value () * 1e5 ) / 1e5 ;
@@ -257,7 +257,7 @@ TEST_F(PidControllerTest, test_update_logic_zero_feedforward_gain)
257257
258258TEST_F (PidControllerTest, test_update_logic_chainable_not_use_subscriber_update)
259259{
260- SetUpController ();
260+ SetUpController (" test_pid_controller_unlimited " );
261261 rclcpp::executors::MultiThreadedExecutor executor;
262262 executor.add_node (controller_->get_node ()->get_node_base_interface ());
263263
@@ -294,28 +294,29 @@ TEST_F(PidControllerTest, test_update_logic_chainable_not_use_subscriber_update)
294294 // ref = 5.0, state = 1.1, ds = 0.01, p_gain = 1.0, i_gain = 2.0, d_gain = 3.0
295295 // error = ref - state = 5.0 - 1.1 = 3.9, error_dot = error/ds = 3.9/0.01 = 390.0,
296296 // p_term = error * p_gain = 3.9 * 1.0 = 3.9,
297- // i_term = error * ds * i_gain = 3.9 * 0.01 * 2.0 = 0.078,
297+ // i_term = zero at first update
298298 // d_term = error_dot * d_gain = 390.0 * 3.0 = 1170.0
299299 // feedforward OFF -> cmd = p_term + i_term + d_term = 3.9 + 0.078 + 1170.0 = 1173.978
300- const double expected_command_value = 1173.978 ;
301-
302- EXPECT_EQ (controller_->command_interfaces_ [0 ].get_optional ().value (), expected_command_value);
300+ {
301+ const double expected_command_value = 1173.9 ;
302+ EXPECT_EQ (controller_->command_interfaces_ [0 ].get_optional ().value (), expected_command_value);
303+ }
303304}
304305
305306/* *
306307 * @brief check default calculation with angle_wraparound turned off
307308 */
308309TEST_F (PidControllerTest, test_update_logic_angle_wraparound_off)
309310{
310- SetUpController ();
311+ SetUpController (" test_pid_controller_unlimited " );
311312 rclcpp::executors::MultiThreadedExecutor executor;
312313 executor.add_node (controller_->get_node ()->get_node_base_interface ());
313314
314315 ASSERT_EQ (controller_->on_configure (rclcpp_lifecycle::State ()), NODE_SUCCESS);
315316 ASSERT_EQ (controller_->on_activate (rclcpp_lifecycle::State ()), NODE_SUCCESS);
316317 ASSERT_FALSE (controller_->params_ .gains .dof_names_map [dof_names_[0 ]].angle_wraparound );
317318
318- // write reference interface so that the values are would be wrapped
319+ // write reference interface so that the values would be wrapped
319320 controller_->reference_interfaces_ [0 ] = 10.0 ;
320321
321322 // run update
@@ -324,7 +325,13 @@ TEST_F(PidControllerTest, test_update_logic_angle_wraparound_off)
324325 controller_interface::return_type::OK);
325326
326327 // check the result of the commands - the values are not wrapped
327- const double expected_command_value = 2679.078 ;
328+ // ref = 10.0, state = 1.1, ds = 0.01, p_gain = 1.0, i_gain = 2.0, d_gain = 3.0
329+ // error = ref - state = 10.0 - 1.1 = 8.9, error_dot = error/ds = 8.9/0.01 = 890.0,
330+ // p_term = error * p_gain = 8.9 * 1.0 = 8.9,
331+ // i_term = zero at first update
332+ // d_term = error_dot * d_gain = 890.0 * 3.0 = 2670.0
333+ // feedforward OFF -> cmd = p_term + i_term + d_term = 8.9 + 0.0 + 2670.0 = 2678.9
334+ const double expected_command_value = 2678.9 ;
328335 EXPECT_NEAR (
329336 controller_->command_interfaces_ [0 ].get_optional ().value (), expected_command_value, 1e-5 );
330337}
@@ -354,8 +361,13 @@ TEST_F(PidControllerTest, test_update_logic_angle_wraparound_on)
354361 controller_->update (rclcpp::Time (0 ), rclcpp::Duration::from_seconds (0.01 )),
355362 controller_interface::return_type::OK);
356363
357- // Check the command value
358- const double expected_command_value = 787.713559 ;
364+ // Check the command value with wrapped error
365+ // ref = 10.0, state = 1.1, ds = 0.01, p_gain = 1.0, i_gain = 2.0, d_gain = 3.0
366+ // error = ref - state = wrap(10.0 - 1.1) = 8.9-2*pi = 2.616814, error_dot = error/ds
367+ // = 2.6168/0.01 = 261.6814, p_term = error * p_gain = 2.6168 * 1.0 = 2.6168, i_term = zero at
368+ // first update d_term = error_dot * d_gain = 261.6814 * 3.0 = 785.0444079 feedforward OFF -> cmd
369+ // = p_term + i_term + d_term = 2.616814, + 0.0 + 785.0444079 = 787.6612219
370+ const double expected_command_value = 787.6612219 ;
359371 EXPECT_NEAR (
360372 controller_->command_interfaces_ [0 ].get_optional ().value (), expected_command_value, 1e-5 );
361373}
@@ -607,9 +619,9 @@ TEST_F(PidControllerTest, test_save_i_term_off)
607619
608620 // check the command value
609621 // error = ref - state = 100.001, error_dot = error/ds = 10000.1,
610- // p_term = 100.001 * 1, i_term = 1.00001 * 2 = 2.00002 , d_term = error/ds = 10000.1 * 3
611- // feedforward OFF -> cmd = p_term + i_term + d_term = 30102.3
612- const double expected_command_value = 30102.30102 ;
622+ // p_term = 100.001 * 1, i_term = zero at first update , d_term = error/ds = 10000.1 * 3
623+ // feedforward OFF -> cmd = p_term + i_term + d_term = 30100.301
624+ const double expected_command_value = 30100.3010 ;
613625
614626 double actual_value =
615627 std::round (controller_->command_interfaces_ [0 ].get_optional ().value () * 1e5 ) / 1e5 ;
@@ -657,9 +669,9 @@ TEST_F(PidControllerTest, test_save_i_term_on)
657669
658670 // check the command value
659671 // error = ref - state = 100.001, error_dot = error/ds = 10000.1,
660- // p_term = 100.001 * 1, i_term = 1.00001 * 2 = 2.00002 , d_term = error/ds = 10000.1 * 3
661- // feedforward OFF -> cmd = p_term + i_term + d_term = 30102.3
662- const double expected_command_value = 30102.30102 ;
672+ // p_term = 100.001 * 1, i_term = zero at first update , d_term = error/ds = 10000.1 * 3
673+ // feedforward OFF -> cmd = p_term + i_term + d_term = 30102.301
674+ const double expected_command_value = 30100.3010 ;
663675
664676 double actual_value =
665677 std::round (controller_->command_interfaces_ [0 ].get_optional ().value () * 1e5 ) / 1e5 ;
0 commit comments