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