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
26#include <SimoxUtility/algorithm/string/string_tools.h>
27
32
33using namespace armarx;
34
35void
37{
38 ARMARX_IMPORTANT << "onInitHapticUnit()";
40 this, &HapticUnitDynamicSimulation::frameAcquisitionTaskLoop);
41
42 std::string simPrxName = getProperty<std::string>("SimulatorName").getValue();
43 usingProxy(simPrxName);
44 robotNodeNames = getCommaSeparatedProperty("RobotNodes");
45 environmentObjectNames = getCommaSeparatedProperty("EnvironmentObjects");
46 robotName = getProperty<std::string>("RobotName").getValue();
47 offeringTopic("DebugDrawerUpdates");
48 ARMARX_IMPORTANT << "robotNodeNames: " << robotNodeNames;
49 ARMARX_IMPORTANT << "environmentObjectNames" << environmentObjectNames;
50}
51
52void
54{
55 std::string simPrxName = getProperty<std::string>("SimulatorName").getValue();
56 simulatorProxy = getProxy<SimulatorInterfacePrx>(simPrxName);
57 ARMARX_CHECK_EXPRESSION(simulatorProxy);
58
59 debugDrawerPrx = getTopic<DebugDrawerInterfacePrx>("DebugDrawerUpdates");
60
61 sensorTask->start();
62}
63
64void
69
76
77void
78HapticUnitDynamicSimulation::frameAcquisitionTaskLoop()
79{
80 while (!sensorTask->isStopped())
81 {
82 for (size_t i = 0; i < robotNodeNames.size(); i++)
83 {
84 //float minValue = 1e10;
85 std::string robotNodeName = robotNodeNames.at(i);
86
87 for (std::string objectName : environmentObjectNames)
88 {
89 DistanceInfo di = simulatorProxy->getDistance(robotName, robotNodeName, objectName);
90 ARMARX_IMPORTANT << "Distance between " << robotNodeName << " and " << objectName
91 << " = " << di.distance;
92 ARMARX_IMPORTANT << "p1:" << di.p1 << ", p2:" << di.p2;
93 debugDrawerPrx->setLineDebugLayerVisu(
94 robotNodeName + objectName, di.p1, di.p2, 5.0f, DrawColor{1, 0, 0, 1});
95 }
96 }
97
98 MatrixFloatPtr matrix = new MatrixFloat(7, 5); // y,x
100 (*matrix)(0, 0) = (now->getTimestamp() / 500) % 4096; // generate some sample data
101 (*matrix)(0, 1) = (now->getTimestamp() / 1000) % 4096; // generate some sample data
102 (*matrix)(0, 2) = (now->getTimestamp() / 2000) % 4096; // generate some sample data
103 hapticTopicPrx->reportSensorValues("/virtualdev/sensorA", "Left Index", matrix, now);
105 }
106}
107
108std::vector<std::string>
109HapticUnitDynamicSimulation::getCommaSeparatedProperty(std::string propertyName)
110{
111 std::string strValue = getProperty<std::string>(propertyName).getValue();
112 std::vector<std::string> values = simox::alg::split(strValue, ",");
113
114 for (size_t i = 0; i < values.size(); i++)
115 {
116 simox::alg::trim(values.at(i));
117 }
118
119 return values;
120}
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