From b0cb4d24a943c6d32e1db0304a0dbeb09f8f4bb8 Mon Sep 17 00:00:00 2001
From: Fabian Reister <fabian.reister@kit.edu>
Date: Tue, 7 Feb 2023 11:18:55 +0100
Subject: [PATCH] fix: removing package_name from relative path to create
 PackagePath

---
 .../server/description/Segment.cpp            | 21 +++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/source/RobotAPI/libraries/armem_robot_state/server/description/Segment.cpp b/source/RobotAPI/libraries/armem_robot_state/server/description/Segment.cpp
index e323a2815..0996242a4 100644
--- a/source/RobotAPI/libraries/armem_robot_state/server/description/Segment.cpp
+++ b/source/RobotAPI/libraries/armem_robot_state/server/description/Segment.cpp
@@ -1,4 +1,5 @@
 #include "Segment.h"
+#include <SimoxUtility/algorithm/string/string_tools.h>
 
 #include <ArmarXCore/core/application/properties/PluginAll.h>
 #include <ArmarXCore/core/exceptions/local/ExpressionException.h>
@@ -83,14 +84,26 @@ namespace armarx::armem::server::robot_state::description
             const std::vector<std::string> packages = armarx::CMakePackageFinder::FindAllArmarXSourcePackages();
             const std::string package = armarx::ArmarXDataPath::getProject(packages, robotFilename);
 
-            const std::string fixedRobotFilename = robotFilename.substr(package.size() + 1, -1);
-            ARMARX_INFO << "Robot description '" << VAROUT(fixedRobotFilename) << "' found in package " << package;
+            // make sure that the relative path is without the 'package/' prefix
+            const std::string robotFileRelPath = [&robotFilename, &package]()-> std::string {
+
+                if(simox::alg::starts_with(robotFilename, package))
+                {
+                    // remove "package" + "/"
+                    const std::string fixedRobotFilename = robotFilename.substr(package.size() + 1, -1);
+                    return fixedRobotFilename;
+                }
+                
+                return robotFilename;
+            }();
+
+            ARMARX_INFO << "Robot description '" << VAROUT(robotFileRelPath) << "' found in package " << package;
 
             const robot::RobotDescription robotDescription
             {
                 .name = kinematicUnit->getRobotName(),
-                .xml  = {package, fixedRobotFilename}
-            }; // FIXME
+                .xml  = {package, robotFileRelPath}
+            };
 
             commitRobotDescription(robotDescription);
         }
-- 
GitLab