102 void initialize(
const rclcpp::Node::SharedPtr& node)
override
105 if (!
node_->has_parameter(makeParameterName(PARAM_BASE_NAME,
"controller_names")))
107 RCLCPP_ERROR_STREAM(getLogger(),
"No controller_names specified.");
110 rclcpp::Parameter controller_names_param;
111 node_->get_parameter(makeParameterName(PARAM_BASE_NAME,
"controller_names"), controller_names_param);
112 if (controller_names_param.get_type() != rclcpp::ParameterType::PARAMETER_STRING_ARRAY)
114 RCLCPP_ERROR(getLogger(),
"Parameter controller_names should be specified as a string array");
117 std::vector<std::string> controller_names = controller_names_param.as_string_array();
119 for (
const std::string& controller_name : controller_names)
123 std::string action_ns;
124 const std::string& action_ns_param = makeParameterName(PARAM_BASE_NAME, controller_name,
"action_ns");
125 if (!
node_->get_parameter(action_ns_param, action_ns))
127 RCLCPP_ERROR_STREAM(getLogger(),
"No action namespace specified for controller `"
128 << controller_name <<
"` through parameter `" << action_ns_param <<
'`');
133 if (!
node_->get_parameter(makeParameterName(PARAM_BASE_NAME, controller_name,
"type"), type))
135 RCLCPP_ERROR_STREAM(getLogger(),
"No type specified for controller " << controller_name);
139 std::vector<std::string> controller_joints;
140 if (!
node_->get_parameter(makeParameterName(PARAM_BASE_NAME, controller_name,
"joints"), controller_joints) ||
141 controller_joints.empty())
143 RCLCPP_ERROR_STREAM(getLogger(),
"No joints specified for controller " << controller_name);
147 ActionBasedControllerHandleBasePtr new_handle;
148 if (type ==
"GripperCommand")
151 node_->get_parameter_or(makeParameterName(PARAM_BASE_NAME, controller_name,
"max_effort"), max_effort, 0.0);
152 RCLCPP_INFO_STREAM(getLogger(), controller_name <<
" will command a max effort of: " << max_effort);
154 new_handle = std::make_shared<GripperCommandControllerHandle>(
node_, controller_name, action_ns, max_effort);
155 bool parallel_gripper =
false;
156 if (
node_->get_parameter(makeParameterName(PARAM_BASE_NAME, controller_name,
"parallel"), parallel_gripper) &&
159 if (controller_joints.size() != 2)
161 RCLCPP_ERROR_STREAM(getLogger(),
"Parallel Gripper requires exactly two joints, "
162 << controller_joints.size() <<
" are specified");
166 ->setParallelJawGripper(controller_joints[0], controller_joints[1]);
170 std::string command_joint;
171 node_->get_parameter_or(makeParameterName(PARAM_BASE_NAME, controller_name,
"command_joint"), command_joint,
172 controller_joints[0]);
178 node_->get_parameter_or(makeParameterName(PARAM_BASE_NAME, controller_name,
"allow_failure"), allow_failure,
182 RCLCPP_INFO_STREAM(getLogger(),
"Added GripperCommand controller for " << controller_name);
185 else if (type ==
"ParallelGripperCommand")
188 node_->get_parameter_or(makeParameterName(PARAM_BASE_NAME, controller_name,
"max_effort"), max_effort, 0.0);
189 if (max_effort > 0.0)
191 RCLCPP_INFO_STREAM(getLogger(), controller_name <<
" will command a max effort of: " << max_effort);
195 node_->get_parameter_or(makeParameterName(PARAM_BASE_NAME, controller_name,
"max_velocity"), max_velocity,
197 if (max_effort > 0.0)
199 RCLCPP_INFO_STREAM(getLogger(), controller_name <<
" will command a max velocity of: " << max_velocity);
202 new_handle = std::make_shared<ParallelGripperCommandControllerHandle>(
node_, controller_name, action_ns,
203 max_effort, max_velocity);
205 if (controller_joints.size() > 1)
207 RCLCPP_WARN_STREAM(getLogger(),
"ParallelGripperCommand controller only supports commanding a single joint "
208 "and multiple joint names were specified. Assuming control of joint: "
209 << controller_joints[0]);
213 RCLCPP_INFO_STREAM(getLogger(),
"Added ParallelGripperCommand controller for " << controller_name);
216 else if (type ==
"FollowJointTrajectory")
218 new_handle = std::make_shared<FollowJointTrajectoryControllerHandle>(
node_, controller_name, action_ns);
219 RCLCPP_INFO_STREAM(getLogger(),
"Added FollowJointTrajectory controller for " << controller_name);
224 RCLCPP_ERROR_STREAM(getLogger(),
"Unknown controller type: " << type);
234 node_->get_parameter_or(makeParameterName(PARAM_BASE_NAME, controller_name,
"default"), state.
default_,
false);
240 for (
const std::string& controller_joint : controller_joints)
241 new_handle->addJoint(controller_joint);
245 RCLCPP_ERROR_STREAM(getLogger(),
"Caught unknown exception while parsing controller information");