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 #include <VirtualRobot/MathTools.h>
8 
12 
15 
16 #include <dmp/representation/trajectory.h>
17 
19 {
20 
21  std::optional<armarx::arondto::Trajectory>
22  createFromFile(const std::filesystem::__cxx11::path& pathToInfoJson, bool taskspace)
23  {
24 
25  if (std::filesystem::exists(pathToInfoJson) &&
26  std::filesystem::is_regular_file(pathToInfoJson))
27  {
28  DMP::Vec<DMP::SampledTrajectoryV2> trajs;
29  DMP::SampledTrajectoryV2 traj;
30  std::string absPath;
31  ArmarXDataPath::getAbsolutePath(pathToInfoJson, absPath);
32  traj.readFromCSVFile(absPath);
33 
34  //traj = DMP::SampledTrajectoryV2::normalizeTimestamps(traj, 0, 1);
35  std::map<double, DMP::DVec> currentTraj = traj.getPositionData(); //todo
36  trajs.push_back(traj);
37 
38  armarx::arondto::Trajectory trajectory;
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)
43  {
44  name.erase(pos, toErase.length());
45  }
46  trajectory.name = name;
47  std::map<std::string, std::vector<float>> mapJointSpace;
48  for (DMP::SampledTrajectoryV2 traj : trajs)
49  {
50  std::map<double, DMP::DVec> currentTraj =
51  traj.getPositionData(); // todo: add config making data structure clear
52 
53  if (taskspace)
54  {
55  for (std::pair<double, DMP::DVec> element : currentTraj)
56  {
57  Eigen::Vector3f vec(
58  element.second.at(0), element.second.at(1), element.second.at(2));
59  Eigen::Matrix<float, 4, 4> poseMatrix =
60  VirtualRobot::MathTools::quat2eigen4f(element.second.at(4),
61  element.second.at(5),
62  element.second.at(6),
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);
69  }
70  }
71  else
72  {
73  for (std::pair<double, DMP::DVec> element : currentTraj)
74  {
75  std::vector<float> configvec;
76  for (double el : element.second)
77  {
78  configvec.push_back(float(el));
79  }
80  armarx::arondto::JSElement jselement;
81  jselement.timestep = element.first;
82  jselement.jointValues = configvec;
83  trajectory.jointSpace.steps.push_back(jselement);
84  }
85  }
86  }
87 
88  return trajectory;
89  }
90  else
91  {
92  return std::nullopt;
93  }
94  }
95 
96 
97 } // namespace armarx::armem::server::motions::mps::segment::util
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:109
Logging.h
ArmarXDataPath.h
armarx::armem::server::motions::mps::segment::util
Definition: motionprimitives.cpp:18