diff --git a/source/RobotAPI/libraries/armem_robot_state/CMakeLists.txt b/source/RobotAPI/libraries/armem_robot_state/CMakeLists.txt index 6484c97ca0695848fc92dcb34008fc5b1d7c70f9..6599139bf53c297b40ace942af30416e01ccda24 100644 --- a/source/RobotAPI/libraries/armem_robot_state/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem_robot_state/CMakeLists.txt @@ -26,6 +26,7 @@ armarx_add_library( ./client/common/RobotReader.h ./client/common/VirtualRobotReader.h + ./client/common/VirtualRobotHelper.h ./client/localization/interfaces.h ./client/localization/TransformReader.h @@ -49,6 +50,7 @@ armarx_add_library( ./client/common/RobotReader.cpp ./client/common/VirtualRobotReader.cpp + ./client/common/VirtualRobotHelper.cpp ./client/localization/TransformReader.cpp diff --git a/source/RobotAPI/libraries/armem_robot_state/client/common/VirtualRobotHelper.cpp b/source/RobotAPI/libraries/armem_robot_state/client/common/VirtualRobotHelper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c2cf87007cc887947c959daefa8c0d8f99128e77 --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_state/client/common/VirtualRobotHelper.cpp @@ -0,0 +1,30 @@ +#include "VirtualRobotHelper.h" +#include "ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h" + +#include <VirtualRobot/Robot.h> + +namespace armarx +{ + VirtualRobotHelper::VirtualRobotHelper(const VirtualRobot::RobotPtr& robot): robot(robot) {} + + RobotInfoNodePtr VirtualRobotHelper::readRobotInfo() const + { + RapidXmlReaderPtr reader = RapidXmlReader::FromFile(robot->getFilename()); + RapidXmlReaderNode robotNode = reader->getRoot("Robot"); + return readRobotInfo(robotNode.first_node("RobotInfo")); + } + + RobotInfoNodePtr VirtualRobotHelper::readRobotInfo(const RapidXmlReaderNode& infoNode) const + { + std::string name = infoNode.name(); + std::string profile = infoNode.attribute_value_or_default("profile", ""); + std::string value = infoNode.attribute_value_or_default("value", ""); + //ARMARX_IMPORTANT << "name: " << name << "; profile: " << profile << "; value: " << value; + std::vector<RobotInfoNodePtr> children; + for (const RapidXmlReaderNode& childNode : infoNode.nodes()) + { + children.push_back(readRobotInfo(childNode)); + } + return new RobotInfoNode(name, profile, value, children); + } +} // namespace armarx \ No newline at end of file diff --git a/source/RobotAPI/libraries/armem_robot_state/client/common/VirtualRobotHelper.h b/source/RobotAPI/libraries/armem_robot_state/client/common/VirtualRobotHelper.h new file mode 100644 index 0000000000000000000000000000000000000000..199cd650afb7a5d0f5ff9832c303cb260abcda63 --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_state/client/common/VirtualRobotHelper.h @@ -0,0 +1,52 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include <VirtualRobot/VirtualRobot.h> + +#include <RobotAPI/interface/core/RobotState.h> + +namespace armarx +{ + + class RapidXmlReaderNode; + + /** + * @brief The VirtualRobotHelper class. + * + * Provides access to additional data stored in the robot's XML file that is not part + * of the VirtualRobot::Robot data structure. + * + * Formerly, this functionality was part of armarx::RobotStateComponent. + */ + class VirtualRobotHelper + { + public: + VirtualRobotHelper(const VirtualRobot::RobotPtr& robot); + + RobotInfoNodePtr readRobotInfo() const; + + private: + RobotInfoNodePtr readRobotInfo(const RapidXmlReaderNode& infoNode) const; + + VirtualRobot::RobotPtr robot; + }; + +} // namespace armarx \ No newline at end of file