AgentInstance.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package MemoryX::WorkingMemory
17* @author Thomas von der Heyde (tvh242 at hotmail dot com)
18* @date 2014
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "AgentInstance.h"
24
25namespace memoryx
26{
35
37 IceUtil::Shared(source),
38 ::armarx::Serializable(source),
39 EntityBase(), // dont copy
40 AgentInstanceBase(source),
41 Entity(source)
42 {
43 }
44
45 AgentInstance::AgentInstance(const std::string& name, const std::string& id) : Entity()
46 {
47 setName(name);
48 setId(id);
49
52 }
53
54 EntityAttributeBasePtr
56 {
57 return getAttribute("position");
58 }
59
62 {
63 return armarx::FramedPositionPtr::dynamicCast(getPositionBase());
64 }
65
66 void
67 AgentInstance::setPosition(const armarx::FramedPositionBasePtr& position, const ::Ice::Current&)
68 {
69 putAttribute("position", position);
70 }
71
72 EntityAttributeBasePtr
74 {
75 return getAttribute("orientation");
76 }
77
80 {
81 return armarx::FramedOrientationPtr::dynamicCast(getOrientationBase());
82 }
83
84 void
85 AgentInstance::setOrientation(const armarx::FramedOrientationBasePtr& orientation,
86 const ::Ice::Current&)
87 {
88 putAttribute("orientation", orientation);
89 }
90
93 {
94 auto pos = getPosition();
95 return new armarx::FramedPose(pos, getOrientation(), pos->frame, pos->agent);
96 }
97
98 void
99 AgentInstance::setPose(const armarx::FramedPoseBasePtr& newPose)
100 {
101 armarx::FramedPosePtr pose = armarx::FramedPosePtr::dynamicCast(newPose);
102 setPosition(pose->getPosition());
103 setOrientation(pose->getOrientation());
104 }
105
106 std::string
108 {
109 return getAttribute("stringifiedSharedRobotInterfaceProxy")->getValue()->getString();
110 }
111
112 void
114 const std::string& stringifiedSharedRobotInterfaceProxy,
115 const ::Ice::Current&)
116 {
117 putAttribute("stringifiedSharedRobotInterfaceProxy", stringifiedSharedRobotInterfaceProxy);
118 }
119
120 std::string
121 AgentInstance::getAgentFilePath(const ::Ice::Current&) const
122 {
123 return getAttribute("agentFilePath")->getValue()->getString();
124 }
125
126 void
127 AgentInstance::setAgentFilePath(const std::string& agentFilePath, const ::Ice::Current&)
128 {
129 putAttribute("agentFilePath", agentFilePath);
130 }
131
133 AgentInstance::getSharedRobot(const Ice::Current& c) const
134 {
135 return robot;
136 }
137
138 void
140 const Ice::Current& c)
141 {
142 // ARMARX_CHECK_EXPRESSION(robot->getName() == getName());
143 this->robot = robot;
144 setName(robot->getName());
145 setStringifiedSharedRobotInterfaceProxy(robot->ice_toString());
146 }
147
148 Ice::ObjectPtr
150 {
151 return this->clone();
152 }
153
155 AgentInstance::clone(const Ice::Current& c) const
156 {
157 std::shared_lock lock1(entityMutex);
158 std::scoped_lock lock2(attributesMutex);
159 std::scoped_lock lock3(wrappersMutex);
160 AgentInstancePtr ret = new AgentInstance(*this);
161 // ret->deepCopy(*this);
162 ret->robot = robot;
163 return ret;
164 }
165
166 // ****************************************************************************
167 // Protected members (Ice interface methods overwritten by C++ implementation).
168 // ****************************************************************************
169
170 armarx::FramedPositionBasePtr
171 AgentInstance::getPositionBase(const ::Ice::Current&) const
172 {
173 return armarx::VariantPtr::dynamicCast(getPositionAttribute()->getValue())
174 ->getClass<armarx::FramedPositionBase>();
175 }
176
177 armarx::FramedOrientationBasePtr
178 AgentInstance::getOrientationBase(const ::Ice::Current&) const
179 {
180 return armarx::VariantPtr::dynamicCast(getOrientationAttribute()->getValue())
181 ->getClass<armarx::FramedOrientationBase>();
182 }
183
184 armarx::FramedPoseBasePtr
185 AgentInstance::getPoseBase(const ::Ice::Current&) const
186 {
187 armarx::FramedOrientationBasePtr ori =
188 armarx::VariantPtr::dynamicCast(getOrientationAttribute()->getValue())
189 ->getClass<armarx::FramedOrientationBase>();
190 armarx::FramedPositionBasePtr pos =
191 armarx::VariantPtr::dynamicCast(getPositionAttribute()->getValue())
192 ->getClass<armarx::FramedPositionBase>();
193 armarx::FramedPoseBasePtr result(
194 new armarx::FramedPose(armarx::FramedOrientationPtr::dynamicCast(ori)->toEigen(),
195 armarx::FramedPositionPtr::dynamicCast(pos)->toEigen(),
196 pos->frame,
197 pos->agent));
198 return result;
199 }
200} // namespace memoryx
constexpr T c
The FramedOrientation class.
Definition FramedPose.h:216
The FramedPose class.
Definition FramedPose.h:281
The FramedPosition class.
Definition FramedPose.h:158
armarx::FramedPoseBasePtr getPoseBase(const ::Ice::Current &=Ice::emptyCurrent) const override
std::string getAgentFilePath(const ::Ice::Current &c=Ice::emptyCurrent) const override
void setOrientation(const armarx::FramedOrientationBasePtr &orientation, const ::Ice::Current &=Ice::emptyCurrent) override
EntityAttributeBasePtr getOrientationAttribute() const
armarx::FramedPosePtr getPose() const
armarx::FramedOrientationPtr getOrientation() const
armarx::FramedPositionPtr getPosition() const
armarx::SharedRobotInterfacePrx getSharedRobot(const Ice::Current &c=Ice::emptyCurrent) const override
armarx::FramedPositionBasePtr getPositionBase(const ::Ice::Current &=Ice::emptyCurrent) const override
void setStringifiedSharedRobotInterfaceProxy(const std::string &stringifiedSharedRobotInterfaceProxy, const ::Ice::Current &c=Ice::emptyCurrent) override
void setPose(const armarx::FramedPoseBasePtr &newPose)
void setPosition(const armarx::FramedPositionBasePtr &position, const ::Ice::Current &=Ice::emptyCurrent) override
std::string getStringifiedSharedRobotInterfaceProxy(const ::Ice::Current &c=Ice::emptyCurrent) const override
void setAgentFilePath(const std::string &agentFilePath, const ::Ice::Current &c=Ice::emptyCurrent) override
armarx::FramedOrientationBasePtr getOrientationBase(const ::Ice::Current &=Ice::emptyCurrent) const override
AgentInstancePtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Ice::ObjectPtr ice_clone() const override
void setSharedRobot(const armarx::SharedRobotInterfacePrx &robot, const Ice::Current &c=Ice::emptyCurrent) override
set the proxy to a SharedRobot for this agent.
EntityAttributeBasePtr getPositionAttribute() const
void setId(const ::std::string &id, const ::Ice::Current &=Ice::emptyCurrent) override
Set id of this entity.
Definition Entity.cpp:174
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition Entity.cpp:311
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition Entity.cpp:188
Entity(const Entity &source)
Definition Entity.cpp:34
std::mutex attributesMutex
Definition Entity.h:524
std::recursive_mutex wrappersMutex
Definition Entity.h:526
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition Entity.cpp:347
std::shared_mutex entityMutex
Definition Entity.h:525
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
Definition FramedPose.h:59
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
Definition FramedPose.h:207
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272
VirtualRobot headers.
IceInternal::Handle< AgentInstance > AgentInstancePtr
Typedef of AgentEntityPtr as IceInternal::Handle<AgentEntity> for convenience.