WeissHapticUnit.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 as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @package ArmarXCore::units
20  * @author Peter Kaiser
21  * @date 2014
22  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
23  * GNU General Public License
24  */
25 
26 #include "WeissHapticUnit.h"
27 
28 #include <boost/regex.hpp>
29 #include <filesystem>
30 
31 
32 using namespace armarx;
33 
35 {
36 
37  std::vector<std::string> devices = getDevices();
38 
39  for (std::vector<std::string>::iterator it = devices.begin(); it != devices.end(); ++it)
40  {
41  WeissHapticSensorPtr sensor(new WeissHapticSensor(*it, 20)); // minimumReportIntervalMs = 20, limit to maximum 50 frames/s
42  this->sensors.push_back(sensor);
43  }
44 
45  std::cout << "Connect Interfaces" << std::endl;
46 
47  for (std::vector<std::shared_ptr<WeissHapticSensor> >::iterator it = sensors.begin(); it != sensors.end(); ++it)
48  {
49  (*it)->connect();
50  }
51 
52 }
53 
54 std::vector< std::string > WeissHapticUnit::getDevices()
55 {
56  const std::string target_path("/dev/");
57  const boost::regex my_filter("ttyACM[0-9]+");
58 
59  std::vector< std::string > files;
60 
61  std::filesystem::directory_iterator end_itr; // Default ctor yields past-the-end
62 
63  for (std::filesystem::directory_iterator i(target_path); i != end_itr; ++i)
64  {
65  // Skip if not a file
66  //if( !std::filesystem::is_( i->status() ) ) continue;
67 
68  boost::smatch what;
69 
70  // Skip if no match
71  if (!boost::regex_match(i->path().filename().string(), what, my_filter))
72  {
73  continue;
74  }
75 
76 
77  // File matches, store it
78  files.push_back("/dev/" + i->path().filename().string());
79  }
80 
81  std::sort(files.begin(), files.end());
82 
83  if (files.size() == 0)
84  {
85  ARMARX_WARNING << "No ACM-Interfaces found";
86  }
87  else
88  {
89  ARMARX_INFO << "Detected ACM-Interfaces: " << files.size();
90 
91  for (std::string file : files)
92  {
93  ARMARX_INFO << "Found device: " << file;
94  }
95  }
96 
97  return files;
98 }
99 
100 void WeissHapticUnit::setDeviceTag(const std::string& deviceName, const std::string& tag, const Ice::Current&)
101 {
102  for (WeissHapticSensorPtr sensor : sensors)
103  {
104  if (sensor->getDeviceName() == deviceName)
105  {
106  ARMARX_IMPORTANT << "scheduling to set new device tag for " << deviceName << ": " << tag;
107  sensor->scheduleSetDeviceTag(tag);
108  return;
109  }
110  }
111 
112  ARMARX_WARNING << "device not found: " << deviceName;
113 }
114 
115 void WeissHapticUnit::startLogging(const Ice::Current&)
116 {
117  // @@@ TODO NotImplemented
118 }
119 
120 void WeissHapticUnit::stopLogging(const Ice::Current&)
121 {
122  // @@@ TODO NotImplemented
123 }
124 
126 {
127 
128  for (std::vector<std::shared_ptr<WeissHapticSensor> >::iterator it = sensors.begin(); it != sensors.end(); ++it)
129  {
130  (*it)->setListenerPrx(hapticTopicPrx);
131  (*it)->startSampling();
132  }
133 
134 }
135 
137 {
138  for (std::vector<std::shared_ptr<WeissHapticSensor> >::iterator it = sensors.begin(); it != sensors.end(); ++it)
139  {
140  (*it)->disconnect();
141  }
142 }
143 
144 /*void WeissHapticUnit::onConnectComponent()
145 {
146 
147 }*/
148 
150 {
151 }
152 
153 
155 {
157 }
158 
files
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation files(the "Software")
armarx::WeissHapticUnit::startLogging
void startLogging(const Ice::Current &) override
Definition: WeissHapticUnit.cpp:115
armarx::WeissHapticUnit::onStartHapticUnit
void onStartHapticUnit() override
Definition: WeissHapticUnit.cpp:125
armarx::HapticUnit::hapticTopicPrx
HapticUnitListenerPrx hapticTopicPrx
Definition: HapticUnit.h:83
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::WeissHapticUnit::onExitHapticUnit
void onExitHapticUnit() override
Definition: WeissHapticUnit.cpp:136
armarx::WeissHapticUnitPropertyDefinitions
Definition: WeissHapticUnit.h:37
armarx::WeissHapticUnit::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: WeissHapticUnit.cpp:149
armarx::WeissHapticSensorPtr
std::shared_ptr< WeissHapticSensor > WeissHapticSensorPtr
Definition: WeissHapticSensor.h:46
WeissHapticUnit.h
armarx::WeissHapticUnit::setDeviceTag
void setDeviceTag(const std::string &deviceName, const std::string &tag, const Ice::Current &) override
Definition: WeissHapticUnit.cpp:100
armarx::WeissHapticUnit::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: WeissHapticUnit.cpp:154
armarx::WeissHapticUnit::onInitHapticUnit
void onInitHapticUnit() override
Definition: WeissHapticUnit.cpp:34
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::Logging::tag
LogTag tag
Definition: Logging.h:271
armarx::WeissHapticSensor
Definition: WeissHapticSensor.h:48
armarx::WeissHapticUnit::stopLogging
void stopLogging(const Ice::Current &) override
Definition: WeissHapticUnit.cpp:120
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28