KinematicSelfLocalization.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 ArmarXSimulation::ArmarXObjects::KinematicSelfLocalization
17 * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
18 * @date 2016
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
25#include <Eigen/Geometry>
26
27#include <SimoxUtility/math/convert/rpy_to_mat3f.h>
28
30#include <RobotAPI/interface/core/GeometryBase.h>
31
34
35using namespace armarx;
36
37void
39{
40 usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
41
42 usingProxy(getProperty<std::string>("WorkingMemoryName").getValue());
43 usingTopic(getProperty<std::string>("PlatformTopicName").getValue());
44}
45
46void
48{
50 getProperty<std::string>("RobotStateComponentName").getValue());
52 ARMARX_INFO << "Retrieved robot state proxy...";
53
55 getProperty<std::string>("WorkingMemoryName").getValue());
57 ARMARX_INFO << "Retrieved WM proxy...";
58
59 agentsMemoryPrx = memoryPrx->getAgentInstancesSegment();
61 ARMARX_INFO << "Retrieved WM agent segment ...";
62
63 Ice::CommunicatorPtr iceCommunicator = getIceManager()->getCommunicator();
64
65 robotName = getProperty<std::string>("RobotName").getValue();
67 getProperty<float>("RobotPoseZ").isSet() ? getProperty<float>("RobotPoseZ").getValue() : 0;
68
69 std::string agentName = getProperty<std::string>("AgentName").isSet()
70 ? getProperty<std::string>("AgentName").getValue()
71 : robotName;
72
73
74 ARMARX_INFO << "Creating robot agent with name " << agentName;
75 robotAgent = new memoryx::AgentInstance(agentName);
76 auto robot = robotStateComponentPrx->getSynchronizedRobot();
77 robotAgent->setSharedRobot(robot);
78 robotAgent->setName(agentName);
79 robotAgent->setStringifiedSharedRobotInterfaceProxy(iceCommunicator->proxyToString(robot));
80 robotAgent->setAgentFilePath(robotStateComponentPrx->getRobotFilename());
81 ARMARX_INFO << "Creating robot agent...done";
82
83 // Simulating platform movement to initial pose
84 Eigen::Isometry3f global_T_robot_initial = Eigen::Isometry3f::Identity();
85 global_T_robot_initial.translation().x() =
86 getProperty<float>("InitialPlatformPoseX").getValue();
87 global_T_robot_initial.translation().y() =
88 getProperty<float>("InitialPlatformPoseY").getValue();
89 global_T_robot_initial.linear() =
90 simox::math::rpy_to_mat3f(0, 0, getProperty<float>("InitialPlatformPoseAngle").getValue());
91
92 TransformStamped transformStamped;
93 transformStamped.transform = global_T_robot_initial.matrix();
94 transformStamped.header.agent = agentName;
95 transformStamped.header.frame = GlobalFrame;
96 transformStamped.header.timestampInMicroSeconds = TimeUtil::GetTime().toMicroSeconds();
97
98 reportGlobalRobotPose(transformStamped);
99
100 // periodic task setup
101 cycleTime = 30;
102
103 if (execTask)
104 {
105 execTask->stop();
106 }
107
108 execTask =
111 cycleTime,
112 false,
113 "KinematicSelfLocalizationCalculation");
114 execTask->start();
115 execTask->setDelayWarningTolerance(100);
116}
117
118void
123
124void
128
135
136void
138{
139 try
140 {
141 std::unique_lock lock(dataMutex);
142 ARMARX_DEBUG << "Reporting robot agent:" << robotAgent->getName()
143 << ", robotAgentId:" << robotAgentId << ", self:" << this->getName();
144
145
146 if (!currentRobotPose)
147 {
148 return;
149 }
151
152 robotAgentId = agentsMemoryPrx->upsertEntityByName(robotAgent->getName(), robotAgent);
153 robotAgent->setId(robotAgentId);
154 }
155 catch (...)
156 {
157 ARMARX_WARNING << deactivateSpam(10) << "Could not update robot pose in agents segment...\n"
159 robotAgentId.clear();
160 }
161}
162
163void
164KinematicSelfLocalization::reportGlobalRobotPose(const ::armarx::TransformStamped& transformStamped,
165 const ::Ice::Current&)
166{
167 std::unique_lock lock(dataMutex);
168
169 Eigen::Isometry3f global_T_robot(transformStamped.transform);
170 global_T_robot.translation().z() = robotPoseZ; // TODO lecagy. Is this really necessary?
171
172 currentRobotPose = new FramedPose(global_T_robot.matrix(), armarx::GlobalFrame, "");
173}
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
The FramedPose class.
Definition FramedPose.h:281
memoryx::WorkingMemoryInterfacePrx memoryPrx
void reportGlobalRobotPose(const ::armarx::TransformStamped &, const ::Ice::Current &=::Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
memoryx::AgentInstancesSegmentBasePrx agentsMemoryPrx
PeriodicTask< KinematicSelfLocalization >::pointer_type execTask
RobotStateComponentInterfacePrx robotStateComponentPrx
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition Logging.cpp:99
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
std::string getName() const
Retrieve name of object.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition TimeUtil.cpp:42
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
Definition IceManager.h:49
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::string GetHandledExceptionString()
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.