ConverterTools.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <set>
5 #include <string>
6 
7 #include <Eigen/Core>
8 
9 #include <SimoxUtility/algorithm/string/string_tools.h>
10 
11 #include <RobotAPI/libraries/armem_robot_state/aron/Proprioception.aron.generated.h>
13 
14 #include "ConverterInterface.h"
15 
16 
18 {
19 
21  {
22  const RobotUnitDataStreaming::TimeStep& data;
23  const RobotUnitDataStreaming::DataEntry& entry;
24  };
25 
26 
27  template <class T>
28  T
30  {
31  return RobotUnitDataStreamingReceiver::GetAs<T>(value.data, value.entry);
32  }
33 
34 
35  /**
36  * @brief Search
37  * @param key
38  * @param prefixes
39  * @return
40  */
41  std::optional<std::string>
42  findByPrefix(const std::string& key, const std::set<std::string>& prefixes);
43 
44 
45  template <class ValueT>
46  ValueT
47  findByPrefix(const std::string& key, const std::map<std::string, ValueT>& map)
48  {
49  for (const auto& [prefix, value] : map)
50  {
51  if (simox::alg::starts_with(key, prefix))
52  {
53  return value;
54  }
55  }
56  return nullptr;
57  }
58 
59 
60  template <class ValueT>
61  ValueT
62  findBySuffix(const std::string& key, const std::map<std::string, ValueT>& map)
63  {
64  for (const auto& [suffix, value] : map)
65  {
66  if (simox::alg::ends_with(key, suffix))
67  {
68  return value;
69  }
70  }
71  return nullptr;
72  }
73 
74 
75 
77  {
78  public:
79 
81 
82 
83  public:
84 
85  std::map<std::string, std::function<void(Eigen::Vector3f&, float)> > vector3fSetters;
86 
87  std::map<std::string, std::function<std::map<std::string, float>*(prop::arondto::Joints&)> > jointGetters;
88  std::map<std::string, std::function<std::map<std::string, Eigen::Vector3f>*(prop::arondto::Joints&)> > jointVectorGetters;
89 
90  using JointSetter = std::function<void(prop::arondto::Joints& dto, const std::vector<std::string>& split, const ConverterValue& value)>;
91  std::map<std::string, JointSetter> jointSetters;
92 
93  std::map<std::string, std::function<Eigen::Vector3f*(prop::arondto::Platform&)> > platformPoseGetters;
94  std::set<std::string> platformIgnored;
95 
96  std::map<std::string, std::function<Eigen::Vector3f*(prop::arondto::ForceTorque&)> > ftGetters;
97 
98 
99  std::map<std::string, std::string> sidePrefixMap
100  {
101  { "R", "Right" },
102  { "L", "Left" },
103  };
104 
105  };
106 }
armarx::human::pose::model::k4a_bt_body_32::Joints
Joints
Joints with index as defined in the body model.
Definition: k4a_bt_body_32.h:39
ConverterInterface.h
armarx::armem::server::robot_state::exteroception::findByPrefix
std::optional< std::string > findByPrefix(const std::string &key, const std::set< std::string > &prefixes)
Search.
Definition: ConverterTools.cpp:14
armarx::armem::server::robot_state::exteroception::ConverterValue::entry
const RobotUnitDataStreaming::DataEntry & entry
Definition: ConverterTools.h:23
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:43
armarx::armem::server::robot_state::exteroception::ConverterTools::platformIgnored
std::set< std::string > platformIgnored
Definition: ConverterTools.h:94
armarx::armem::server::robot_state::exteroception::ConverterTools::vector3fSetters
std::map< std::string, std::function< void(Eigen::Vector3f &, float)> > vector3fSetters
Definition: ConverterTools.h:85
RobotUnitDataStreamingReceiver.h
armarx::armem::server::robot_state::exteroception::ConverterTools::ftGetters
std::map< std::string, std::function< Eigen::Vector3f *(prop::arondto::ForceTorque &)> > ftGetters
Definition: ConverterTools.h:96
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::armem::server::robot_state::exteroception::ConverterTools::ConverterTools
ConverterTools()
Definition: ConverterTools.cpp:30
armarx::armem::server::robot_state::exteroception::ConverterTools
Definition: ConverterTools.h:76
armarx::armem::server::robot_state::exteroception::ConverterTools::JointSetter
std::function< void(prop::arondto::Joints &dto, const std::vector< std::string > &split, const ConverterValue &value)> JointSetter
Definition: ConverterTools.h:90
armarx::armem::server::robot_state::exteroception::ConverterTools::platformPoseGetters
std::map< std::string, std::function< Eigen::Vector3f *(prop::arondto::Platform &)> > platformPoseGetters
Definition: ConverterTools.h:93
armarx::armem::server::robot_state::exteroception::ConverterTools::jointVectorGetters
std::map< std::string, std::function< std::map< std::string, Eigen::Vector3f > *(prop::arondto::Joints &)> > jointVectorGetters
Definition: ConverterTools.h:88
armarx::armem::server::robot_state::exteroception::ConverterTools::jointSetters
std::map< std::string, JointSetter > jointSetters
Definition: ConverterTools.h:91
armarx::armem::server::robot_state::exteroception
Definition: ArmarDEConverter.cpp:18
armarx::armem::server::robot_state::exteroception::ConverterTools::sidePrefixMap
std::map< std::string, std::string > sidePrefixMap
Definition: ConverterTools.h:100
armarx::armem::server::robot_state::exteroception::ConverterValue
Definition: ConverterTools.h:20
armarx::armem::server::robot_state::exteroception::findBySuffix
ValueT findBySuffix(const std::string &key, const std::map< std::string, ValueT > &map)
Definition: ConverterTools.h:62
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:50
armarx::armem::server::robot_state::exteroception::ConverterTools::jointGetters
std::map< std::string, std::function< std::map< std::string, float > *(prop::arondto::Joints &)> > jointGetters
Definition: ConverterTools.h:87
armarx::armem::server::robot_state::exteroception::getValueAs
T getValueAs(const ConverterValue &value)
Definition: ConverterTools.h:29
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::armem::server::robot_state::exteroception::ConverterValue::data
const RobotUnitDataStreaming::TimeStep & data
Definition: ConverterTools.h:22
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36