34#include <RobotAPI/libraries/armem_robot_state/aron/Proprioception.aron.generated.h>
35#include <RobotAPI/libraries/armem_robot_state/aron/Transform.aron.generated.h>
42 template <
class... Args>
44 concatenate(
const std::vector<Args...>& lhs,
const std::vector<Args...>& rhs)
46 std::vector<Args...> conc = lhs;
47 std::copy(rhs.begin(), rhs.end(), std::back_inserter(conc));
51 template <
class KeyT,
class ValueT>
52 std::map<KeyT, ValueT>
55 const size_t size = std::min(lhs.size(), rhs.size());
57 std::map<KeyT, ValueT> map;
58 for (
size_t i = 0; i < size; ++i)
60 map.emplace(lhs[i], rhs[i]);
65 template <
class KeyT,
class ValueT>
68 const std::vector<KeyT>& keys,
69 bool skipMissing =
false)
71 std::vector<ValueT> values;
72 values.reserve(keys.size());
74 for (
const KeyT& key : keys)
78 if (
auto it = map.find(key); it != map.end())
80 values.push_back(it->second);
86 values.push_back(map.at(key));
93 template <
class... Args>
95 slice(
const std::vector<Args...>& vector,
97 std::optional<size_t> end = std::nullopt)
99 std::vector<Args...> result;
100 auto beginIt = vector.begin() + start;
101 auto endIt = end ? vector.begin() + *end : vector.end();
102 std::copy(beginIt, endIt, std::back_inserter(result));
113 client.remote.robotReader.emplace();
120 const std::string& prefix)
122 defs->optional(
properties.robotName, prefix +
"robotName",
"Name of the robot.");
124 defs->optional(
properties.predictAheadSeconds,
125 prefix +
"predictAheadSeconds",
126 "How far into the future to predict [s].");
128 client.remote.robotReader->registerPropertyDefinitions(defs);
145 client.remote.robotReader->connect(mns);
147 this->
remote.arviz = arviz;
168 while (
task and not
task->isStopped())
187 auto desc =
client.remote.robotReader->queryDescription(
properties.robotName, now);
188 if (desc.has_value())
209 :
client.queryLocalizationEntityIDs();
210 const std::vector<armem::MemoryID> propEntityIDs =
212 :
client.queryProprioceptionEntityIDs();
216 auto prediction =
client.predictWholeBody(
217 locEntityIDs, propEntityIDs, predictedTime,
properties.robotName,
"Linear");
221 if (prediction.globalPose.has_value())
224 robotViz->pose(prediction.globalPose->matrix());
229 this->localizationEntityIDs = locEntityIDs;
232 if (prediction.jointPositions.has_value())
234 robotViz->joints(prediction.jointPositions.value());
238 this->propioceptionEntityIDs = propEntityIDs;
246 remote.arviz.commit(layer);
static DateTime Now()
Current time on the virtual clock.
static Duration SecondsDouble(double seconds)
Constructs a duration in seconds.
static Frequency Hertz(std::int64_t hertz)
data::PackagePath serialize() const
The memory name system (MNS) client.
Indicates that a query to the Memory Name System failed.
Represents a point in time.
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Duration waitForNextTick() const
Wait and block until the target period is met.
void connect(armem::client::MemoryNameSystem &mns, viz::Client arviz)
armem::robot_state::RobotStatePredictionClient client
std::optional< std::vector< armem::MemoryID > > localizationEntityIDs
std::optional< viz::Robot > robotViz
std::optional< std::vector< armem::MemoryID > > propioceptionEntityIDs
armarx::SimpleRunningTask ::pointer_type task
void defineProperties(IceUtil::Handle< armarx::PropertyDefinitionContainer > &defs, const std::string &prefix)
Robot & file(std::string const &project, std::string const &filename)
Robot & overrideColor(Color c)
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
const std::string memoryName
SimpleRunningTask(Ts...) -> SimpleRunningTask< std::function< void(void)> >
std::vector< ValueT > multi_at(const std::map< KeyT, ValueT > &map, const std::vector< KeyT > &keys, bool skipMissing=false)
std::vector< Args... > concatenate(const std::vector< Args... > &lhs, const std::vector< Args... > &rhs)
std::vector< Args... > slice(const std::vector< Args... > &vector, size_t start=0, std::optional< size_t > end=std::nullopt)
std::map< KeyT, ValueT > map_from_key_value_pairs(const std::vector< KeyT > &lhs, const std::vector< ValueT > &rhs)
void add(ElementT const &element)