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 <filesystem>
29 
30 #include <boost/regex.hpp>
31 
32 
33 using namespace armarx;
34 
35 void
37 {
38 
39  std::vector<std::string> devices = getDevices();
40 
41  for (std::vector<std::string>::iterator it = devices.begin(); it != devices.end(); ++it)
42  {
44  *it, 20)); // minimumReportIntervalMs = 20, limit to maximum 50 frames/s
45  this->sensors.push_back(sensor);
46  }
47 
48  std::cout << "Connect Interfaces" << std::endl;
49 
50  for (std::vector<std::shared_ptr<WeissHapticSensor>>::iterator it = sensors.begin();
51  it != sensors.end();
52  ++it)
53  {
54  (*it)->connect();
55  }
56 }
57 
58 std::vector<std::string>
59 WeissHapticUnit::getDevices()
60 {
61  const std::string target_path("/dev/");
62  const boost::regex my_filter("ttyACM[0-9]+");
63 
64  std::vector<std::string> files;
65 
66  std::filesystem::directory_iterator end_itr; // Default ctor yields past-the-end
67 
68  for (std::filesystem::directory_iterator i(target_path); i != end_itr; ++i)
69  {
70  // Skip if not a file
71  //if( !std::filesystem::is_( i->status() ) ) continue;
72 
73  boost::smatch what;
74 
75  // Skip if no match
76  if (!boost::regex_match(i->path().filename().string(), what, my_filter))
77  {
78  continue;
79  }
80 
81 
82  // File matches, store it
83  files.push_back("/dev/" + i->path().filename().string());
84  }
85 
86  std::sort(files.begin(), files.end());
87 
88  if (files.size() == 0)
89  {
90  ARMARX_WARNING << "No ACM-Interfaces found";
91  }
92  else
93  {
94  ARMARX_INFO << "Detected ACM-Interfaces: " << files.size();
95 
96  for (std::string file : files)
97  {
98  ARMARX_INFO << "Found device: " << file;
99  }
100  }
101 
102  return files;
103 }
104 
105 void
106 WeissHapticUnit::setDeviceTag(const std::string& deviceName,
107  const std::string& tag,
108  const Ice::Current&)
109 {
110  for (WeissHapticSensorPtr sensor : sensors)
111  {
112  if (sensor->getDeviceName() == deviceName)
113  {
114  ARMARX_IMPORTANT << "scheduling to set new device tag for " << deviceName << ": "
115  << tag;
116  sensor->scheduleSetDeviceTag(tag);
117  return;
118  }
119  }
120 
121  ARMARX_WARNING << "device not found: " << deviceName;
122 }
123 
124 void
125 WeissHapticUnit::startLogging(const Ice::Current&)
126 {
127  // @@@ TODO NotImplemented
128 }
129 
130 void
131 WeissHapticUnit::stopLogging(const Ice::Current&)
132 {
133  // @@@ TODO NotImplemented
134 }
135 
136 void
138 {
139 
140  for (std::vector<std::shared_ptr<WeissHapticSensor>>::iterator it = sensors.begin();
141  it != sensors.end();
142  ++it)
143  {
144  (*it)->setListenerPrx(hapticTopicPrx);
145  (*it)->startSampling();
146  }
147 }
148 
149 void
151 {
152  for (std::vector<std::shared_ptr<WeissHapticSensor>>::iterator it = sensors.begin();
153  it != sensors.end();
154  ++it)
155  {
156  (*it)->disconnect();
157  }
158 }
159 
160 /*void WeissHapticUnit::onConnectComponent()
161 {
162 
163 }*/
164 
165 void
167 {
168 }
169 
172 {
174 }
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:125
armarx::WeissHapticUnit::onStartHapticUnit
void onStartHapticUnit() override
Definition: WeissHapticUnit.cpp:137
armarx::HapticUnit::hapticTopicPrx
HapticUnitListenerPrx hapticTopicPrx
Definition: HapticUnit.h:82
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::WeissHapticUnit::onExitHapticUnit
void onExitHapticUnit() override
Definition: WeissHapticUnit.cpp:150
armarx::WeissHapticUnitPropertyDefinitions
Definition: WeissHapticUnit.h:39
armarx::WeissHapticUnit::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: WeissHapticUnit.cpp:166
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:106
armarx::WeissHapticUnit::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: WeissHapticUnit.cpp:171
armarx::WeissHapticUnit::onInitHapticUnit
void onInitHapticUnit() override
Definition: WeissHapticUnit.cpp:36
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::Logging::tag
LogTag tag
Definition: Logging.h:278
armarx::WeissHapticSensor
Definition: WeissHapticSensor.h:48
armarx::WeissHapticUnit::stopLogging
void stopLogging(const Ice::Current &) override
Definition: WeissHapticUnit.cpp:131
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27