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 
33 using namespace armarx;
34 
35 void
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 
52 void
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 
64 void
66 {
67  sensorTask->stop();
68 }
69 
72 {
75 }
76 
77 void
78 HapticUnitDynamicSimulation::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 
108 std::vector<std::string>
109 HapticUnitDynamicSimulation::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 }
armarx::HapticUnit::hapticTopicPrx
HapticUnitListenerPrx hapticTopicPrx
Definition: HapticUnit.h:82
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::HapticUnitDynamicSimulation::onStartHapticUnit
void onStartHapticUnit() override
Definition: HapticUnitDynamicSimulation.cpp:53
MatrixVariant.h
armarx::HapticUnitDynamicSimulation::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: HapticUnitDynamicSimulation.cpp:71
armarx::TimeUtil::MSSleep
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition: TimeUtil.cpp:100
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:36
armarx::TimestampVariant::nowPtr
static TimestampVariantPtr nowPtr()
Definition: TimestampVariant.h:126
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::HapticUnitDynamicSimulation::onExitHapticUnit
void onExitHapticUnit() override
Definition: HapticUnitDynamicSimulation.cpp:65
TimestampVariant.h
armarx::HapticUnitDynamicSimulation::onInitHapticUnit
void onInitHapticUnit() override
Definition: HapticUnitDynamicSimulation.cpp:36
ExpressionException.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
TimeUtil.h
armarx::VariantType::MatrixFloat
const VariantTypeId MatrixFloat
Definition: MatrixVariant.h:37
IceUtil::Handle< class PropertyDefinitionContainer >
HapticUnitDynamicSimulation.h
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::HapticUnitDynamicSimulationPropertyDefinitions
Definition: HapticUnitDynamicSimulation.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:38