HapticUnitDynamicSimulation.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-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
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
25
27
28#include <SimoxUtility/algorithm/string/string_tools.h>
29
34
35using namespace armarx;
36
37void
39{
40 ARMARX_IMPORTANT << "onInitHapticUnit()";
42 this, &HapticUnitDynamicSimulation::frameAcquisitionTaskLoop);
43
44 std::string simPrxName = getProperty<std::string>("SimulatorName").getValue();
45 usingProxy(simPrxName);
46 robotNodeNames = getCommaSeparatedProperty("RobotNodes");
47 environmentObjectNames = getCommaSeparatedProperty("EnvironmentObjects");
48 robotName = getProperty<std::string>("RobotName").getValue();
49 offeringTopic("DebugDrawerUpdates");
50 ARMARX_IMPORTANT << "robotNodeNames: " << robotNodeNames;
51 ARMARX_IMPORTANT << "environmentObjectNames" << environmentObjectNames;
52}
53
54void
56{
57 std::string simPrxName = getProperty<std::string>("SimulatorName").getValue();
58 simulatorProxy = getProxy<SimulatorInterfacePrx>(simPrxName);
59 ARMARX_CHECK_EXPRESSION(simulatorProxy);
60
61 debugDrawerPrx = getTopic<DebugDrawerInterfacePrx>("DebugDrawerUpdates");
62
63 sensorTask->start();
64}
65
66void
71
78
79void
80HapticUnitDynamicSimulation::frameAcquisitionTaskLoop()
81{
82 while (!sensorTask->isStopped())
83 {
84 for (size_t i = 0; i < robotNodeNames.size(); i++)
85 {
86 //float minValue = 1e10;
87 std::string robotNodeName = robotNodeNames.at(i);
88
89 for (std::string objectName : environmentObjectNames)
90 {
91 DistanceInfo di = simulatorProxy->getDistance(robotName, robotNodeName, objectName);
92 ARMARX_IMPORTANT << "Distance between " << robotNodeName << " and " << objectName
93 << " = " << di.distance;
94 ARMARX_IMPORTANT << "p1:" << di.p1 << ", p2:" << di.p2;
95 debugDrawerPrx->setLineDebugLayerVisu(
96 robotNodeName + objectName, di.p1, di.p2, 5.0f, DrawColor{1, 0, 0, 1});
97 }
98 }
99
100 MatrixFloatPtr matrix = new MatrixFloat(7, 5); // y,x
102 (*matrix)(0, 0) = (now->getTimestamp() / 500) % 4096; // generate some sample data
103 (*matrix)(0, 1) = (now->getTimestamp() / 1000) % 4096; // generate some sample data
104 (*matrix)(0, 2) = (now->getTimestamp() / 2000) % 4096; // generate some sample data
105 hapticTopicPrx->reportSensorValues("/virtualdev/sensorA", "Left Index", matrix, now);
107 }
108}
109
110std::vector<std::string>
111HapticUnitDynamicSimulation::getCommaSeparatedProperty(std::string propertyName)
112{
113 std::string strValue = getProperty<std::string>(propertyName).getValue();
114 std::vector<std::string> values = simox::alg::split(strValue, ",");
115
116 for (size_t i = 0; i < values.size(); i++)
117 {
118 simox::alg::trim(values.at(i));
119 }
120
121 return values;
122}
123
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
PropertyDefinitionsPtr createPropertyDefinitions() override
HapticUnitListenerPrx hapticTopicPrx
Definition HapticUnit.h:82
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition TimeUtil.cpp:100
static TimestampVariantPtr nowPtr()
#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_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
const VariantTypeId MatrixFloat
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< MatrixFloat > MatrixFloatPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< TimestampVariant > TimestampVariantPtr