ATINetFTUnit.h
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 VisionX::ArmarXObjects::ATINetFTUnit
19  * @author Jonas Rauber ( kit at jonasrauber dot de )
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 
28 #include <fstream>
29 
30 #include <netinet/in.h>
31 
33 
34 #include <RobotAPI/interface/units/ATINetFTUnit.h>
35 #include <RobotAPI/interface/units/UnitInterface.h>
36 
37 namespace armarx
38 {
39  /**
40  * @class ATINetFTUnitPropertyDefinitions
41  * @brief
42  */
44  {
45  public:
47  {
48  defineOptionalProperty<std::string>(
49  "ATINetFTHostName",
50  "i61ATINetFT1:801",
51  "ATINetFT host name and port, usually i61ATINetFT1:801 or i61ATINetFT2:801");
52  defineOptionalProperty<std::string>(
53  "DatabasePathName", "", "Path name to motion database on receiving ATINetFT host");
54  defineOptionalProperty<std::string>(
55  "CaptureName", "Trial01", "Custom name of first trial in motion recording session");
56  defineOptionalProperty<std::string>(
57  "ATINetFTReceiveHostName",
58  "i61ATINetFT1:801",
59  "ATINetFT host name and port, usually i61ATINetFT1:801 or i61ATINetFT2:801");
60  defineOptionalProperty<float>(
61  "xOffset",
62  0.0f,
63  "Offset along x axis from VirtualRobot origin to ATINetFT reference marker");
64  defineOptionalProperty<float>(
65  "yOffset",
66  0.0f,
67  "Offset along y axis from VirtualRobot origin to ATINetFT reference marker");
68  defineOptionalProperty<float>(
69  "zOffset",
70  0.0f,
71  "Offset along z axis from VirtualRobot origin to ATINetFT reference marker");
72  }
73  };
74 
75  /**
76  * @class ATINetFTUnit
77  * @ingroup VisionX-Components
78  * @brief ArmarX wrapper of the ATINetFT DataStream SDK
79  *
80  * Documentation mainly uses the term subject instead of object, as that's the
81  * common term in the context of ATINetFT.
82  */
83  class ATINetFTUnit : virtual public armarx::Component, virtual public ATINetFTUnitInterface
84  {
85  public:
86  /**
87  * @see armarx::ManagedIceObject::getDefaultName()
88  */
89  std::string
90  getDefaultName() const override
91  {
92  return "ATINetFTUnit";
93  }
94 
95  void startRecording(const std::string& customName, const Ice::Current& c) override;
96 
97 
98  void stopRecording(const Ice::Current& c) override;
99 
100  bool
101  isComponentOnline(const Ice::Current& c) override
102  {
103  return remoteTriggerEnabled;
104  };
105 
106  void request(const Ice::Current& c) override{};
107 
108  void
109  release(const Ice::Current& c) override
110  {
111  }
112 
113  void
114  init(const Ice::Current& c) override
115  {
116  }
117 
118  void
119  start(const Ice::Current& c) override
120  {
121  }
122 
123  void
124  stop(const Ice::Current& c) override
125  {
126  }
127 
128  armarx::UnitExecutionState
129  getExecutionState(const Ice::Current& c) override
130  {
131  return armarx::eUndefinedUnitExecutionState;
132  }
133 
134  protected:
135  /**
136  * @see armarx::ManagedIceObject::onInitComponent()
137  */
138  void onInitComponent() override;
139 
140  /**
141  * @see armarx::ManagedIceObject::onConnectComponent()
142  */
143  void onConnectComponent() override;
144 
145  /**
146  * @see armarx::ManagedIceObject::onDisconnectComponent()
147  */
148  void onDisconnectComponent() override;
149 
150  /**
151  * @see armarx::ManagedIceObject::onExitComponent()
152  */
153  void onExitComponent() override;
154 
155  /**
156  * @see PropertyUser::createPropertyDefinitions()
157  */
159 
160 
161  private:
162  /**
163  * The ATINetFT DataStream SDK Client
164  */
165 
166 
167  void periodicExec();
168  void establishATINetFTReceiveHostConnection(std::string receiverHostName);
169  bool sendPacket(char* bytePacket, int bpSize);
170  bool receivePacket(char* bytePacket);
171  void convertToFTValues(char* receiveBuf, float* ftdata, int ftdataSize);
172  void writeFTValuesToFile(float* ftdata, int ftdataSize);
173 
174  std::ofstream recordingFile;
175 
176  bool remoteTriggerEnabled;
177  bool recordingStarted;
178  bool recordingStopped;
179  bool recordingCompleted;
180 
181  int packetID;
182  int ftDataSize;
183  int sendPacketSize;
184  int receivePacketSize;
185  int captureNumber;
186  int senderSocket;
187  int nPaddingZeros;
188  int sampleIndex;
189 
190  std::string captureNamePrefix;
191  std::string databasePathName;
192  struct sockaddr_in receiveHostAddr;
193  struct sockaddr_in senderHostAddr;
194  };
195 } // namespace armarx
armarx::ATINetFTUnit::startRecording
void startRecording(const std::string &customName, const Ice::Current &c) override
Definition: ATINetFTUnit.cpp:140
armarx::ATINetFTUnit::start
void start(const Ice::Current &c) override
Definition: ATINetFTUnit.h:119
armarx::ATINetFTUnit::release
void release(const Ice::Current &c) override
Definition: ATINetFTUnit.h:109
armarx::ATINetFTUnit::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ATINetFTUnit.cpp:134
armarx::ATINetFTUnit::onInitComponent
void onInitComponent() override
Definition: ATINetFTUnit.cpp:42
armarx::ATINetFTUnit::onDisconnectComponent
void onDisconnectComponent() override
Definition: ATINetFTUnit.cpp:99
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
armarx::ATINetFTUnit::onExitComponent
void onExitComponent() override
Definition: ATINetFTUnit.cpp:105
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::ATINetFTUnit::getExecutionState
armarx::UnitExecutionState getExecutionState(const Ice::Current &c) override
Definition: ATINetFTUnit.h:129
armarx::ATINetFTUnit
ArmarX wrapper of the ATINetFT DataStream SDK.
Definition: ATINetFTUnit.h:83
armarx::ATINetFTUnit::isComponentOnline
bool isComponentOnline(const Ice::Current &c) override
Definition: ATINetFTUnit.h:101
armarx::ATINetFTUnit::onConnectComponent
void onConnectComponent() override
Definition: ATINetFTUnit.cpp:47
armarx::ATINetFTUnitPropertyDefinitions
Definition: ATINetFTUnit.h:43
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::ATINetFTUnit::stopRecording
void stopRecording(const Ice::Current &c) override
Definition: ATINetFTUnit.cpp:167
armarx::ATINetFTUnitPropertyDefinitions::ATINetFTUnitPropertyDefinitions
ATINetFTUnitPropertyDefinitions(std::string prefix)
Definition: ATINetFTUnit.h:46
armarx::ATINetFTUnit::getDefaultName
std::string getDefaultName() const override
Definition: ATINetFTUnit.h:90
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
armarx::ATINetFTUnit::init
void init(const Ice::Current &c) override
Definition: ATINetFTUnit.h:114
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::ATINetFTUnit::stop
void stop(const Ice::Current &c) override
Definition: ATINetFTUnit.h:124
armarx::ATINetFTUnit::request
void request(const Ice::Current &c) override
Definition: ATINetFTUnit.h:106
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27