6 #include <SimoxUtility/algorithm/string.h>
11 #include <dmp/representation/trajectory.h>
17 #include <VirtualRobot/MathTools.h>
22 std::optional<armarx::arondto::Trajectory>
createFromFile(
const std::filesystem::__cxx11::path &pathToInfoJson,
bool taskspace)
25 if (std::filesystem::exists(pathToInfoJson) && std::filesystem::is_regular_file(pathToInfoJson))
27 DMP::Vec<DMP::SampledTrajectoryV2 > trajs;
28 DMP::SampledTrajectoryV2 traj;
31 traj.readFromCSVFile(absPath);
34 std::map<double, DMP::DVec> currentTraj = traj.getPositionData();
35 trajs.push_back(traj);
38 std::string name = pathToInfoJson.filename();
39 std::string toErase =
"taskspace-trajectory-";
40 size_t pos = name.find(toErase);
41 if (pos != std::string::npos)
43 name.erase(pos, toErase.length());
45 trajectory.name = name;
46 std::map<std::string, std::vector<float>> mapJointSpace;
47 for(DMP::SampledTrajectoryV2 traj: trajs)
49 std::map<double, DMP::DVec> currentTraj = traj.getPositionData();
53 for(std::pair<double, DMP::DVec> element: currentTraj)
55 Eigen::Vector3f vec(element.second.at(0), element.second.at(1), element.second.at(2));
56 Eigen::Matrix<float, 4, 4> poseMatrix = VirtualRobot::MathTools::quat2eigen4f(element.second.at(4), element.second.at(5), element.second.at(6), element.second.at(3));
57 poseMatrix.block<3, 1>(0, 3) = vec;
58 armarx::arondto::TSElement tselement;
59 tselement.timestep = element.first;
60 tselement.pose = poseMatrix;
61 trajectory.taskSpace.steps.push_back(tselement);
69 for(std::pair<double, DMP::DVec> element: currentTraj)
71 std::vector<float> configvec;
72 for(
double el: element.second)
74 configvec.push_back(
float(el));
76 armarx::arondto::JSElement jselement;
77 jselement.timestep = element.first;
78 jselement.jointValues = configvec;
79 trajectory.jointSpace.steps.push_back(jselement);