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
25#include <mutex>
26
31
32#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
34
35#include <RobotComponents/interface/components/DHParameterOptimizationLoggerInterface.h>
36#include <RobotComponents/interface/components/ViconMarkerProviderInterface.h>
37
38namespace armarx
39{
40 /**
41 * @class DHParameterOptimizationLoggerPropertyDefinitions
42 * @brief
43 */
46 {
47 public:
50 {
52 "ViconDataTopicName",
53 "ViconDataUpdates",
54 "Topic on which the marker data is published by the ViconMarkerProvider");
55 defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent");
57 "RobotUnitObserverName", "RobotUnitObserver", "Name of the RobotUnitObserver");
59 "LoggingFilePath", "~/home/DHLogging", "Path to the logging file");
61 "DebugObserverTopicName", "DebugObserver", "The topic where updates are send to");
63 "FilterWindowSize",
64 100,
65 "Window size of average filter applied to vicon marker positions.");
67 "Neck_ViconObjectName",
68 "Name of the object for the neck marker that is used in the vicon system. "
69 "This is needed to parse the data received from the vicon system correctly.");
71 "Hand_ViconObjectName",
72 "Name of the object for the hand marker that is used in the vicon system. "
73 "This is needed to parse the data received from the vicon system correctly.");
74 }
75 };
76
77 /**
78 * @defgroup Component-DHParameterOptimizationLogger DHParameterOptimizationLogger
79 * @ingroup RobotComponents-Components
80 * A description of the component DHParameterOptimizationLogger.
81 *
82 * @class DHParameterOptimizationLogger
83 * @ingroup Component-DHParameterOptimizationLogger
84 * @brief Brief description of class DHParameterOptimizationLogger.
85 *
86 * Detailed description of class DHParameterOptimizationLogger.
87 */
89 virtual public armarx::Component,
90 virtual public DHParameterOptimizationLoggerInterface
91 {
92 public:
93 /**
94 * @see armarx::ManagedIceObject::getDefaultName()
95 */
96 std::string
97 getDefaultName() const override
98 {
99 return "DHParameterOptimizationLogger";
100 }
101
102 // DHParameterOptimizationLoggerInterface interface
103 /**
104 * @brief logData logs data for the current position. Blocks until as many vicon data frames as specified by the property "FilterWindowSize" were received.
105 */
106 void logData(const Ice::Current& = Ice::emptyCurrent) override;
107 void logDataWithRepeatAccuracy(const Ice::Current& = Ice::emptyCurrent) override;
108 void startViconLogging(const Ice::Current& = Ice::emptyCurrent) override;
109 void stopViconLogging(const Ice::Current& = Ice::emptyCurrent) override;
110 void init(const std::string& kinematicChainName,
111 const std::map<std::string, std::string>& neckMarkerMapping,
112 const std::map<std::string, std::string>& handMarkerMapping,
113 const std::string& loggingFileName,
114 bool logRepeatAccuracy,
115 const Ice::Current& = Ice::emptyCurrent) override;
116
117 protected:
118 /**
119 * @see armarx::ManagedIceObject::onInitComponent()
120 */
121 void onInitComponent() override;
122
123 /**
124 * @see armarx::ManagedIceObject::onConnectComponent()
125 */
126 void onConnectComponent() override;
127
128 /**
129 * @see armarx::ManagedIceObject::onDisconnectComponent()
130 */
131 void onDisconnectComponent() override;
132
133 /**
134 * @see armarx::ManagedIceObject::onExitComponent()
135 */
136 void onExitComponent() override;
137
138 /**
139 * @see PropertyUser::createPropertyDefinitions()
140 */
142
143 // ViconMarkerProviderListenerInterface interface
144 void reportLabeledViconMarkerFrame(const StringVector3fMap& markerPosMap,
145 const Ice::Current& = Ice::emptyCurrent) override;
146 void reportUnlabeledViconMarkerFrame(const Vector3fSeq& markerPos,
147 const Ice::Current& = Ice::emptyCurrent) override;
148
149 private:
150 RobotStateComponentInterfacePrx robotStateComponent;
151 VirtualRobot::RobotPtr localRobot;
152 ObserverInterfacePrx robotUnitObserver;
153 DebugObserverInterfacePrx debugObserverPrx;
154 DebugDrawerInterfacePrx debugDrawerPrx;
155
156 std::string _filePath;
157 void setupFile(const std::string& fileName);
158 NameList _header;
159 void setupHeader();
160 bool _initialized;
161
162 StringVector3fMap _viconMarkerBuffer;
163 bool _viconBufferUpdated;
164 StringVector3fMap _filteredViconMarkerPositions_robotRootFrame;
165 bool _filteredViconMarkerPositionsUpdated;
166 IceUtil::Time _timeStampLastViconDataUpdate;
167 mutable std::mutex _bufferMutex;
168 bool _viconLoggingActive;
169 size_t _filterSize;
170
171 void logData(std::vector<float>& data);
172 void logViconMarkerPositions(std::vector<float>& data);
173 void logJointValues(std::vector<float>& data) const;
174 void logForwardKinematicToViconMarker(std::vector<float>& data) const;
175 void logErrorBetweenModelAndVicon(std::vector<float>& data);
176 void logRawTorqueTicks(std::vector<float>& data) const;
177 void logTorqueValues(std::vector<float>& data) const;
178 // void logRawFTSensorTicks(std::vector<float>& data) const;
179 void logFTSensorValues(std::vector<float>& data) const;
180
181 StringVector3fMap waitBlockingForAllMarkersFiltered();
182
183 std::string _kcName;
184 VirtualRobot::RobotNodeSetPtr _kc;
185 NameList _jointNames;
186 NameList _neckMarker;
187 NameList _handMarker;
188 std::map<std::string, std::string> _neckMarkerMapping;
189 std::map<std::string, std::string> _handMarkerMapping;
190 VirtualRobot::RobotNodePtr getNeckMarkerRootNode() const;
191 VirtualRobot::RobotNodePtr getHandMarkerRootNode() const;
192 std::string _viconObjectName_neck;
193 std::string _viconObjectName_hand;
194
195 bool _logRepeatAccuracy;
196 Eigen::Matrix4f _lastObservedHandRootPose;
197 Eigen::Matrix4f _newObservedHandRootPose;
198 bool _observedHandPosesUpdated;
199 std::pair<float, float> calculateRepeatError();
200
201 Eigen::Matrix4f registration3d(const Eigen::MatrixXf& matrixA,
202 const Eigen::MatrixXf& matrixB) const;
203 StringVector3fMap
204 transformViconMarkerPositionsIntoRobotRootFrame(const StringVector3fMap& values) const;
205 };
206} // namespace armarx
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
Brief description of class DHParameterOptimizationLogger.
void stopViconLogging(const Ice::Current &=Ice::emptyCurrent) override
void startViconLogging(const Ice::Current &=Ice::emptyCurrent) override
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
void reportLabeledViconMarkerFrame(const StringVector3fMap &markerPosMap, const Ice::Current &=Ice::emptyCurrent) override
void reportUnlabeledViconMarkerFrame(const Vector3fSeq &markerPos, const Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void logData(const Ice::Current &=Ice::emptyCurrent) override
logData logs data for the current position.
void logDataWithRepeatAccuracy(const Ice::Current &=Ice::emptyCurrent) override
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)
PropertyDefinition< PropertyType > & defineRequiredProperty(const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx