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
29
30#include <cmath>
31
32#include <Eigen/Geometry>
33
34#include <VirtualRobot/MathTools.h>
35
37
38using namespace armarx;
39
40void
42{
43 //linearVelocityMax = getProperty<float>("LinearVelocityMax").getValue();
44 //linearVelocityMin = getProperty<float>("LinearVelocityMin").getValue();
45 //linearAccelerationMax = getProperty<float>("LinearAccelerationMax").getValue();
46 //angularVelocityMax = getProperty<float>("AngularVelocityMax").getValue();
47 //angularAccelerationMax = getProperty<float>("AngularAccelerationMax").getValue();
48
49 robotName = getProperty<std::string>("RobotName").getValue();
50 //robotRootNodeName = getProperty<std::string>("RobotRootNodeName").getValue();
51
52 simulatorPrxName = getProperty<std::string>("SimulatorProxyName").getValue();
53
54 positionalAccuracy = 0.02f; //in m
55 orientationalAccuracy = 0.1f; //in rad
56
57 intervalMs = getProperty<int>("IntervalMs").getValue();
58 ARMARX_VERBOSE << "Starting RobotPose unit dynamic simulation with " << intervalMs
59 << " ms interval";
61 this,
64 false,
65 "RobotPoseUnitSimulation");
66 simulationTask->setDelayWarningTolerance(100);
67
68 if (!robotName.empty())
69 {
70 std::string robotTopicName = "Simulator_Robot_";
71 robotTopicName += robotName;
72 ARMARX_INFO << "Simulator Robot topic: " << robotTopicName;
73 usingTopic(robotTopicName);
74 }
75 else
76 {
77 ARMARX_WARNING << "No robot loaded...";
78 }
79
81
82 Eigen::Matrix4f m;
83 m.setIdentity();
84 currentPose = Pose(m);
85 targetPose = Pose(m);
86}
87
88void
90{
91 ARMARX_INFO << "Stopping RobotPose unit";
92 std::unique_lock lock(currentPoseMutex);
93 simulationTask->stop();
94 simulatorPrx = nullptr;
95}
96
97void
99{
100 RobotPoseControlMode = eUnknown;
101
102 ARMARX_INFO << "Using simulator proxy: " << simulatorPrxName;
104 PoseBasePtr p = simulatorPrx->getRobotPose(robotName);
107
108 simulationTask->start();
109}
110
111void
116
117void
119{
120 Eigen::Matrix4f m = Eigen::Matrix4f::Identity();
121 PosePtr p(new Pose(m));
122
123 moveRelative(p, 500, 500, current);
124}
125
126void
128{
129 // todo: implement velocity control....
130
131 {
132 std::unique_lock lock(currentPoseMutex);
133
134 if (!simulatorPrx)
135 {
136 return;
137 }
138 }
139}
140
141void
143 Ice::Float positionalAccuracy,
144 Ice::Float orientationalAccuracy,
145 const Ice::Current& c)
146{
147 std::unique_lock lock(currentPoseMutex);
148 RobotPoseControlMode = ePositionControl;
149 ARMARX_DEBUG << "RobotPose move to" << flush;
150 this->targetPose = *(PosePtr::dynamicCast(targetPose));
151 this->positionalAccuracy = positionalAccuracy * .001f;
152 this->orientationalAccuracy = orientationalAccuracy;
153 listenerPrx->begin_reportNewTargetPose(targetPose);
154 ARMARX_LOG << deactivateSpam(5) << "New Target: " << targetPose->position->x << " "
155 << targetPose->position->y << " " << targetPose->position->z;
156 if (simulatorPrx)
157 {
158 //simulatorPrx->begin_setRobotPose(robotName, targetPose);
159 simulatorPrx->setRobotPose(robotName, targetPose);
160 }
161}
162
163Eigen::Vector3f
165{
166 Eigen::Quaternionf q(QuaternionPtr::dynamicCast(pose->orientation)->toEigen());
167 Eigen::Matrix4f m = VirtualRobot::MathTools::quat2eigen4f(q.x(), q.y(), q.z(), q.w());
168 Eigen::Vector3f rpy;
169 VirtualRobot::MathTools::eigen4f2rpy(m, rpy);
170 return rpy;
171}
172
173void
174RobotPoseUnitDynamicSimulation::move(const PoseBasePtr& targetVelocity, const Ice::Current& c)
175{
176 std::unique_lock lock(currentPoseMutex);
177 ARMARX_INFO << deactivateSpam(1) << "NYI";
178}
179
180void
181RobotPoseUnitDynamicSimulation::moveRelative(const PoseBasePtr& relativeTarget,
182 float positionalAccuracy,
184 const Ice::Current& c)
185{
186 PosePtr p;
187 {
188 std::unique_lock lock(currentPoseMutex);
189 RobotPoseControlMode = ePositionControl;
190 Eigen::Matrix4f pose;
191 Eigen::Matrix4f cur = currentPose.toEigen();
192 Eigen::Matrix4f rel = PosePtr::dynamicCast(relativeTarget)->toEigen();
193 pose = cur * rel;
194 p = PosePtr(new Pose(pose));
195 ARMARX_DEBUG << "RobotPose move relative" << flush;
196 }
198}
199
200void
202 float angularVelocity,
203 const Ice::Current& c)
204{
205 //linearVelocityMax = linearVelocity;
206 //angularVelocityMax = angularVelocity;
207}
208
209void
211{
212 ARMARX_DEBUG << "Update new RobotPose pose" << flush;
213
214 if (!newPose)
215 {
216 return;
217 }
218
219 currentPose = *PosePtr::dynamicCast(newPose);
220}
221
222void
223RobotPoseUnitDynamicSimulation::reportState(SimulatedRobotState const& state, const Ice::Current&)
224{
225 setCurrentPose(state.pose);
226}
227
228void
230{
231 std::unique_lock lock(currentPoseMutex);
232 updateCurrentPose(newPose);
233 try
234 {
235 PosePtr p(new Pose(currentPose));
236 listenerPrx->begin_reportRobotPose(p);
237 }
238 catch (...)
239 {
240 }
241}
242
249
250std::string
252{
253 return "RobotPoseUnitDynamicSimulation";
254}
255
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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
This unit connects to the physics simulator topic (default: "Simulator") and handles RobotPose moveme...
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