6 #include <SimoxUtility/algorithm/string.h>
7 #include <VirtualRobot/MathTools.h>
16 #include <dmp/representation/trajectory.h>
21 std::optional<armarx::arondto::Trajectory>
22 createFromFile(
const std::filesystem::__cxx11::path& pathToInfoJson,
bool taskspace)
25 if (std::filesystem::exists(pathToInfoJson) &&
26 std::filesystem::is_regular_file(pathToInfoJson))
28 DMP::Vec<DMP::SampledTrajectoryV2> trajs;
29 DMP::SampledTrajectoryV2 traj;
32 traj.readFromCSVFile(absPath);
35 std::map<double, DMP::DVec> currentTraj = traj.getPositionData();
36 trajs.push_back(traj);
39 std::string name = pathToInfoJson.filename();
40 std::string toErase =
"taskspace-trajectory-";
41 size_t pos = name.find(toErase);
42 if (pos != std::string::npos)
44 name.erase(pos, toErase.length());
46 trajectory.name = name;
47 std::map<std::string, std::vector<float>> mapJointSpace;
48 for (DMP::SampledTrajectoryV2 traj : trajs)
50 std::map<double, DMP::DVec> currentTraj =
51 traj.getPositionData();
55 for (std::pair<double, DMP::DVec> element : currentTraj)
58 element.second.at(0), element.second.at(1), element.second.at(2));
60 VirtualRobot::MathTools::quat2eigen4f(element.second.at(4),
63 element.second.at(3));
64 poseMatrix.block<3, 1>(0, 3) = vec;
65 armarx::arondto::TSElement tselement;
66 tselement.timestep = element.first;
67 tselement.pose = poseMatrix;
68 trajectory.taskSpace.steps.push_back(tselement);
73 for (std::pair<double, DMP::DVec> element : currentTraj)
75 std::vector<float> configvec;
76 for (
double el : element.second)
78 configvec.push_back(
float(el));
80 armarx::arondto::JSElement jselement;
81 jselement.timestep = element.first;
82 jselement.jointValues = configvec;
83 trajectory.jointSpace.steps.push_back(jselement);