Skip to content
Snippets Groups Projects
Commit 928afc24 authored by Christoph Pohl's avatar Christoph Pohl
Browse files

Add readers for executed and executable actions

parent 836d5a86
No related branches found
No related tags found
No related merge requests found
......@@ -2,14 +2,19 @@ armarx_add_library(client
SOURCES
action_hypothesis/Writer.cpp
executed_action/Writer.cpp
executed_action/Reader.cpp
executable_action/Writer.cpp
executable_action/Reader.cpp
manipulation_process/Writer.cpp
HEADERS
action_hypothesis/Writer.h
executed_action/Writer.h
executed_action/Reader.h
executable_action/Writer.h
executable_action/Reader.h
manipulation_process/Writer.h
core/Writer.h
core/Reader.h
DEPENDENCIES_PUBLIC
aron armem
armarx_manipulation::core
......
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package armarx_manipulation
* @author Christoph Pohl ( christoph dot pohl at kit dot edu )
* @date 22.02.23
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <experimental/memory>
#include <RobotAPI/libraries/armem/client/Query.h>
#include <RobotAPI/libraries/armem/client/query/Builder.h>
#include <RobotAPI/libraries/armem/client/query/selectors.h>
#include <RobotAPI/libraries/armem/client/util/SimpleReaderBase.h>
#include <armarx/manipulation/core/forward_declarations.h>
#include <armarx/manipulation/meta/is_stl_container.h>
namespace armarx::manipulation::memory::client::core
{
template <typename BusinessObj>
struct ReaderImplementation;
template <typename BusinessObj>
class Reader : virtual public armem::client::util::SimpleReaderBase
{
using ImplT = ReaderImplementation<BusinessObj>;
public:
using armem::client::util::SimpleReaderBase::SimpleReaderBase;
std::vector<BusinessObj>
query(const std::string& providerName,
const std::optional<std::string>& entityName = std::nullopt,
const std::optional<armem::Time>& startTime = std::nullopt,
const std::optional<armem::Time>& endTime = std::nullopt)
{
armem::client::query::Builder qb;
std::experimental::observer_ptr<armem::client::query::ProviderSegmentSelector> ps;
std::experimental::observer_ptr<armem::client::query::EntitySelector> es;
std::experimental::observer_ptr<armem::client::query::SnapshotSelector> ss;
ps = std::experimental::make_observer(&qb.coreSegments()
.withName(properties().coreSegmentName)
.providerSegments()
.withName(providerName));
if (entityName.has_value())
{
es = std::experimental::make_observer(&ps->entities().withName(entityName.value()));
}
else
{
es = std::experimental::make_observer(&ps->entities().all());
}
if (startTime.has_value() and endTime.has_value())
{
ss = std::experimental::make_observer(
&es->snapshots().timeRange(startTime.value(), endTime.value()));
}
else
{
ss = std::experimental::make_observer(&es->snapshots().all());
}
(void*)ss.get();
const auto query = qb.buildQueryInput();
return fromQuery(memoryReader().query(query), providerName);
}
std::string
propertyPrefix() const override
{
return std::string(ImplT::propertyPrefix);
}
Properties
defaultProperties() const override
{
return {.memoryName = std::string(ImplT::memoryName),
.coreSegmentName = std::string(ImplT::coreSegmentName)};
}
private:
std::vector<BusinessObj>
fromQuery(const armem::client::QueryResult& query, const std::string& providerName)
{
return ImplT::fromQuery(query, properties().coreSegmentName, providerName);
}
};
} // namespace armarx::manipulation::memory::client::core
\ No newline at end of file
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package armarx_manipulation
* @author Christoph Pohl ( christoph dot pohl at kit dot edu )
* @date 22.02.23
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "Reader.h"
#include <armarx/manipulation/core/ExecutableAction.h>
#include <armarx/manipulation/core/aron_conversions.h>
namespace armarx::manipulation::memory::client::core
{
std::vector<manipulation::core::ExecutableAction>
ReaderImplementation<armarx::manipulation::core::ExecutableAction>::fromQuery(
const armem::client::QueryResult& query,
const std::string& coreSegment,
const std::string& providerSegment)
{
const auto& segment =
query.memory.getCoreSegment(coreSegment).getProviderSegment(providerSegment);
std::vector<armarx::manipulation::core::ExecutableAction> actions;
segment.forEachInstance(
[&actions](const auto& instance)
{
manipulation::core::arondto::ExecutableAction action;
try
{
action.fromAron(instance.data());
}
catch (...)
{
ARMARX_WARNING << "Conversion to ExecutedAction failed!";
}
actions.emplace_back(manipulation::core::fromAron(action));
});
return actions;
}
template struct ReaderImplementation<armarx::manipulation::core::ExecutableAction>;
template class Reader<armarx::manipulation::core::ExecutableAction>;
} // namespace armarx::manipulation::memory::client::core
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package armarx_manipulation
* @author Christoph Pohl ( christoph dot pohl at kit dot edu )
* @date 24.02.22
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <armarx/manipulation/client/core/Reader.h>
namespace armarx::manipulation::memory::client
{
namespace core
{
template <>
struct ReaderImplementation<armarx::manipulation::core::ExecutableAction>
{
static constexpr std::string_view propertyPrefix = "mem.manip.executed_action.";
static constexpr std::string_view memoryName = "Manipulation";
static constexpr std::string_view coreSegmentName = "Actions_Executed";
static constexpr std::string_view providerName = "";
static std::vector<manipulation::core::ExecutableAction>
fromQuery(const armem::client::QueryResult& query,
const std::string& coreSegment,
const std::string& providerSegment);
};
extern template struct ReaderImplementation<armarx::manipulation::core::ExecutableAction>;
extern template struct ReaderImplementation<armarx::manipulation::core::ExecutableAction>;
} // namespace core
namespace executable_action
{
using Reader = core::Reader<armarx::manipulation::core::ExecutableAction>;
}
} // namespace armarx::manipulation::memory::client
\ No newline at end of file
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package armarx_manipulation
* @author Christoph Pohl ( christoph dot pohl at kit dot edu )
* @date 22.02.23
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "Reader.h"
#include <armarx/manipulation/core/ExecutedAction.h>
#include <armarx/manipulation/core/aron/ExecutedAction.aron.generated.h>
#include <armarx/manipulation/core/aron_conversions.h>
namespace armarx::manipulation::memory::client::core
{
std::vector<manipulation::core::ExecutedAction>
ReaderImplementation<armarx::manipulation::core::ExecutedAction>::fromQuery(
const armem::client::QueryResult& query,
const std::string& coreSegment,
const std::string& providerSegment)
{
const auto& segment =
query.memory.getCoreSegment(coreSegment).getProviderSegment(providerSegment);
std::vector<armarx::manipulation::core::ExecutedAction> actions;
segment.forEachInstance(
[&actions](const auto& instance)
{
manipulation::core::arondto::ExecutedAction action;
try
{
action.fromAron(instance.data());
}
catch (...)
{
ARMARX_WARNING << "Conversion to ExecutedAction failed!";
}
actions.emplace_back(manipulation::core::fromAron(action));
});
return actions;
}
template struct ReaderImplementation<armarx::manipulation::core::ExecutedAction>;
template class Reader<armarx::manipulation::core::ExecutedAction>;
} // namespace armarx::manipulation::memory::client::core
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package armarx_manipulation
* @author Christoph Pohl ( christoph dot pohl at kit dot edu )
* @date 24.02.22
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <armarx/manipulation/client/core/Reader.h>
namespace armarx::manipulation::memory::client
{
namespace core
{
template <>
struct ReaderImplementation<armarx::manipulation::core::ExecutedAction>
{
static constexpr std::string_view propertyPrefix = "mem.manip.executed_action.";
static constexpr std::string_view memoryName = "Manipulation";
static constexpr std::string_view coreSegmentName = "Actions_Executed";
static constexpr std::string_view providerName = "";
static std::vector<manipulation::core::ExecutedAction>
fromQuery(const armem::client::QueryResult& query,
const std::string& coreSegment,
const std::string& providerSegment);
};
extern template struct ReaderImplementation<armarx::manipulation::core::ExecutedAction>;
extern template struct ReaderImplementation<armarx::manipulation::core::ExecutedAction>;
} // namespace core
namespace executed_action
{
using Reader = core::Reader<armarx::manipulation::core::ExecutedAction>;
}
} // namespace armarx::manipulation::memory::client
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment