WeissHapticSensorTest.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-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 RobotAPI::WeissHapticGroup
19  * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "WeissHapticSensorTest.h"
26 
29 
31 
32 using namespace armarx;
33 using namespace WeissHapticGroup;
34 
35 //// DO NOT EDIT NEXT LINE
36 WeissHapticSensorTest::SubClassRegistry WeissHapticSensorTest::Registry(WeissHapticSensorTest::GetName(), &WeissHapticSensorTest::CreateInstance);
37 
38 
39 
41  XMLStateTemplate<WeissHapticSensorTest>(stateData), WeissHapticSensorTestGeneratedBase<WeissHapticSensorTest>(stateData)
42 {
43 }
44 
45 
47 {
48  HapticUnitObserverInterfacePrx hapticObserver = getHapticObserver();
49  ChannelRegistry channels = hapticObserver->getAvailableChannels(false);
50  std::map<std::string, DatafieldRefPtr> tactileDatafields_MaximumValueMap;
51 
52  if (channels.size() == 0)
53  {
54  ARMARX_WARNING << "No tactile pads found";
55  }
56  else
57  {
58  ARMARX_INFO << "Creating tactile channels";
59 
60  for (std::pair<std::string, ChannelRegistryEntry> pair : channels)
61  {
62  std::string tactilePad = pair.first;
63  DatafieldRefBasePtr matrixDatafield = new DatafieldRef(hapticObserver, tactilePad, "matrix");
64  DatafieldRefBasePtr matrixNulled = hapticObserver->createFilteredDatafield(DatafieldFilterBasePtr(new filters::OffsetFilter()), matrixDatafield);
65  DatafieldRefBasePtr matrixMax = hapticObserver->createFilteredDatafield(DatafieldFilterBasePtr(new filters::MatrixMaxFilter()), matrixNulled);
66  tactileDatafields_MaximumValueMap.insert(std::make_pair(tactilePad, DatafieldRefPtr::dynamicCast(matrixMax)));
67  }
68  }
69 
70  local.setTactileDatafields_MaximumValue(tactileDatafields_MaximumValueMap);
71 
72 
73 }
74 
76 {
77  std::map<std::string, DatafieldRefPtr> tactileDatafields_MaximumValueMap = local.getTactileDatafields_MaximumValue();
78 
79  while (!isRunningTaskStopped()) // stop run function if returning true
80  {
81  std::stringstream ss;
82  std::stringstream ssNames;
83  int max = 0;
84 
85  for (std::pair<std::string, DatafieldRefPtr> pair : tactileDatafields_MaximumValueMap)
86  {
87  std::string tactilePad = pair.first;
88  DatafieldRefPtr matrixMax = pair.second;
89  int padMax = (int)matrixMax->getDataField()->getFloat();
90  ss << padMax << "; ";
91  ssNames << tactilePad << "; ";
92  max = std::max(max, padMax);
93  }
94 
95  ARMARX_IMPORTANT << "tactile max value: " << max << "; \n\n" << ss.str() << "\n" << ssNames.str();
96 
97  usleep(10000); // 100ms
98  }
99 
100 }
101 
103 {
104  // put your user code for the breaking point here
105  // execution time should be short (<100ms)
106 }
107 
109 {
110  // put your user code for the exit point here
111  // execution time should be short (<100ms)
112 
113 }
114 
115 // DO NOT EDIT NEXT FUNCTION
117 {
118  return XMLStateFactoryBasePtr(new WeissHapticSensorTest(stateData));
119 }
120 
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::filters::MatrixMaxFilter
Definition: MatrixFilters.h:36
armarx::WeissHapticGroup::WeissHapticSensorTest::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: WeissHapticSensorTest.cpp:116
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
armarx::WeissHapticGroup::WeissHapticSensorTest::WeissHapticSensorTest
WeissHapticSensorTest(const XMLStateConstructorParams &stateData)
Definition: WeissHapticSensorTest.cpp:40
armarx::filters::OffsetFilter
The OffsetFilter class returns values relative to value from the first call of the filter....
Definition: OffsetFilter.h:41
MatrixFilters.h
IceInternal::Handle< DatafieldRef >
DatafieldRef.h
WeissHapticSensorTest.h
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::WeissHapticGroup::WeissHapticSensorTest::onBreak
void onBreak() override
Definition: WeissHapticSensorTest.cpp:102
armarx::WeissHapticGroup::WeissHapticSensorTest
Definition: WeissHapticSensorTest.h:30
max
T max(T t1, T t2)
Definition: gdiam.h:48
OffsetFilter.h
armarx::VariantType::DatafieldRef
const VariantTypeId DatafieldRef
Definition: DatafieldRef.h:169
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::WeissHapticGroup::WeissHapticSensorTest::run
void run() override
Definition: WeissHapticSensorTest.cpp:75
armarx::WeissHapticGroup::WeissHapticSensorTest::Registry
static SubClassRegistry Registry
Definition: WeissHapticSensorTest.h:44
armarx::WeissHapticGroup::WeissHapticSensorTest::onExit
void onExit() override
Definition: WeissHapticSensorTest.cpp:108
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::WeissHapticGroup::WeissHapticSensorTest::onEnter
void onEnter() override
Definition: WeissHapticSensorTest.cpp:46