38 std::vector<std::string> robots;
39 std::string param_name =
"robot_hardware";
40 if (!robot_hw_nh.
getParam(param_name, robots))
46 for (
const auto& robot : robots)
57 const std::list<hardware_interface::ControllerInfo>& stop_list)
62 std::list<hardware_interface::ControllerInfo> filtered_start_list;
63 std::list<hardware_interface::ControllerInfo> filtered_stop_list;
69 if (!robot_hw->prepareSwitch(filtered_start_list, filtered_stop_list))
76 const std::list<hardware_interface::ControllerInfo>& stop_list)
81 std::list<hardware_interface::ControllerInfo> filtered_start_list;
82 std::list<hardware_interface::ControllerInfo> filtered_stop_list;
88 robot_hw->doSwitch(filtered_start_list, filtered_stop_list);
94 ROS_DEBUG(
"Will load robot HW '%s'", name.c_str());
102 catch(std::exception &e)
104 ROS_ERROR(
"Exception thrown while constructing nodehandle for robot HW with name '%s':\n%s", name.c_str(), e.what());
109 ROS_ERROR(
"Exception thrown while constructing nodehandle for robot HW with name '%s'", name.c_str());
117 ROS_DEBUG(
"Constructing robot HW '%s' of type '%s'", name.c_str(), type.c_str());
122 if (type == cur_type)
128 catch (
const std::runtime_error &ex)
130 ROS_ERROR(
"Could not load class %s: %s", type.c_str(), ex.what());
135 ROS_ERROR(
"Could not load robot HW '%s' because the type was not specified. Did you load the robot HW configuration on the parameter server (namespace: '%s')?", name.c_str(), c_nh.
getNamespace().c_str());
142 ROS_ERROR(
"Could not load robot HW '%s' because robot HW type '%s' does not exist.", name.c_str(), type.c_str());
147 ROS_DEBUG(
"Initializing robot HW '%s'", name.c_str());
151 initialized = robot_hw->init(
root_nh_, c_nh);
153 catch(std::exception &e)
155 ROS_ERROR(
"Exception thrown while initializing robot HW %s.\n%s", name.c_str(), e.what());
160 ROS_ERROR(
"Exception thrown while initializing robot HW %s", name.c_str());
166 ROS_ERROR(
"Initializing robot HW '%s' failed", name.c_str());
169 ROS_DEBUG(
"Initialized robot HW '%s' successful", name.c_str());
175 ROS_DEBUG(
"Successfully load robot HW '%s'", name.c_str());
184 robot_hw->read(time, period);
194 robot_hw->write(time, period);
199 std::list<hardware_interface::ControllerInfo>& filtered_list,
202 filtered_list.clear();
203 for (
const auto& controller : list)
206 filtered_controller.
name = controller.name;
207 filtered_controller.
type = controller.type;
209 if (controller.claimed_resources.empty())
211 filtered_list.push_back(filtered_controller);
214 for (
const auto& claimed_resource : controller.claimed_resources)
218 std::vector<std::string> r_hw_ifaces = robot_hw->getNames();
220 auto const if_name = std::find(r_hw_ifaces.begin(), r_hw_ifaces.end(), filtered_iface_resources.
hardware_interface);
221 if (if_name == r_hw_ifaces.end())
226 std::vector<std::string> r_hw_iface_resources = robot_hw->getInterfaceResources(filtered_iface_resources.
hardware_interface);
227 std::set<std::string> filtered_resources;
228 for (
const auto& resource : claimed_resource.resources)
230 std::vector<std::string>::iterator res_name = std::find(r_hw_iface_resources.begin(), r_hw_iface_resources.end(), resource);
231 if (res_name != r_hw_iface_resources.end())
233 filtered_resources.insert(resource);
236 if (!filtered_resources.empty())
238 filtered_iface_resources.
resources = filtered_resources;
244 filtered_list.push_back(filtered_controller);