TCPControlUnitObserver.cpp
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 ArmarX::
17* @author Mirko Waechter ( mirko.waechter at kit dot edu)
18* @date 2013
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
24
25//#include <ArmarXCore/core/checks/ConditionCheckEqualsPoseWithTolerance.h>
32
35
36#define TCP_POSE_CHANNEL "TCPPose"
37#define TCP_TRANS_VELOCITIES_CHANNEL "TCPVelocities"
38
39namespace armarx
40{
41
45
46 void
48 {
49 usingTopic(getProperty<std::string>("TCPControlUnitName").getValue() + "State");
50
51 // register all checks
56 // offerConditionCheck("magnitudeinrange", new ConditionCheckInRange());
57 offerConditionCheck("magnitudelarger", new ConditionCheckMagnitudeLarger());
59 }
60
61 void
63 {
64 offerChannel(TCP_POSE_CHANNEL, "TCP poses of the robot.");
65 offerChannel(TCP_TRANS_VELOCITIES_CHANNEL, "TCP velocities of the robot.");
66 }
67
74
75 void
76 TCPControlUnitObserver::reportTCPPose(const FramedPoseBaseMap& poseMap, const Ice::Current&)
77 {
78 std::unique_lock lock(dataMutex);
79 // ARMARX_INFO << deactivateSpam() << "new tcp poses reported";
80 FramedPoseBaseMap::const_iterator it = poseMap.begin();
81
82 for (; it != poseMap.end(); it++)
83 {
84
85 FramedPosePtr vec = FramedPosePtr::dynamicCast(it->second);
86 const std::string& tcpName = it->first;
87
88 if (!existsDataField(TCP_POSE_CHANNEL, tcpName))
89 {
91 TCP_POSE_CHANNEL, tcpName, Variant(it->second), "Pose of " + tcpName);
92 }
93 else
94 {
95 setDataField(TCP_POSE_CHANNEL, tcpName, Variant(it->second));
96 }
97
99
100 if (!existsChannel(tcpName))
101 {
102 offerChannel(tcpName, "pose components of " + tcpName);
103 offerDataFieldWithDefault(tcpName, "x", Variant(vec->position->x), "X axis");
104 offerDataFieldWithDefault(tcpName, "y", Variant(vec->position->y), "Y axis");
105 offerDataFieldWithDefault(tcpName, "z", Variant(vec->position->z), "Z axis");
107 tcpName, "qx", Variant(vec->orientation->qx), "Quaternion part x");
109 tcpName, "qy", Variant(vec->orientation->qy), "Quaternion part y");
111 tcpName, "qz", Variant(vec->orientation->qz), "Quaternion part z");
113 tcpName, "qw", Variant(vec->orientation->qw), "Quaternion part w");
114 offerDataFieldWithDefault(tcpName, "frame", Variant(vec->frame), "Reference Frame");
115 }
116 else
117 {
118 setDataField(tcpName, "x", Variant(vec->position->x));
119 setDataField(tcpName, "y", Variant(vec->position->y));
120 setDataField(tcpName, "z", Variant(vec->position->z));
121 setDataField(tcpName, "qx", Variant(vec->orientation->qx));
122 setDataField(tcpName, "qy", Variant(vec->orientation->qy));
123 setDataField(tcpName, "qz", Variant(vec->orientation->qz));
124 setDataField(tcpName, "qw", Variant(vec->orientation->qw));
125 setDataField(tcpName, "frame", Variant(vec->frame));
126 }
127
128 updateChannel(tcpName);
129 }
130 }
131
132 void
133 TCPControlUnitObserver::reportTCPVelocities(const FramedDirectionMap& tcpTranslationVelocities,
134 const FramedDirectionMap& tcpOrientationVelocities,
135 const Ice::Current&)
136 {
137 std::unique_lock lock(dataMutex);
138 FramedDirectionMap::const_iterator it = tcpTranslationVelocities.begin();
139
140 for (; it != tcpTranslationVelocities.end(); it++)
141 {
142
143 FramedDirectionPtr vec = FramedDirectionPtr::dynamicCast(it->second);
144 FramedDirectionPtr vecOri;
145 FramedDirectionMap::const_iterator itOri = tcpOrientationVelocities.find(it->first);
146
147 if (itOri != tcpOrientationVelocities.end())
148 {
149 vecOri = FramedDirectionPtr::dynamicCast(itOri->second);
150 }
151
152 const std::string& tcpName = it->first;
153
154 ARMARX_CHECK_EXPRESSION(vec->frame == vecOri->frame);
155
157 {
159 tcpName,
160 Variant(it->second),
161 "Pose of " + tcpName);
162 }
163 else
164 {
166 }
167
169 const std::string channelName = tcpName + "Velocities";
170
171 if (!existsChannel(channelName))
172 {
173 offerChannel(channelName, "pose components of " + tcpName);
174 offerDataFieldWithDefault(channelName, "x", Variant(vec->x), "X axis");
175 offerDataFieldWithDefault(channelName, "y", Variant(vec->y), "Y axis");
176 offerDataFieldWithDefault(channelName, "z", Variant(vec->z), "Z axis");
177 offerDataFieldWithDefault(channelName, "roll", Variant(vecOri->x), "Roll");
178 offerDataFieldWithDefault(channelName, "pitch", Variant(vecOri->y), "Pitch");
179 offerDataFieldWithDefault(channelName, "yaw", Variant(vecOri->z), "Yaw");
181 channelName, "frame", Variant(vecOri->frame), "Reference Frame");
182 }
183 else
184 {
185 setDataField(channelName, "x", Variant(vec->x));
186 setDataField(channelName, "y", Variant(vec->y));
187 setDataField(channelName, "z", Variant(vec->z));
188 setDataField(channelName, "roll", Variant(vecOri->x));
189 setDataField(channelName, "pitch", Variant(vecOri->y));
190 setDataField(channelName, "yaw", Variant(vecOri->z));
191 setDataField(channelName, "frame", Variant(vec->frame));
192 }
193
194 updateChannel(channelName);
195 }
196 }
197
198} // namespace armarx
#define TCP_POSE_CHANNEL
#define TCP_TRANS_VELOCITIES_CHANNEL
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
Checks if the numbers published in the relevant data fields equal a reference value.
Checks if the numbers published in the relevant data fields are larger than a reference value.
Checks if the numbers published in the relevant data fields are smaller than a reference value.
Checks if the relevant data fields have been updated since the installation of this condition.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
bool existsChannel(const std::string &channelName) const
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition Observer.cpp:131
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition Observer.cpp:301
void updateChannel(const std::string &channelName, const std::set< std::string > &updatedDatafields=std::set< std::string >())
Update all conditions for a channel.
Definition Observer.cpp:788
void offerDataFieldWithDefault(std::string channelName, std::string datafieldName, const Variant &defaultValue, std::string description)
Offer a datafield with default value.
Definition Observer.cpp:160
bool existsDataField(const std::string &channelName, const std::string &datafieldName) const
void setDataField(const std::string &channelName, const std::string &datafieldName, const Variant &value, bool triggerFilterUpdate=true)
set datafield with datafieldName and in channel channelName
Definition Observer.cpp:508
void onConnectObserver() override
Framework hook.
void reportTCPPose(const FramedPoseBaseMap &poseMap, const Ice::Current &c=Ice::emptyCurrent) override
PropertyDefinitionsPtr createPropertyDefinitions() override
void onInitObserver() override
Framework hook.
void reportTCPVelocities(const FramedDirectionMap &tcpTranslationVelocities, const FramedDirectionMap &tcpOrientationVelocities, const Ice::Current &c=Ice::emptyCurrent) override
The Variant class is described here: Variants.
Definition Variant.h:224
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< FramedDirection > FramedDirectionPtr
Definition FramedPose.h:84
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272
::std::map<::std::string, ::armarx::FramedPoseBasePtr > FramedPoseBaseMap