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 
31 
32 #include <SimoxUtility/algorithm/string/string_tools.h>
33 
34 using namespace armarx;
35 
36 
38 {
39  ARMARX_IMPORTANT << "onInitHapticUnit()";
40  sensorTask = new RunningTask<HapticUnitDynamicSimulation>(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 
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 
65 {
66  sensorTask->stop();
67 }
68 
70 {
72 }
73 
74 void HapticUnitDynamicSimulation::frameAcquisitionTaskLoop()
75 {
76  while (!sensorTask->isStopped())
77  {
78  for (size_t i = 0; i < robotNodeNames.size(); i++)
79  {
80  //float minValue = 1e10;
81  std::string robotNodeName = robotNodeNames.at(i);
82 
83  for (std::string objectName : environmentObjectNames)
84  {
85  DistanceInfo di = simulatorProxy->getDistance(robotName, robotNodeName, objectName);
86  ARMARX_IMPORTANT << "Distance between " << robotNodeName << " and " << objectName << " = " << di.distance;
87  ARMARX_IMPORTANT << "p1:" << di.p1 << ", p2:" << di.p2;
88  debugDrawerPrx->setLineDebugLayerVisu(robotNodeName + objectName, di.p1, di.p2, 5.0f, DrawColor {1, 0, 0, 1});
89  }
90  }
91 
92  MatrixFloatPtr matrix = new MatrixFloat(7, 5); // y,x
94  (*matrix)(0, 0) = (now->getTimestamp() / 500) % 4096; // generate some sample data
95  (*matrix)(0, 1) = (now->getTimestamp() / 1000) % 4096; // generate some sample data
96  (*matrix)(0, 2) = (now->getTimestamp() / 2000) % 4096; // generate some sample data
97  hapticTopicPrx->reportSensorValues("/virtualdev/sensorA", "Left Index", matrix, now);
99  }
100 }
101 
102 std::vector<std::string> HapticUnitDynamicSimulation::getCommaSeparatedProperty(std::string propertyName)
103 {
104  std::string strValue = getProperty<std::string>(propertyName).getValue();
105  std::vector<std::string> values = simox::alg::split(strValue, ",");
106 
107  for (size_t i = 0; i < values.size(); i++)
108  {
109  simox::alg::trim(values.at(i));
110  }
111 
112  return values;
113 }
armarx::HapticUnit::hapticTopicPrx
HapticUnitListenerPrx hapticTopicPrx
Definition: HapticUnit.h:83
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::HapticUnitDynamicSimulation::onStartHapticUnit
void onStartHapticUnit() override
Definition: HapticUnitDynamicSimulation.cpp:53
MatrixVariant.h
armarx::HapticUnitDynamicSimulation::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: HapticUnitDynamicSimulation.cpp:69
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:94
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::TimestampVariant::nowPtr
static TimestampVariantPtr nowPtr()
Definition: TimestampVariant.h:111
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::HapticUnitDynamicSimulation::onExitHapticUnit
void onExitHapticUnit() override
Definition: HapticUnitDynamicSimulation.cpp:64
TimestampVariant.h
armarx::HapticUnitDynamicSimulation::onInitHapticUnit
void onInitHapticUnit() override
Definition: HapticUnitDynamicSimulation.cpp:37
ExpressionException.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
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:36
IceUtil::Handle< class PropertyDefinitionContainer >
HapticUnitDynamicSimulation.h
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::HapticUnitDynamicSimulationPropertyDefinitions
Definition: HapticUnitDynamicSimulation.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36