DHParameterOptimizationLogger.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotComponents::ArmarXObjects::DHParameterOptimizationLogger
17  * @author Stefan Reither ( stef dot reither at web dot de )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
30 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
31 
32 #include <RobotComponents/interface/components/ViconMarkerProviderInterface.h>
33 #include <RobotComponents/interface/components/DHParameterOptimizationLoggerInterface.h>
34 
35 #include <mutex>
36 
37 namespace armarx
38 {
39  /**
40  * @class DHParameterOptimizationLoggerPropertyDefinitions
41  * @brief
42  */
45  {
46  public:
49  {
50  defineOptionalProperty<std::string>("ViconDataTopicName", "ViconDataUpdates", "Topic on which the marker data is published by the ViconMarkerProvider");
51  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent");
52  defineOptionalProperty<std::string>("RobotUnitObserverName", "RobotUnitObserver", "Name of the RobotUnitObserver");
53  defineOptionalProperty<std::string>("LoggingFilePath", "~/home/DHLogging", "Path to the logging file");
54  defineOptionalProperty<std::string>("DebugObserverTopicName", "DebugObserver", "The topic where updates are send to");
55  defineOptionalProperty<int>("FilterWindowSize", 100, "Window size of average filter applied to vicon marker positions.");
56  defineRequiredProperty<std::string>("Neck_ViconObjectName", "Name of the object for the neck marker that is used in the vicon system. "
57  "This is needed to parse the data received from the vicon system correctly.");
58  defineRequiredProperty<std::string>("Hand_ViconObjectName", "Name of the object for the hand marker that is used in the vicon system. "
59  "This is needed to parse the data received from the vicon system correctly.");
60  }
61  };
62 
63  /**
64  * @defgroup Component-DHParameterOptimizationLogger DHParameterOptimizationLogger
65  * @ingroup RobotComponents-Components
66  * A description of the component DHParameterOptimizationLogger.
67  *
68  * @class DHParameterOptimizationLogger
69  * @ingroup Component-DHParameterOptimizationLogger
70  * @brief Brief description of class DHParameterOptimizationLogger.
71  *
72  * Detailed description of class DHParameterOptimizationLogger.
73  */
75  virtual public armarx::Component,
76  virtual public DHParameterOptimizationLoggerInterface
77  {
78  public:
79  /**
80  * @see armarx::ManagedIceObject::getDefaultName()
81  */
82  std::string getDefaultName() const override
83  {
84  return "DHParameterOptimizationLogger";
85  }
86 
87  // DHParameterOptimizationLoggerInterface interface
88  /**
89  * @brief logData logs data for the current position. Blocks until as many vicon data frames as specified by the property "FilterWindowSize" were received.
90  */
91  void logData(const Ice::Current& = Ice::emptyCurrent) override;
92  void logDataWithRepeatAccuracy(const Ice::Current& = Ice::emptyCurrent) override;
93  void startViconLogging(const Ice::Current& = Ice::emptyCurrent) override;
94  void stopViconLogging(const Ice::Current& = Ice::emptyCurrent) override;
95  void init(const std::string& kinematicChainName,
96  const std::map<std::string, std::string>& neckMarkerMapping,
97  const std::map<std::string, std::string>& handMarkerMapping,
98  const std::string& loggingFileName,
99  bool logRepeatAccuracy,
100  const Ice::Current& = Ice::emptyCurrent) override;
101  protected:
102  /**
103  * @see armarx::ManagedIceObject::onInitComponent()
104  */
105  void onInitComponent() override;
106 
107  /**
108  * @see armarx::ManagedIceObject::onConnectComponent()
109  */
110  void onConnectComponent() override;
111 
112  /**
113  * @see armarx::ManagedIceObject::onDisconnectComponent()
114  */
115  void onDisconnectComponent() override;
116 
117  /**
118  * @see armarx::ManagedIceObject::onExitComponent()
119  */
120  void onExitComponent() override;
121 
122  /**
123  * @see PropertyUser::createPropertyDefinitions()
124  */
126 
127  // ViconMarkerProviderListenerInterface interface
128  void reportLabeledViconMarkerFrame(const StringVector3fMap& markerPosMap, const Ice::Current& = Ice::emptyCurrent) override;
129  void reportUnlabeledViconMarkerFrame(const Vector3fSeq& markerPos, const Ice::Current& = Ice::emptyCurrent) override;
130 
131  private:
132  RobotStateComponentInterfacePrx robotStateComponent;
133  VirtualRobot::RobotPtr localRobot;
134  ObserverInterfacePrx robotUnitObserver;
135  DebugObserverInterfacePrx debugObserverPrx;
136  DebugDrawerInterfacePrx debugDrawerPrx;
137 
138  std::string _filePath;
139  void setupFile(const std::string& fileName);
140  NameList _header;
141  void setupHeader();
142  bool _initialized;
143 
144  StringVector3fMap _viconMarkerBuffer;
145  bool _viconBufferUpdated;
146  StringVector3fMap _filteredViconMarkerPositions_robotRootFrame;
147  bool _filteredViconMarkerPositionsUpdated;
148  IceUtil::Time _timeStampLastViconDataUpdate;
149  mutable std::mutex _bufferMutex;
150  bool _viconLoggingActive;
151  size_t _filterSize;
152 
153  void logData(std::vector<float>& data);
154  void logViconMarkerPositions(std::vector<float>& data);
155  void logJointValues(std::vector<float>& data) const;
156  void logForwardKinematicToViconMarker(std::vector<float>& data) const;
157  void logErrorBetweenModelAndVicon(std::vector<float>& data);
158  void logRawTorqueTicks(std::vector<float>& data) const;
159  void logTorqueValues(std::vector<float>& data) const;
160  // void logRawFTSensorTicks(std::vector<float>& data) const;
161  void logFTSensorValues(std::vector<float>& data) const;
162 
163  StringVector3fMap waitBlockingForAllMarkersFiltered();
164 
165  std::string _kcName;
166  VirtualRobot::RobotNodeSetPtr _kc;
167  NameList _jointNames;
168  NameList _neckMarker;
169  NameList _handMarker;
170  std::map<std::string, std::string> _neckMarkerMapping;
171  std::map<std::string, std::string> _handMarkerMapping;
172  VirtualRobot::RobotNodePtr getNeckMarkerRootNode() const;
173  VirtualRobot::RobotNodePtr getHandMarkerRootNode() const;
174  std::string _viconObjectName_neck;
175  std::string _viconObjectName_hand;
176 
177  bool _logRepeatAccuracy;
178  Eigen::Matrix4f _lastObservedHandRootPose;
179  Eigen::Matrix4f _newObservedHandRootPose;
180  bool _observedHandPosesUpdated;
181  std::pair<float, float> calculateRepeatError();
182 
183  Eigen::Matrix4f registration3d(const Eigen::MatrixXf& matrixA, const Eigen::MatrixXf& matrixB) const;
184  StringVector3fMap transformViconMarkerPositionsIntoRobotRootFrame(const StringVector3fMap& values) const;
185  };
186 }
armarx::DHParameterOptimizationLogger::logDataWithRepeatAccuracy
void logDataWithRepeatAccuracy(const Ice::Current &=Ice::emptyCurrent) override
Definition: DHParameterOptimizationLogger.cpp:63
RemoteRobot.h
armarx::DHParameterOptimizationLogger::logData
void logData(const Ice::Current &=Ice::emptyCurrent) override
logData logs data for the current position.
Definition: DHParameterOptimizationLogger.cpp:44
AverageFilter.h
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
CsvWriter.h
Observer.h
armarx::DHParameterOptimizationLogger::init
void init(const std::string &kinematicChainName, const std::map< std::string, std::string > &neckMarkerMapping, const std::map< std::string, std::string > &handMarkerMapping, const std::string &loggingFileName, bool logRepeatAccuracy, const Ice::Current &=Ice::emptyCurrent) override
Definition: DHParameterOptimizationLogger.cpp:101
armarx::DHParameterOptimizationLoggerPropertyDefinitions::DHParameterOptimizationLoggerPropertyDefinitions
DHParameterOptimizationLoggerPropertyDefinitions(std::string prefix)
Definition: DHParameterOptimizationLogger.h:47
armarx::DHParameterOptimizationLogger::onConnectComponent
void onConnectComponent() override
Definition: DHParameterOptimizationLogger.cpp:259
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::DHParameterOptimizationLogger::onInitComponent
void onInitComponent() override
Definition: DHParameterOptimizationLogger.cpp:242
armarx::DHParameterOptimizationLogger::startViconLogging
void startViconLogging(const Ice::Current &=Ice::emptyCurrent) override
Definition: DHParameterOptimizationLogger.cpp:91
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::DHParameterOptimizationLogger::onExitComponent
void onExitComponent() override
Definition: DHParameterOptimizationLogger.cpp:285
Component.h
armarx::DHParameterOptimizationLogger::reportUnlabeledViconMarkerFrame
void reportUnlabeledViconMarkerFrame(const Vector3fSeq &markerPos, const Ice::Current &=Ice::emptyCurrent) override
Definition: DHParameterOptimizationLogger.cpp:196
armarx::DHParameterOptimizationLogger::reportLabeledViconMarkerFrame
void reportLabeledViconMarkerFrame(const StringVector3fMap &markerPosMap, const Ice::Current &=Ice::emptyCurrent) override
Definition: DHParameterOptimizationLogger.cpp:169
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::DHParameterOptimizationLogger
Brief description of class DHParameterOptimizationLogger.
Definition: DHParameterOptimizationLogger.h:74
armarx::DHParameterOptimizationLogger::onDisconnectComponent
void onDisconnectComponent() override
Definition: DHParameterOptimizationLogger.cpp:279
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::DHParameterOptimizationLogger::getDefaultName
std::string getDefaultName() const override
Definition: DHParameterOptimizationLogger.h:82
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::DHParameterOptimizationLogger::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: DHParameterOptimizationLogger.cpp:290
armarx::DHParameterOptimizationLoggerPropertyDefinitions
Definition: DHParameterOptimizationLogger.h:43
armarx::DHParameterOptimizationLogger::stopViconLogging
void stopViconLogging(const Ice::Current &=Ice::emptyCurrent) override
Definition: DHParameterOptimizationLogger.cpp:96
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18