ForceTorqueUnitDynamicSimulation.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 ArmarXCore::units
19 * @author nv
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27#include <SimoxUtility/algorithm/string/string_tools.h>
28
30
31using namespace armarx;
32
33void
35{
36 usingTopic("ForceTorqueDynamicSimulationValues");
37 agentName = getProperty<std::string>("AgentName").getValue();
38
39 std::string framesStr = getProperty<std::string>("ReportFrames").getValue();
40 frames = simox::alg::split(framesStr, ",;");
41 ARMARX_INFO << "ForceTorqueUnit initialized." << std::endl
42 << "AgentName: " << agentName << ". " << std::endl
43 << "Report Frames: " << frames;
44 auto sensorRobotNodeSplit =
45 armarx::Split(getProperty<std::string>("SensorRobotNodeMapping").getValue(), ",");
46 for (auto& elem : sensorRobotNodeSplit)
47 {
48 simox::alg::trim(elem);
49 std::vector<std::string> split = simox::alg::split(elem, ":");
50 if (split.size() == 2)
51 {
52 sensorRobotNodeMapping[simox::alg::trim_copy(split[0])] =
53 simox::alg::trim_copy(split[1]);
54 }
55 }
56 reportInSensorFrame = getProperty<bool>("ReportInSensorFrame").getValue();
57 usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
58}
59
60void
62{
63 ARMARX_INFO << "Starting ForceTorqueUnit, requesting robot from RobotStateComponent...";
64
65 try
66 {
67 RobotStateComponentInterfacePrx robotStateComponent =
69 getProperty<std::string>("RobotStateComponentName").getValue());
70 sharedRobot = robotStateComponent->getSynchronizedRobot();
72 }
73 catch (...)
74 {
76 terminate();
77 return;
78 }
79
80 for (auto& frame : frames)
81 {
82 if (!frame.empty() && !remoteRobot->hasRobotNode(frame))
83 {
84 ARMARX_WARNING << "Robot " << remoteRobot->getName() << " does not know report frame '"
85 << frame << "'. Will not report FT values in this frame...";
86 }
87 }
88}
89
90void
94
101
102void
104 const Vector3BasePtr& torque,
105 const std::string& sensorName,
106 const std::string& nodeName,
107 bool aValueChanged,
108 const Ice::Current& c)
109{
110 std::unique_lock lock(reportMutex);
111 Vector3Ptr f = Vector3Ptr::dynamicCast(filterValues(sensorName, force, forceFilters));
112 Vector3Ptr t = Vector3Ptr::dynamicCast(filterValues(sensorName, torque, torqueFilters));
113
114 FramedDirectionPtr framedForce = new FramedDirection(f->toEigen(), nodeName, agentName);
115 FramedDirectionPtr framedTorque = new FramedDirection(t->toEigen(), nodeName, agentName);
117 try
118 {
119 auto prx = listenerPrx->ice_batchOneway();
120 // if sensor is named as a robot node, we use the robot node as report frame
121 if (sensorName != nodeName && remoteRobot->hasRobotNode(sensorName))
122 {
123 framedForce->changeFrame(remoteRobot, sensorName);
124 framedTorque->changeFrame(remoteRobot, sensorName);
125 }
126
128 {
129 prx->reportSensorValues(sensorName, framedForce, framedTorque);
130 }
131
132 for (auto& frame : frames)
133 {
134 if (!frame.empty() && remoteRobot->hasRobotNode(frame))
135 {
136 FramedDirectionPtr framedForce1 =
137 new FramedDirection(f->toEigen(), nodeName, agentName);
138 FramedDirectionPtr framedTorque1 =
139 new FramedDirection(t->toEigen(), nodeName, agentName);
140 framedForce1->changeFrame(remoteRobot, frame);
141 framedTorque1->changeFrame(remoteRobot, frame);
142 prx->reportSensorValues(sensorName, framedForce1, framedTorque1);
143 }
144 }
145
146 auto it = sensorRobotNodeMapping.find(sensorName);
147 if (it != sensorRobotNodeMapping.end())
148 {
149 if (remoteRobot->hasRobotNode(it->second))
150 {
151 FramedDirectionPtr framedForce1 =
152 new FramedDirection(f->toEigen(), nodeName, agentName);
153 FramedDirectionPtr framedTorque1 =
154 new FramedDirection(t->toEigen(), nodeName, agentName);
155 framedForce1->changeFrame(remoteRobot, it->second);
156 framedTorque1->changeFrame(remoteRobot, it->second);
157 prx->reportSensorValues(it->second, framedForce1, framedTorque1);
158 ARMARX_DEBUG << deactivateSpam(1, it->second) << "Reporting " << it->second << ": "
159 << framedForce1->output() << "\n"
160 << framedTorque1->output();
161 }
162 else
163 {
164 ARMARX_WARNING << deactivateSpam(10000, it->second) << "Robot does not have node "
165 << it->second;
166 }
167 }
168 prx->ice_flushBatchRequests();
169 }
170 catch (...)
171 {
172 ARMARX_WARNING << deactivateSpam() << "Could not report FT vlaues:";
174 }
175}
176
177Vector3BasePtr
179 const std::string& sensorName,
180 const Vector3BasePtr& torques,
181 std::map<std::string, DatafieldFilterBasePtr>& filters)
182{
183 auto filter = [&, this](const std::string& dim, float value)
184 {
185 const auto name = sensorName + dim;
186 auto itX = filters.find(name);
187 if (itX == filters.end())
188 {
189 filters.insert(
190 std::make_pair(name, new filters::ButterworthFilter(2, 100, Lowpass, 1)));
191 itX = filters.find(name);
192 }
193 auto& filterX = *itX->second;
194 filterX.update(0, new Variant(value));
195 double r = filterX.getValue()->getDouble();
196 return r;
197 };
198
199
200 Vector3BasePtr result =
201 new Vector3(filter("x", torques->x), filter("y", torques->y), filter("z", torques->z));
202 return result;
203}
204
205void
206armarx::ForceTorqueUnitDynamicSimulation::setOffset(const armarx::FramedDirectionBasePtr&,
207 const armarx::FramedDirectionBasePtr&,
208 const Ice::Current&)
209{
210 ARMARX_INFO_S << "NYI";
211}
212
213void
215{
216 ARMARX_INFO_S << "NYI";
217}
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)
std::map< std::string, DatafieldFilterBasePtr > forceFilters
Vector3BasePtr filterValues(const std::string &sensorName, const Vector3BasePtr &torques, std::map< std::string, DatafieldFilterBasePtr > &filters)
void reportForceTorque(const Vector3BasePtr &force, const Vector3BasePtr &torque, const std::string &sensorName, const std::string &nodeName, bool aValueChanged, const Ice::Current &c=Ice::emptyCurrent) override
std::map< std::string, DatafieldFilterBasePtr > torqueFilters
void setOffset(const FramedDirectionBasePtr &, const FramedDirectionBasePtr &, const Ice::Current &) override
ForceTorqueUnitListenerPrx listenerPrx
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
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 terminate()
Initiates termination of this IceManagedObject.
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)
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
The Variant class is described here: Variants.
Definition Variant.h:224
The Vector3 class.
Definition Pose.h:113
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_INFO_S
Definition Logging.h:202
#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
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
void handleExceptions()
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceInternal::Handle< FramedDirection > FramedDirectionPtr
Definition FramedPose.h:84
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx