@@ -586,6 +586,72 @@ TEST_F(PidControllerTest, test_update_chained_feedforward_with_gain)
586
586
ASSERT_EQ (controller_->command_interfaces_ [0 ].get_value (), exepected_command_value);
587
587
}
588
588
589
+ /* *
590
+ * @brief check chained pid controller with feedforward OFF and gain as non-zero, single interface
591
+ */
592
+ TEST_F (PidControllerTest, test_update_chained_feedforward_off_with_gain)
593
+ {
594
+ // state interface value is 1.1 as defined in test fixture
595
+ // given target value 5.0
596
+ // with p gain 0.5, the command value should be 0.5 * (5.0 - 1.1) = 1.95
597
+ // with feedforward off, the command value should be still 1.95 even though feedforward gain
598
+ // is 1.0
599
+ auto target_value = 5.0 ;
600
+ auto exepected_command_value = 1.95 ;
601
+
602
+ SetUpController (" test_pid_controller_with_feedforward_gain" );
603
+ ASSERT_EQ (controller_->on_configure (rclcpp_lifecycle::State ()), NODE_SUCCESS);
604
+
605
+ // check on interfaces & pid gain parameters
606
+ for (const auto & dof_name : dof_names_)
607
+ {
608
+ ASSERT_EQ (controller_->params_ .gains .dof_names_map [dof_name].p , 0.5 );
609
+ ASSERT_EQ (controller_->params_ .gains .dof_names_map [dof_name].feedforward_gain , 1.0 );
610
+ }
611
+ ASSERT_EQ (controller_->params_ .command_interface , command_interface_);
612
+ EXPECT_THAT (
613
+ controller_->params_ .reference_and_state_interfaces ,
614
+ testing::ElementsAreArray (state_interfaces_));
615
+ ASSERT_FALSE (controller_->params_ .use_external_measured_states );
616
+
617
+ // setup executor
618
+ rclcpp::executors::MultiThreadedExecutor executor;
619
+ executor.add_node (controller_->get_node ()->get_node_base_interface ());
620
+ executor.add_node (service_caller_node_->get_node_base_interface ());
621
+
622
+ controller_->set_chained_mode (true );
623
+
624
+ // activate controller
625
+ ASSERT_EQ (controller_->on_activate (rclcpp_lifecycle::State ()), NODE_SUCCESS);
626
+ ASSERT_TRUE (controller_->is_in_chained_mode ());
627
+
628
+ // feedforward by default is OFF
629
+ ASSERT_EQ (*(controller_->control_mode_ .readFromRT ()), feedforward_mode_type::OFF);
630
+
631
+ // send a message to update reference interface
632
+ std::shared_ptr<ControllerCommandMsg> msg = std::make_shared<ControllerCommandMsg>();
633
+ msg->dof_names = controller_->params_ .dof_names ;
634
+ msg->values .resize (msg->dof_names .size (), 0.0 );
635
+ for (size_t i = 0 ; i < msg->dof_names .size (); ++i)
636
+ {
637
+ msg->values [i] = target_value;
638
+ }
639
+ msg->values_dot .resize (msg->dof_names .size (), std::numeric_limits<double >::quiet_NaN ());
640
+ controller_->input_ref_ .writeFromNonRT (msg);
641
+ ASSERT_EQ (
642
+ controller_->update_reference_from_subscribers (
643
+ rclcpp::Time (0 ), rclcpp::Duration::from_seconds (0.01 )),
644
+ controller_interface::return_type::OK);
645
+
646
+ // run update
647
+ ASSERT_EQ (
648
+ controller_->update (rclcpp::Time (0 ), rclcpp::Duration::from_seconds (0.01 )),
649
+ controller_interface::return_type::OK);
650
+
651
+ // check on result from update
652
+ ASSERT_EQ (controller_->command_interfaces_ [0 ].get_value (), exepected_command_value);
653
+ }
654
+
589
655
int main (int argc, char ** argv)
590
656
{
591
657
::testing::InitGoogleTest (&argc, argv);
0 commit comments