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
37namespace armarx
38{
39 /**
40 * @class ATINetFTUnitPropertyDefinitions
41 * @brief
42 */
44 {
45 public:
47 {
49 "ATINetFTHostName",
50 "i61ATINetFT1:801",
51 "ATINetFT host name and port, usually i61ATINetFT1:801 or i61ATINetFT2:801");
53 "DatabasePathName", "", "Path name to motion database on receiving ATINetFT host");
55 "CaptureName", "Trial01", "Custom name of first trial in motion recording session");
57 "ATINetFTReceiveHostName",
58 "i61ATINetFT1:801",
59 "ATINetFT host name and port, usually i61ATINetFT1:801 or i61ATINetFT2:801");
61 "xOffset",
62 0.0f,
63 "Offset along x axis from VirtualRobot origin to ATINetFT reference marker");
65 "yOffset",
66 0.0f,
67 "Offset along y axis from VirtualRobot origin to ATINetFT reference marker");
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
constexpr T c
ATINetFTUnitPropertyDefinitions(std::string prefix)
ArmarX wrapper of the ATINetFT DataStream SDK.
void onInitComponent() override
void onDisconnectComponent() override
void stop(const Ice::Current &c) override
void request(const Ice::Current &c) override
void release(const Ice::Current &c) override
armarx::UnitExecutionState getExecutionState(const Ice::Current &c) override
void start(const Ice::Current &c) override
void stopRecording(const Ice::Current &c) override
bool isComponentOnline(const Ice::Current &c) override
void onConnectComponent() override
PropertyDefinitionsPtr createPropertyDefinitions() override
void startRecording(const std::string &customName, const Ice::Current &c) override
void init(const Ice::Current &c) override
void onExitComponent() override
std::string getDefaultName() const override
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.