Skip to content
Snippets Groups Projects
Commit 523f8567 authored by Johann Mantel's avatar Johann Mantel
Browse files

create client Library for easy c

parent 4039b8ec
No related branches found
No related tags found
1 merge request!5Feature/call via memory
......@@ -3,6 +3,7 @@
add_subdirectory(gaze_targets)
add_subdirectory(gaze_controller)
add_subdirectory(client)
# Components
......
armarx_add_ice_library(client_ice
SLICE_FILES
ice/GazeSchedulerInterface.ice
DEPENDENCIES
ArmarXCoreInterfaces
RobotAPIInterfaces
)
armarx_add_library(client
SOURCES
ice_conversions.cpp
AttentionType.cpp
TargetPriority.cpp
ViewSelection.cpp
HEADERS
ice_conversions.h
AttentionType.h
TargetPriority.h
../client.h
DEPENDENCIES_PUBLIC
ViewSelection.h
DEPENDENCIES
ArmarXCoreInterfaces
ArmarXCore
armarx_view_selection::client_ice
armarx_control::gaze_controller
# DEPENDENCIES_PRIVATE
# ...
# DEPENDENCIES_INTERFACE
# ...
# DEPENDENCIES_LEGACY_PUBLIC
# ...
# DEPENDENCIES_LEGACY_PRIVATE
# ...
# DEPENDENCIES_LEGACY_INTERFACE
# ...
armem_robot_state
armarx_view_selection::gaze_targets
)
/**
* 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 view_selection::ArmarXObjects::scheduler_example
* @author Johann Mantel ( j-mantel at gmx dot net )
* @date 2022
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include <ArmarXCore/core/time.h>
#include <RobotAPI/libraries/core/FramedPose.h>
#include "ViewSelection.h"
#include <armarx/view_selection/memory/constants.h>
namespace armarx::view_selection::client
{
ViewSelection::ViewSelection(armarx::armem::client::MemoryNameSystem& mns,
std::string providerSegmentName) :
memoryNameSystem(mns), providerSegmentName(providerSegmentName),
coreSegmentID(memory::constants::ViewMemoryName,
memory::constants::GazeTargetCoreSegmentName)
{
}
ViewSelection::~ViewSelection() = default;
void
ViewSelection::connect()
{
ARMARX_IMPORTANT << "ViewSelection: Waiting for memory '" << coreSegmentID << "' ...";
try
{
memoryWriter = memoryNameSystem.getWriter(coreSegmentID);
ARMARX_IMPORTANT << "ViewSelection: Connected to memory '" << coreSegmentID << "'";
}
catch (const armem::error::CouldNotResolveMemoryServer& e)
{
ARMARX_ERROR << e.what();
return;
}
}
void
ViewSelection::commitGazeTarget(const gaze_targets::GazeTarget& target)
{
if (not memoryWriter)
{
ARMARX_WARNING << "Memory writer is null. Did you forget to call "
"ViewSelection::connect() in onConnectComponent()?";
return;
}
gaze_targets::arondto::GazeTarget dto;
toAron(dto, target);
armem::EntityUpdate update;
update.entityID = coreSegmentID.withProviderSegmentName(providerSegmentName).withEntityName(dto.name);
update.timeCreated = armarx::Clock::Now();
update.instancesData = {dto.toAron()};
memoryWriter.commit(update);
}
void
ViewSelection::commitGazeTargets(const std::vector<gaze_targets::GazeTarget>& targets)
{
for (const auto target : targets)
{
commitGazeTarget(target);
}
}
} // namespace armarx::view_selection::client
/**
* 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 view_selection::ArmarXObjects::scheduler_example
* @author Johann Mantel ( j-mantel at gmx dot net )
* @date 2022
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <ArmarXCore/core/Component.h>
#include <RobotAPI/libraries/armem/client/plugins.h>
// for writing
#include <RobotAPI/libraries/armem/client/Writer.h>
#include <RobotAPI/libraries/armem/client/plugins/PluginUser.h>
#include <RobotAPI/libraries/armem/core/error/mns.h>
#include <RobotAPI/libraries/armem_robot_state/client/common/VirtualRobotReader.h>
#include <armarx/view_selection/gaze_targets.h>
namespace armarx::view_selection::client
{
class ViewSelection
{
public:
ViewSelection(armarx::armem::client::MemoryNameSystem& mns,
std::string providerSegmentName);
~ViewSelection();
void connect();
void commitGazeTarget(const gaze_targets::GazeTarget& target);
void commitGazeTargets(const std::vector<gaze_targets::GazeTarget>& targets);
protected:
private:
private:
// Private member variables go here.
armarx::armem::client::MemoryNameSystem& memoryNameSystem;
std::string providerSegmentName;
const armarx::armem::MemoryID coreSegmentID;
armarx::armem::client::Writer memoryWriter;
};
} // namespace armarx::view_selection::client
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