Skip to content

Commit

Permalink
Async params (ros-controls#927)
Browse files Browse the repository at this point in the history
* add is_async param to controller manager

* handle is_async param for hw components

* Remove std::terminate() call used for debugging

* Remove whitespace

* Remove empty line

* use strcasecmp
  • Loading branch information
VX792 authored Feb 2, 2023
1 parent 17d5ca0 commit c1b1865
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class ControllerInterfaceBase : public rclcpp_lifecycle::node_interfaces::Lifecy
CONTROLLER_INTERFACE_PUBLIC
unsigned int get_update_rate() const;

CONTROLLER_INTERFACE_PUBLIC
bool is_async() const;

/// Declare and initialize a parameter with a type.
/**
*
Expand Down Expand Up @@ -220,6 +223,7 @@ class ControllerInterfaceBase : public rclcpp_lifecycle::node_interfaces::Lifecy
std::vector<hardware_interface::LoanedCommandInterface> command_interfaces_;
std::vector<hardware_interface::LoanedStateInterface> state_interfaces_;
unsigned int update_rate_ = 0;
bool is_async_ = false;

private:
std::shared_ptr<rclcpp_lifecycle::LifecycleNode> node_;
Expand Down
2 changes: 2 additions & 0 deletions controller_interface/src/controller_interface_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ return_type ControllerInterfaceBase::init(
try
{
auto_declare<int>("update_rate", 0);
auto_declare<bool>("is_async", false);
}
catch (const std::exception & e)
{
Expand Down Expand Up @@ -84,6 +85,7 @@ const rclcpp_lifecycle::State & ControllerInterfaceBase::configure()
if (get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED)
{
update_rate_ = get_node()->get_parameter("update_rate").as_int();
is_async_ = get_node()->get_parameter("is_async").as_bool();
}

return get_node()->configure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ struct HardwareComponentInfo
/// Component pluginlib plugin name.
std::string plugin_name;

/// Component is async
bool is_async;

/// Component current state.
rclcpp_lifecycle::State state;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct ComponentInfo
std::string name;
/// Type of the component: sensor, joint, or GPIO.
std::string type;

/**
* Name of the command interfaces that can be set, e.g. "position", "velocity", etc.
* Used by joints and GPIOs.
Expand Down Expand Up @@ -106,6 +107,8 @@ struct HardwareInfo
std::string name;
/// Type of the hardware: actuator, sensor or system.
std::string type;
/// Component is async
bool is_async;
/// Name of the pluginlib plugin of the hardware that will be loaded.
std::string hardware_plugin_name;
/// (Optional) Key-value pairs for hardware parameters.
Expand Down
17 changes: 17 additions & 0 deletions hardware_interface/src/component_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ constexpr const auto kTypeAttribute = "type";
constexpr const auto kRoleAttribute = "role";
constexpr const auto kReductionAttribute = "mechanical_reduction";
constexpr const auto kOffsetAttribute = "offset";
constexpr const auto kIsAsyncAttribute = "is_async";

} // namespace

namespace hardware_interface
Expand Down Expand Up @@ -211,6 +213,20 @@ std::string parse_data_type_attribute(const tinyxml2::XMLElement * elem)
return data_type;
}

/// Parse is_async attribute
/**