|
| 1 | +// Copyright 2020 ros2_control Development Team |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef HARDWARE_INTERFACE__COMPONENT_PARSER_HPP_ |
| 16 | +#define HARDWARE_INTERFACE__COMPONENT_PARSER_HPP_ |
| 17 | + |
| 18 | +#include <tinyxml2.h> |
| 19 | +#include <string> |
| 20 | +#include <unordered_map> |
| 21 | +#include <vector> |
| 22 | + |
| 23 | +#include "hardware_interface/components/component_info.hpp" |
| 24 | +#include "hardware_interface/hardware_info.hpp" |
| 25 | +#include "hardware_interface/visibility_control.h" |
| 26 | + |
| 27 | +namespace hardware_interface |
| 28 | +{ |
| 29 | + |
| 30 | +/** |
| 31 | + * \brief Search XML snippet from URDF for information about a control component. |
| 32 | + * |
| 33 | + * \param urdf string with robot's URDF |
| 34 | + * \return vector filled with information about robot's control resources |
| 35 | + * \throws std::runtime_error if a robot attribute or tag is not found |
| 36 | + */ |
| 37 | +HARDWARE_INTERFACE_PUBLIC |
| 38 | +std::vector<HardwareInfo> parse_control_resources_from_urdf(const std::string & urdf); |
| 39 | + |
| 40 | +/** |
| 41 | + * \brief Parse a control resource from an "ros2_control" tag. |
| 42 | + * |
| 43 | + * \param ros2_control_it pointer to ros2_control element with informtions about resource. |
| 44 | + * \return robot_control_components::ComponentInfo filled with information about the robot |
| 45 | + * \throws std::runtime_error if a attributes or tag are not found |
| 46 | + */ |
| 47 | +HARDWARE_INTERFACE_PUBLIC |
| 48 | +HardwareInfo parse_resource_from_xml(const tinyxml2::XMLElement * ros2_control_it); |
| 49 | + |
| 50 | +/** |
| 51 | + * \brief Gets value of the attribute on an XMLelement. |
| 52 | + * If attribute is not found throws an error. |
| 53 | + * |
| 54 | + * \param element_it XMLElement iterator to search for the attribute |
| 55 | + * \param attribute_name atribute name to serach for and return value |
| 56 | + * \param tag_name parent tag name where attribute is searched for (used for error output) |
| 57 | + * \return attribute value |
| 58 | + * \throws std::runtime_error if attribute is not found |
| 59 | + */ |
| 60 | +HARDWARE_INTERFACE_PUBLIC |
| 61 | +std::string get_attribute_value( |
| 62 | + const tinyxml2::XMLElement * element_it, |
| 63 | + const char * attribute_name, const char * tag_name); |
| 64 | + |
| 65 | +/** |
| 66 | + * \brief Gets value of the text between tags. |
| 67 | + * |
| 68 | + * \param element_it XMLElement iterator to search for the text. |
| 69 | + * \param tag_name parent tag name where text is searched for (used for error output) |
| 70 | + * \return text of for the tag |
| 71 | + * \throws std::runtime_error if text is not found |
| 72 | + */ |
| 73 | +HARDWARE_INTERFACE_PUBLIC |
| 74 | +std::string get_text_for_element( |
| 75 | + const tinyxml2::XMLElement * element_it, |
| 76 | + const std::string & tag_name); |
| 77 | + |
| 78 | +/** |
| 79 | + * \brief Gets value of the attribute on an XMLelement. |
| 80 | + * If attribute is not found throws an error. |
| 81 | + * |
| 82 | + * \param element_it XMLElement iterator to search for the attribute |
| 83 | + * \param attribute_name atribute name to serach for and return value |
| 84 | + * \param tag_name parent tag name where attribute is searched for (used for error output) |
| 85 | + * \return attribute value |
| 86 | + * \throws std::runtime_error if attribute is not found |
| 87 | + */ |
| 88 | +HARDWARE_INTERFACE_PUBLIC |
| 89 | +std::string get_attribute_value( |
| 90 | + const tinyxml2::XMLElement * element_it, |
| 91 | + const char * attribute_name, std::string tag_name); |
| 92 | + |
| 93 | +/** |
| 94 | + * \brief Search XML snippet from URDF for information about a control component. |
| 95 | + * |
| 96 | + * \param component_it pointer to the iterator where component info should be found |
| 97 | + * \return robot_control_components::ComponentInfo filled with information about component |
| 98 | + * \throws std::runtime_error if a component attribute or tag is not found |
| 99 | + */ |
| 100 | +HARDWARE_INTERFACE_PUBLIC |
| 101 | +components::ComponentInfo parse_component_from_xml(const tinyxml2::XMLElement * component_it); |
| 102 | + |
| 103 | +/** |
| 104 | + * \brief Search XML snippet for definition of interfaceTypes. |
| 105 | + * |
| 106 | + * \param interfaces_it pointer to the interator over interfaces |
| 107 | + * \param interfaceTag interface type tag (command or state) |
| 108 | + * \return std::vector< std::__cxx11::string > list of interface types |
| 109 | + * \throws std::runtime_error if the interfaceType text not set in a tag |
| 110 | + */ |
| 111 | +HARDWARE_INTERFACE_PUBLIC |
| 112 | +std::vector<std::string> parse_interfaces_from_xml( |
| 113 | + const tinyxml2::XMLElement * interfaces_it, const char * interfaceTag); |
| 114 | + |
| 115 | +/** |
| 116 | + * \brief Search XML snippet from URDF for parameters. |
| 117 | + * |
| 118 | + * \param params_it pointer to the iterator where parameters info should be found |
| 119 | + * \return std::map< std::__cxx11::string, std::__cxx11::string > key-value map with parameters |
| 120 | + * \throws std::runtime_error if a component attribute or tag is not found |
| 121 | + */ |
| 122 | +HARDWARE_INTERFACE_PUBLIC |
| 123 | +std::unordered_map<std::string, std::string> parse_parameters_from_xml( |
| 124 | + const tinyxml2::XMLElement * params_it); |
| 125 | + |
| 126 | +} // namespace hardware_interface |
| 127 | +#endif // HARDWARE_INTERFACE__COMPONENT_PARSER_HPP_ |
0 commit comments