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
12#include <RobotAPI/libraries/armem_robot_state/aron/Proprioception.aron.generated.h>
13
14#include "ConverterInterface.h"
15
17{
18
20 {
21 const RobotUnitDataStreaming::TimeStep& data;
22 const RobotUnitDataStreaming::DataEntry& entry;
23 };
24
25 template <class T>
26 T
28 {
29 return RobotUnitDataStreamingReceiver::GetAs<T>(value.data, value.entry);
30 }
31
32 /**
33 * @brief Search
34 * @param key
35 * @param prefixes
36 * @return
37 */
38 std::optional<std::string> findByPrefix(const std::string& key,
39 const std::set<std::string>& prefixes);
40
41 template <class ValueT>
42 ValueT
43 findByPrefix(const std::string& key, const std::map<std::string, ValueT>& map)
44 {
45 for (const auto& [prefix, value] : map)
46 {
47 if (simox::alg::starts_with(key, prefix))
48 {
49 return value;
50 }
51 }
52 return nullptr;
53 }
54
55 template <class ValueT>
56 ValueT
57 findBySuffix(const std::string& key, const std::map<std::string, ValueT>& map)
58 {
59 for (const auto& [suffix, value] : map)
60 {
61 if (simox::alg::ends_with(key, suffix))
62 {
63 return value;
64 }
65 }
66 return nullptr;
67 }
68
70 {
71 public:
73
74
75 public:
76 std::map<std::string, std::function<void(Eigen::Vector3f&, float)>> vector3fSetters;
77
78 std::map<std::string, std::function<std::map<std::string, float>*(prop::arondto::Joints&)>>
80 std::map<std::string,
81 std::function<std::map<std::string, Eigen::Vector3f>*(prop::arondto::Joints&)>>
83
84 using JointSetter = std::function<void(prop::arondto::Joints& dto,
85 const std::vector<std::string>& split,
86 const ConverterValue& value)>;
87 std::map<std::string, JointSetter> jointSetters;
88
89 std::map<std::string, std::function<Eigen::Vector3f*(prop::arondto::Platform&)>>
91 std::set<std::string> platformIgnored;
92
93 std::map<std::string, std::function<Eigen::Vector3f*(prop::arondto::ForceTorque&)>>
95
96
97 std::map<std::string, std::string> sidePrefixMap{
98 {"R", "Right"},
99 {"L", "Left"},
100 };
101 };
102} // namespace armarx::armem::server::robot_state::exteroception
static T GetAs(const timestep_t &st, const entry_t &e)
std::map< std::string, std::function< std::map< std::string, float > *(prop::arondto::Joints &)> > jointGetters
std::map< std::string, std::function< std::map< std::string, Eigen::Vector3f > *(prop::arondto::Joints &)> > jointVectorGetters
std::function< void(prop::arondto::Joints &dto, const std::vector< std::string > &split, const ConverterValue &value)> JointSetter
std::map< std::string, std::function< Eigen::Vector3f *(prop::arondto::ForceTorque &)> > ftGetters
std::map< std::string, std::function< Eigen::Vector3f *(prop::arondto::Platform &)> > platformPoseGetters
std::map< std::string, std::function< void(Eigen::Vector3f &, float)> > vector3fSetters
ValueT findBySuffix(const std::string &key, const std::map< std::string, ValueT > &map)
std::optional< std::string > findByPrefix(const std::string &key, const std::set< std::string > &prefixes)
Search.
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)