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 
25 namespace memoryx
26 {
28  {
29  setName("");
30  setId("");
31 
34  }
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 AgentInstance::getPositionAttribute() const
55  {
56  return getAttribute("position");
57  }
58 
60  {
61  return armarx::FramedPositionPtr::dynamicCast(getPositionBase());
62  }
63 
64  void AgentInstance::setPosition(const armarx::FramedPositionBasePtr& position, const ::Ice::Current&)
65  {
66  putAttribute("position", position);
67  }
68 
69  EntityAttributeBasePtr AgentInstance::getOrientationAttribute() const
70  {
71  return getAttribute("orientation");
72  }
73 
75  {
76  return armarx::FramedOrientationPtr::dynamicCast(getOrientationBase());
77  }
78 
79  void AgentInstance::setOrientation(const armarx::FramedOrientationBasePtr& orientation, const ::Ice::Current&)
80  {
81  putAttribute("orientation", orientation);
82  }
83 
85  {
86  auto pos = getPosition();
87  return new armarx::FramedPose(pos, getOrientation(), pos->frame, pos->agent);
88  }
89 
90  void AgentInstance::setPose(const armarx::FramedPoseBasePtr& newPose)
91  {
92  armarx::FramedPosePtr pose = armarx::FramedPosePtr::dynamicCast(newPose);
93  setPosition(pose->getPosition());
94  setOrientation(pose->getOrientation());
95  }
96 
97  std::string AgentInstance::getStringifiedSharedRobotInterfaceProxy(const ::Ice::Current&) const
98  {
99  return getAttribute("stringifiedSharedRobotInterfaceProxy")->getValue()->getString();
100  }
101 
102  void AgentInstance::setStringifiedSharedRobotInterfaceProxy(const std::string& stringifiedSharedRobotInterfaceProxy, const ::Ice::Current&)
103  {
104  putAttribute("stringifiedSharedRobotInterfaceProxy", stringifiedSharedRobotInterfaceProxy);
105  }
106 
107  std::string AgentInstance::getAgentFilePath(const::Ice::Current&) const
108  {
109  return getAttribute("agentFilePath")->getValue()->getString();
110  }
111 
112  void AgentInstance::setAgentFilePath(const std::string& agentFilePath, const::Ice::Current&)
113  {
114  putAttribute("agentFilePath", agentFilePath);
115  }
116 
118  {
119  return robot;
120  }
121 
122  void AgentInstance::setSharedRobot(const armarx::SharedRobotInterfacePrx& robot, const Ice::Current& c)
123  {
124  // ARMARX_CHECK_EXPRESSION(robot->getName() == getName());
125  this->robot = robot;
126  setName(robot->getName());
127  setStringifiedSharedRobotInterfaceProxy(robot->ice_toString());
128  }
129 
131  {
132  return this->clone();
133  }
134 
135  AgentInstancePtr AgentInstance::clone(const Ice::Current& c) const
136  {
137  std::shared_lock lock1(entityMutex);
138  std::scoped_lock lock2(attributesMutex);
139  std::scoped_lock lock3(wrappersMutex);
140  AgentInstancePtr ret = new AgentInstance(*this);
141  // ret->deepCopy(*this);
142  ret->robot = robot;
143  return ret;
144  }
145 
146  // ****************************************************************************
147  // Protected members (Ice interface methods overwritten by C++ implementation).
148  // ****************************************************************************
149 
150  armarx::FramedPositionBasePtr AgentInstance::getPositionBase(const ::Ice::Current&) const
151  {
152  return armarx::VariantPtr::dynamicCast(getPositionAttribute()->getValue())->getClass<armarx::FramedPositionBase>();
153  }
154 
155  armarx::FramedOrientationBasePtr AgentInstance::getOrientationBase(const ::Ice::Current&) const
156  {
157  return armarx::VariantPtr::dynamicCast(getOrientationAttribute()->getValue())->getClass<armarx::FramedOrientationBase>();
158  }
159 
160  armarx::FramedPoseBasePtr AgentInstance::getPoseBase(const ::Ice::Current&) const
161  {
162  armarx::FramedOrientationBasePtr ori = armarx::VariantPtr::dynamicCast(getOrientationAttribute()->getValue())->getClass<armarx::FramedOrientationBase>();
163  armarx::FramedPositionBasePtr pos = armarx::VariantPtr::dynamicCast(getPositionAttribute()->getValue())->getClass<armarx::FramedPositionBase>();
164  armarx::FramedPoseBasePtr result(new armarx::FramedPose(armarx::FramedOrientationPtr::dynamicCast(ori)->toEigen(), armarx::FramedPositionPtr::dynamicCast(pos)->toEigen(), pos->frame, pos->agent));
165  return result;
166  }
167 }
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
memoryx::AgentInstance::getPositionAttribute
EntityAttributeBasePtr getPositionAttribute() const
Definition: AgentInstance.cpp:54
armarx::viz::toEigen
Eigen::Matrix4f toEigen(data::GlobalPose const &pose)
Definition: Interaction.h:46
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:327
memoryx::AgentInstance::getOrientation
armarx::FramedOrientationPtr getOrientation() const
Definition: AgentInstance.cpp:74
armarx::FramedPose
The FramedPose class.
Definition: FramedPose.h:258
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:293
memoryx::AgentInstance::getPoseBase
armarx::FramedPoseBasePtr getPoseBase(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: AgentInstance.cpp:160
memoryx::AgentInstance::getStringifiedSharedRobotInterfaceProxy
std::string getStringifiedSharedRobotInterfaceProxy(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: AgentInstance.cpp:97
memoryx::AgentInstance::getPosition
armarx::FramedPositionPtr getPosition() const
Definition: AgentInstance.cpp:59
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::AgentInstance::getPose
armarx::FramedPosePtr getPose() const
Definition: AgentInstance.cpp:84
IceUtil
Definition: Instance.h:21
IceInternal::Handle< FramedPosition >
memoryx::AgentInstance::setAgentFilePath
void setAgentFilePath(const std::string &agentFilePath, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: AgentInstance.cpp:112
memoryx::Entity::attributesMutex
std::mutex attributesMutex
Definition: Entity.h:504
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:142
memoryx::AgentInstance::clone
AgentInstancePtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: AgentInstance.cpp:135
memoryx::AgentInstance::getOrientationAttribute
EntityAttributeBasePtr getOrientationAttribute() const
Definition: AgentInstance.cpp:69
armarx::FramedOrientation
The FramedOrientation class.
Definition: FramedPose.h:199
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
memoryx::Entity::setId
void setId(const ::std::string &id, const ::Ice::Current &=Ice::emptyCurrent) override
Set id of this entity.
Definition: Entity.cpp:167
memoryx::AgentInstance::getSharedRobot
armarx::SharedRobotInterfacePrx getSharedRobot(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: AgentInstance.cpp:117
memoryx::AgentInstance::getOrientationBase
armarx::FramedOrientationBasePtr getOrientationBase(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: AgentInstance.cpp:155
memoryx::AgentInstance::getPositionBase
armarx::FramedPositionBasePtr getPositionBase(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: AgentInstance.cpp:150
memoryx::AgentInstance::setSharedRobot
void setSharedRobot(const armarx::SharedRobotInterfacePrx &robot, const Ice::Current &c=Ice::emptyCurrent) override
set the proxy to a SharedRobot for this agent.
Definition: AgentInstance.cpp:122
memoryx::AgentInstance::setPosition
void setPosition(const armarx::FramedPositionBasePtr &position, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: AgentInstance.cpp:64
memoryx::Entity::entityMutex
std::shared_mutex entityMutex
Definition: Entity.h:505
memoryx::AgentInstance::getAgentFilePath
std::string getAgentFilePath(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: AgentInstance.cpp:107
memoryx::AgentInstance::setPose
void setPose(const armarx::FramedPoseBasePtr &newPose)
Definition: AgentInstance.cpp:90
IceInternal::ProxyHandle< ::IceProxy::armarx::SharedRobotInterface >
AgentInstance.h
memoryx::AgentInstance::AgentInstance
AgentInstance()
Definition: AgentInstance.cpp:27
memoryx::AgentInstance::setOrientation
void setOrientation(const armarx::FramedOrientationBasePtr &orientation, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: AgentInstance.cpp:79
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::AgentInstance
Definition: AgentInstance.h:44
memoryx::AgentInstance::setStringifiedSharedRobotInterfaceProxy
void setStringifiedSharedRobotInterfaceProxy(const std::string &stringifiedSharedRobotInterfaceProxy, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: AgentInstance.cpp:102
memoryx::Entity
Definition: Entity.h:246
memoryx::AgentInstance::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: AgentInstance.cpp:130
memoryx::Entity::setName
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition: Entity.cpp:179
memoryx::Entity::wrappersMutex
std::recursive_mutex wrappersMutex
Definition: Entity.h:506
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28