@@ -582,6 +582,14 @@ class HardwareComponentInterface : public rclcpp_lifecycle::node_interfaces::Lif
582
582
lifecycle_state_ = new_state;
583
583
}
584
584
585
+ // / Set the value of a state interface.
586
+ /* *
587
+ * \tparam T The type of the value to be stored.
588
+ * \param[in] interface_name The name of the state interface to access.
589
+ * \param[in] value The value to store.
590
+ * \throws std::runtime_error This method throws a runtime error if it cannot
591
+ * access the state interface.
592
+ */
585
593
template <typename T>
586
594
void set_state (const std::string & interface_name, const T & value)
587
595
{
@@ -600,6 +608,14 @@ class HardwareComponentInterface : public rclcpp_lifecycle::node_interfaces::Lif
600
608
std::ignore = handle->set_value (lock, value);
601
609
}
602
610
611
+ // / Get the value from a state interface.
612
+ /* *
613
+ * \tparam T The type of the value to be retrieved.
614
+ * \param[in] interface_name The name of the state interface to access.
615
+ * \return The value obtained from the interface.
616
+ * \throws std::runtime_error This method throws a runtime error if it cannot
617
+ * access the state interface or its stored value.
618
+ */
603
619
template <typename T = double >
604
620
T get_state (const std::string & interface_name) const
605
621
{
@@ -626,6 +642,15 @@ class HardwareComponentInterface : public rclcpp_lifecycle::node_interfaces::Lif
626
642
return opt_value.value ();
627
643
}
628
644
645
+ // / Set the value of a command interface.
646
+ /* *
647
+ * \tparam T The type of the value to be stored.
648
+ * \param interface_name The name of the command
649
+ * interface to access.
650
+ * \param value The value to store.
651
+ * \throws This method throws a runtime error if it
652
+ * cannot access the command interface.
653
+ */
629
654
template <typename T>
630
655
void set_command (const std::string & interface_name, const T & value)
631
656
{
@@ -644,6 +669,14 @@ class HardwareComponentInterface : public rclcpp_lifecycle::node_interfaces::Lif
644
669
std::ignore = handle->set_value (lock, value);
645
670
}
646
671
672
+ // / Get the value from a command interface.
673
+ /* *
674
+ * \tparam T The type of the value to be retrieved.
675
+ * \param[in] interface_name The name of the command interface to access.
676
+ * \return The value obtained from the interface.
677
+ * \throws std::runtime_error This method throws a runtime error if it cannot
678
+ * access the command interface or its stored value.
679
+ */
647
680
template <typename T = double >
648
681
T get_command (const std::string & interface_name) const
649
682
{
@@ -659,7 +692,7 @@ class HardwareComponentInterface : public rclcpp_lifecycle::node_interfaces::Lif
659
692
}
660
693
auto & handle = it->second ;
661
694
std::shared_lock<std::shared_mutex> lock (handle->get_mutex ());
662
- const auto opt_value = handle->get_optional <double >(lock);
695
+ const auto opt_value = handle->get_optional <T >(lock);
663
696
if (!opt_value)
664
697
{
665
698
throw std::runtime_error (
0 commit comments