25 #include "yaml-cpp/yaml.h"
26 #include "yaml-cpp/exceptions.h"
31 std::string hand_config_path,
33 detected_hands_file_(detected_hands_file),
34 forced_hand_side_(forced_hand_side)
36 if (hand_config_path.empty())
55 throw std::runtime_error(
"sr_hand_autodetect: Did not find sr_hand_config package.");
73 std::string path_to_info_file =
sr_hand_config_path_ +
"/" + std::to_string(serial) +
"/general_info.yaml";
76 return YAML::LoadFile(path_to_info_file);
80 std::cerr <<
"sr_hand_autodetect: General info for detected hand does not exist!";
88 for (YAML::const_iterator it = config.begin(); it != config.end(); ++it)
99 std::string side_to_remove_string;
103 side_to_remove_string =
"left";
107 side_to_remove_string =
"right";
111 throw std::runtime_error(
"sr_hand_autodetect: Unknown side to be forced");
117 if (side_to_remove_string == detected_hand_side)
135 std::cout <<
"No hands detected. Not wrapping the roslaunch command!" << std::endl;
148 throw std::runtime_error(
"sr_hand_autodetect: Unsupported number of hands detected in the system");
159 " hand_serial:=" + std::to_string(hand_serial) +
160 " side:=" + hand_info[
"side"].as<std::string>() +
161 " hand_type:=" + hand_info[
"type"].as<std::string>() +
162 " hand_version:=" + hand_info[
"version"].as<std::string>() +
169 if (hand_info[
"mapping_path"])
172 [
"package_name"].as<std::string>()) +
173 "/" + hand_info[
"mapping_path"] \
174 [
"relative_path"].as<std::string>();
181 int rh_serial, lh_serial;
182 std::string rh_eth_port, lh_eth_port, rh_command_component, lh_command_component, mapping_path_suffix_component;
188 std::string hand_side = hand_info[
"side"].as<std::string>();
189 if (
"right" == hand_side)
191 rh_serial = serial_to_port.first;
192 rh_eth_port = serial_to_port.second;
195 else if (
"left" == hand_side)
197 lh_serial = serial_to_port.first;
198 lh_eth_port = serial_to_port.second;
203 throw std::runtime_error(
"sr_hand_autodetect: Unsupported hand id");
207 command_suffix_ +=
" eth_port:=" + rh_eth_port +
"_" + lh_eth_port +
" rh_serial:=" +
208 std::to_string(rh_serial) +
" lh_serial:=" + std::to_string(lh_serial) +
209 rh_command_component + lh_command_component + mapping_path_suffix_component;
215 std::string mapping_path_suffix_component;
216 std::string side = hand_info[
"side"].as<std::string>();
218 if (hand_info[
"mapping_path"])
221 [
"package_name"].as<std::string>()) +
222 "/" + hand_info[
"mapping_path"] \
223 [
"relative_path"].as<std::string>();
224 mapping_path_suffix_component +=
" " +
hand_side_to_prefix(side) +
"_mapping_path:=" + mapping_path;
227 return " " + side +
"_hand_type:=" + hand_info[
"type"].as<std::string>() +
228 " " + side +
"_hand_version:=" + hand_info[
"version"].as<std::string>() +
234 mapping_path_suffix_component;
243 else if (
"left" == side)
248 throw std::runtime_error(
"Unknown hand type!");
253 if (vec.size() == 0)
return "none";
257 for (
auto it = vec.begin(); it != vec.end(); ++it)
260 if (it != std::prev(vec.end())) result +=
",";
268 if (m.size() == 0)
return "none";
272 for (
auto it = m.begin(); it != m.end(); it++)
274 result += (it->first +
"=" + it->second);
275 if (it != std::prev(m.end())) result +=
",";
283 std::vector<std::string> result;
285 for (std::size_t i = 0; i < node_list.size(); ++i)
287 result.push_back(node_list[i].as<std::string>());
295 std::map<std::string, std::string> result;
297 for (
auto it=node_map.begin(); it != node_map.end(); ++it)
299 result.insert(std::pair<std::string, std::string>(it->first.as<std::string>(), it->second.as<std::string>()));