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
33using namespace armarx;
34
35void
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
58std::vector<std::string>
59WeissHapticUnit::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
105void
106WeissHapticUnit::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
124void
126{
127 // @@@ TODO NotImplemented
128}
129
130void
132{
133 // @@@ TODO NotImplemented
134}
135
136void
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
149void
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
165void
169
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
HapticUnitListenerPrx hapticTopicPrx
Definition HapticUnit.h:82
void setDeviceTag(const std::string &deviceName, const std::string &tag, const Ice::Current &) override
void onExitHapticUnit() override
void onDisconnectComponent() override
Hook for subclass.
void onStartHapticUnit() override
PropertyDefinitionsPtr createPropertyDefinitions() override
void onInitHapticUnit() override
void startLogging(const Ice::Current &) override
void stopLogging(const Ice::Current &) override
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::shared_ptr< WeissHapticSensor > WeissHapticSensorPtr