RobotPoseUnitDynamicSimulation.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2013-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXSimulation::units
19 * @author Nikolaus Vahrenkamp
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
27
28#include <cmath>
29
30#include <Eigen/Geometry>
31
32#include <VirtualRobot/MathTools.h>
33
35
36using namespace armarx;
37
38void
40{
41 //linearVelocityMax = getProperty<float>("LinearVelocityMax").getValue();
42 //linearVelocityMin = getProperty<float>("LinearVelocityMin").getValue();
43 //linearAccelerationMax = getProperty<float>("LinearAccelerationMax").getValue();
44 //angularVelocityMax = getProperty<float>("AngularVelocityMax").getValue();
45 //angularAccelerationMax = getProperty<float>("AngularAccelerationMax").getValue();
46
47 robotName = getProperty<std::string>("RobotName").getValue();
48 //robotRootNodeName = getProperty<std::string>("RobotRootNodeName").getValue();
49
50 simulatorPrxName = getProperty<std::string>("SimulatorProxyName").getValue();
51
52 positionalAccuracy = 0.02f; //in m
53 orientationalAccuracy = 0.1f; //in rad
54
55 intervalMs = getProperty<int>("IntervalMs").getValue();
56 ARMARX_VERBOSE << "Starting RobotPose unit dynamic simulation with " << intervalMs
57 << " ms interval";
59 this,
62 false,
63 "RobotPoseUnitSimulation");
64 simulationTask->setDelayWarningTolerance(100);
65
66 if (!robotName.empty())
67 {
68 std::string robotTopicName = "Simulator_Robot_";
69 robotTopicName += robotName;
70 ARMARX_INFO << "Simulator Robot topic: " << robotTopicName;
71 usingTopic(robotTopicName);
72 }
73 else
74 {
75 ARMARX_WARNING << "No robot loaded...";
76 }
77
79
80 Eigen::Matrix4f m;
81 m.setIdentity();
82 currentPose = Pose(m);
83 targetPose = Pose(m);
84}
85
86void
88{
89 ARMARX_INFO << "Stopping RobotPose unit";
90 std::unique_lock lock(currentPoseMutex);
91 simulationTask->stop();
92 simulatorPrx = nullptr;
93}
94
95void
97{
98 RobotPoseControlMode = eUnknown;
99
100 ARMARX_INFO << "Using simulator proxy: " << simulatorPrxName;
102 PoseBasePtr p = simulatorPrx->getRobotPose(robotName);
105
106 simulationTask->start();
107}
108
109void
114
115void
117{
118 Eigen::Matrix4f m = Eigen::Matrix4f::Identity();
119 PosePtr p(new Pose(m));
120
121 moveRelative(p, 500, 500, current);
122}
123
124void
126{
127 // todo: implement velocity control....
128
129 {
130 std::unique_lock lock(currentPoseMutex);
131
132 if (!simulatorPrx)
133 {
134 return;
135 }
136 }
137}
138
139void
141 Ice::Float positionalAccuracy,
142 Ice::Float orientationalAccuracy,
143 const Ice::Current& c)
144{
145 std::unique_lock lock(currentPoseMutex);
146 RobotPoseControlMode = ePositionControl;
147 ARMARX_DEBUG << "RobotPose move to" << flush;
148 this->targetPose = *(PosePtr::dynamicCast(targetPose));
149 this->positionalAccuracy = positionalAccuracy * .001f;
150 this->orientationalAccuracy = orientationalAccuracy;
151 listenerPrx->begin_reportNewTargetPose(targetPose);
152 ARMARX_LOG << deactivateSpam(5) << "New Target: " << targetPose->position->x << " "
153 << targetPose->position->y << " " << targetPose->position->z;
154 if (simulatorPrx)
155 {
156 //simulatorPrx->begin_setRobotPose(robotName, targetPose);
157 simulatorPrx->setRobotPose(robotName, targetPose);
158 }
159}
160
161Eigen::Vector3f
163{
164 Eigen::Quaternionf q(QuaternionPtr::dynamicCast(pose->orientation)->toEigen());
165 Eigen::Matrix4f m = VirtualRobot::MathTools::quat2eigen4f(q.x(), q.y(), q.z(), q.w());
166 Eigen::Vector3f rpy;
167 VirtualRobot::MathTools::eigen4f2rpy(m, rpy);
168 return rpy;
169}
170
171void
172RobotPoseUnitDynamicSimulation::move(const PoseBasePtr& targetVelocity, const Ice::Current& c)
173{
174 std::unique_lock lock(currentPoseMutex);
175 ARMARX_INFO << deactivateSpam(1) << "NYI";
176}
177
178void
179RobotPoseUnitDynamicSimulation::moveRelative(const PoseBasePtr& relativeTarget,
180 float positionalAccuracy,
182 const Ice::Current& c)
183{
184 PosePtr p;
185 {
186 std::unique_lock lock(currentPoseMutex);
187 RobotPoseControlMode = ePositionControl;
188 Eigen::Matrix4f pose;
189 Eigen::Matrix4f cur = currentPose.toEigen();
190 Eigen::Matrix4f rel = PosePtr::dynamicCast(relativeTarget)->toEigen();
191 pose = cur * rel;
192 p = PosePtr(new Pose(pose));
193 ARMARX_DEBUG << "RobotPose move relative" << flush;
194 }
196}
197
198void
200 float angularVelocity,
201 const Ice::Current& c)
202{
203 //linearVelocityMax = linearVelocity;
204 //angularVelocityMax = angularVelocity;
205}
206
207void
209{
210 ARMARX_DEBUG << "Update new RobotPose pose" << flush;
211
212 if (!newPose)
213 {
214 return;
215 }
216
217 currentPose = *PosePtr::dynamicCast(newPose);
218}
219
220void
221RobotPoseUnitDynamicSimulation::reportState(SimulatedRobotState const& state, const Ice::Current&)
222{
223 setCurrentPose(state.pose);
224}
225
226void
228{
229 std::unique_lock lock(currentPoseMutex);
230 updateCurrentPose(newPose);
231 try
232 {
233 PosePtr p(new Pose(currentPose));
234 listenerPrx->begin_reportRobotPose(p);
235 }
236 catch (...)
237 {
238 }
239}
240
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
constexpr T c
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
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.
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...
The Pose class.
Definition Pose.h:243
void stopMovement(const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTask< RobotPoseUnitDynamicSimulation >::pointer_type simulationTask
void moveRelative(const PoseBasePtr &relativeTarget, Ice::Float positionalAccuracy, Ice::Float orientationalAccuracy, const Ice::Current &c=Ice::emptyCurrent) override
void reportState(SimulatedRobotState const &state, const Ice::Current &) override
PropertyDefinitionsPtr createPropertyDefinitions() override
void moveTo(const PoseBasePtr &targetPose, Ice::Float positionalAccuracy, Ice::Float orientationalAccuracy, const Ice::Current &c=Ice::emptyCurrent) override
void move(const PoseBasePtr &targetVelocity, const Ice::Current &c=Ice::emptyCurrent) override
void setMaxVelocities(Ice::Float positionalVelocity, Ice::Float orientationalVelocity, const Ice::Current &c=Ice::emptyCurrent) override
RobotPoseUnitListenerPrx listenerPrx
RobotPoseUnitListener proxy for publishing state updates.
#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
#define ARMARX_LOG
Definition Logging.h:165
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
#define q
Quaternion< float, 0 > Quaternionf
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const LogSender::manipulator flush
Definition LogSender.h:251