motionprimitives.cpp
Go to the documentation of this file.
1 #include "motionprimitives.h"
2 
3 // #include <iostream>
4 // #include <fstream>
5 
6 #include <SimoxUtility/algorithm/string.h>
7 
10 
11 #include <dmp/representation/trajectory.h>
12 
17 #include <VirtualRobot/MathTools.h>
18 
20 {
21 
22 std::optional<armarx::arondto::Trajectory> createFromFile(const std::filesystem::__cxx11::path &pathToInfoJson, bool taskspace)
23 {
24 
25  if (std::filesystem::exists(pathToInfoJson) && std::filesystem::is_regular_file(pathToInfoJson))
26  {
27  DMP::Vec<DMP::SampledTrajectoryV2 > trajs;
28  DMP::SampledTrajectoryV2 traj;
29  std::string absPath;
30  ArmarXDataPath::getAbsolutePath(pathToInfoJson, absPath);
31  traj.readFromCSVFile(absPath);
32 
33  //traj = DMP::SampledTrajectoryV2::normalizeTimestamps(traj, 0, 1);
34  std::map<double, DMP::DVec> currentTraj = traj.getPositionData();//todo
35  trajs.push_back(traj);
36 
37  armarx::arondto::Trajectory trajectory;
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)
42  {
43  name.erase(pos, toErase.length());
44  }
45  trajectory.name = name;
46  std::map<std::string, std::vector<float>> mapJointSpace;
47  for(DMP::SampledTrajectoryV2 traj: trajs)
48  {
49  std::map<double, DMP::DVec> currentTraj = traj.getPositionData(); // todo: add config making data structure clear
50 
51  if(taskspace)
52  {
53  for(std::pair<double, DMP::DVec> element: currentTraj)
54  {
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);
62 
63  }
64 
65 
66  }
67  else
68  {
69  for(std::pair<double, DMP::DVec> element: currentTraj)
70  {
71  std::vector<float> configvec;
72  for(double el: element.second)
73  {
74  configvec.push_back(float(el));
75  }
76  armarx::arondto::JSElement jselement;
77  jselement.timestep = element.first;
78  jselement.jointValues = configvec;
79  trajectory.jointSpace.steps.push_back(jselement);
80  }
81  }
82 
83  }
84 
85  return trajectory;
86  }
87  else
88  {
89  return std::nullopt;
90  }
91 }
92 
93 
94 
95 }
MemoryRemoteGui.h
error.h
motionprimitives.h
armarx::VariantType::Trajectory
const VariantTypeId Trajectory
Definition: Trajectory.h:44
ExpressionException.h
armarx::armem::server::motions::mps::segment::util::createFromFile
std::optional< armarx::arondto::Trajectory > createFromFile(const std::filesystem::__cxx11::path &pathToInfoJson, bool taskspace)
Definition: motionprimitives.cpp:22
Eigen::Matrix
Definition: EigenForwardDeclarations.h:27
armarx::ArmarXDataPath::getAbsolutePath
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
Definition: ArmarXDataPath.cpp:111
Logging.h
ArmarXDataPath.h
armarx::armem::server::motions::mps::segment::util
Definition: motionprimitives.cpp:19