KinematicUnitObserver.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 ArmarX::Core
17* @author Kai Welke (welke _at_ kit _dot_ edu)
18* @date 2011 Kai Welke
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#include <string>
27
31#include <ArmarXCore/interface/observers/VariantBase.h>
34
35#include <RobotAPI/interface/observers/KinematicUnitObserverInterface.h>
36#include <RobotAPI/interface/units/KinematicUnitInterface.h>
37
38namespace armarx
39{
42
44 {
45 public:
48 {
50 "RobotNodeSetName",
51 "Robot node set name as defined in robot xml file, e.g. 'LeftArm'");
53 "Robot file name, e.g. robot_model.xml");
54 defineOptionalProperty<std::string>("RobotFileNameProject",
55 "",
56 "Project in which the robot filename is located "
57 "(if robot is loaded from an external project)");
59 "TopicPrefix", "", "Prefix for the sensor value topic name.");
60 }
61 };
62
63 /**
64 * \class KinematicUnitObserver
65 * \ingroup RobotAPI-SensorActorUnits-observers
66 * \brief Observer monitoring kinematic sensor and actor values
67 *
68 * The KinematicUnitObserver allows to install conditions on all channel reported by the KinematicUnit.
69 * These include joint angles, velocities, torques and motor temperatures
70 *
71 * The KinematicUnitObserver retrieves its configuration from a VirtualRobot robot model. Within the model, the joints
72 * which are observer by the unit are define by a robotnodeset.
73 *
74 * Available condition checks are: *valid*, *updated*, *equals*, *inrange*, *approx*, *larger* and *smaller*.
75 */
77 virtual public Observer,
78 virtual public KinematicUnitObserverInterface
79 {
80 public:
81 // framework hooks
82 void onInitObserver() override;
83 void onConnectObserver() override;
84
85
86 // slice interface implementation
87 void reportControlModeChanged(const NameControlModeMap& jointModes,
88 Ice::Long timestamp,
89 bool aValueChanged,
90 const Ice::Current& c = Ice::emptyCurrent) override;
91 void reportJointAngles(const NameValueMap& jointAngles,
92 Ice::Long timestamp,
93 bool aValueChanged,
94 const Ice::Current& c = Ice::emptyCurrent) override;
95 void reportJointVelocities(const NameValueMap& jointVelocities,
96 Ice::Long timestamp,
97 bool aValueChanged,
98 const Ice::Current& c = Ice::emptyCurrent) override;
99 void reportJointTorques(const NameValueMap& jointTorques,
100 Ice::Long timestamp,
101 bool aValueChanged,
102 const Ice::Current& c = Ice::emptyCurrent) override;
103 void reportJointAccelerations(const NameValueMap& jointAccelerations,
104 Ice::Long timestamp,
105 bool aValueChanged,
106 const Ice::Current& c) override;
107 void reportJointCurrents(const NameValueMap& jointCurrents,
108 Ice::Long timestamp,
109 bool aValueChanged,
110 const Ice::Current& c = Ice::emptyCurrent) override;
111 void reportJointMotorTemperatures(const NameValueMap& jointMotorTemperatures,
112 Ice::Long timestamp,
113 bool aValueChanged,
114 const Ice::Current& c = Ice::emptyCurrent) override;
115 void reportJointStatuses(const NameStatusMap& jointStatuses,
116 Ice::Long timestamp,
117 bool aValueChanged,
118 const Ice::Current& c = Ice::emptyCurrent) override;
119
120 std::string
121 getDefaultName() const override
122 {
123 return "KinematicUnitObserver";
124 }
125
126 /**
127 * @see PropertyUser::createPropertyDefinitions()
128 */
129 PropertyDefinitionsPtr createPropertyDefinitions() override;
130
131 static std::string
132 ControlModeToString(ControlMode mode)
133 {
134 switch (mode)
135 {
136 case eDisabled:
137 return "Disabled";
138
139 case ePositionControl:
140 return "PositionControl";
141
142 case eVelocityControl:
143 return "VelocityControl";
144
145 case eTorqueControl:
146 return "TorqueControl";
147
148 case ePositionVelocityControl:
149 return "PositionVelocityControl";
150
151 case eUnknown:
152 default:
153 return "Unknown";
154 }
155 }
156
157 static ControlMode
158 StringToControlMode(const std::string& mode)
159 {
160 if (mode == "Disabled")
161 {
162 return eDisabled;
163 }
164
165 if (mode == "PositionControl")
166 {
167 return ePositionControl;
168 }
169
170 if (mode == "VelocityControl")
171 {
172 return eVelocityControl;
173 }
174
175 if (mode == "TorqueControl")
176 {
177 return eTorqueControl;
178 }
179
180 if (mode == "PositionVelocityControl")
181 {
182 return ePositionVelocityControl;
183 }
184
185 return eUnknown;
186 }
187
188 protected:
189 void nameValueMapToDataFields(const std::string& channelName,
190 const NameValueMap& nameValueMap,
191 Ice::Long timestamp,
192 bool aValueChanged);
193 std::set<std::string> initializedChannels;
195
196 private:
197 std::string robotNodeSetName;
198 std::set<std::string> robotNodes;
199 };
200
201 /**
202 @class KinematicUnitDatafieldCreator
203 @brief
204 @ingroup RobotAPI-SensorActorUnits-util
205 */
207 {
208 public:
209 KinematicUnitDatafieldCreator(const std::string& channelName) : _channelName(channelName)
210 {
211 }
212
213 /**
214 * @brief Function to create a Channel Representation for a KinematicUnitObserver
215 * @param kinematicUnitOberserverName Name of the KinematicUnitObserver
216 * @param jointName Name of a joint of the robot like it is specified
217 * in the simox-robot-xml-file
218 * @return returns a ChannelRepresentationPtr
219 */
221 getDatafield(const std::string& kinematicUnitObserverName,
222 const std::string& jointName) const
223 {
224 if (kinematicUnitObserverName.empty())
225 {
226 throw LocalException("kinematicUnitObserverName must not be empty!");
227 }
228
229 if (jointName.empty())
230 {
231 throw LocalException("jointName must not be empty!");
232 }
233
234 return DataFieldIdentifier(kinematicUnitObserverName, _channelName, jointName);
235 }
236
237 private:
238 std::string _channelName;
239 };
240} // namespace armarx
241
243{
249} // namespace armarx::channels::KinematicUnitObserver
std::string timestamp()
#define ARMARX_CREATE_CHECK(OFFERER, NEWCHECK)
#define ARMARXCORE_IMPORT_EXPORT
constexpr T c
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
DataFieldIdentifier getDatafield(const std::string &kinematicUnitObserverName, const std::string &jointName) const
Function to create a Channel Representation for a KinematicUnitObserver.
KinematicUnitDatafieldCreator(const std::string &channelName)
Observer monitoring kinematic sensor and actor values.
static ControlMode StringToControlMode(const std::string &mode)
void reportJointMotorTemperatures(const NameValueMap &jointMotorTemperatures, Ice::Long timestamp, bool aValueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void onConnectObserver() override
Framework hook.
void reportJointVelocities(const NameValueMap &jointVelocities, Ice::Long timestamp, bool aValueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointAngles(const NameValueMap &jointAngles, Ice::Long timestamp, bool aValueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointTorques(const NameValueMap &jointTorques, Ice::Long timestamp, bool aValueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void reportControlModeChanged(const NameControlModeMap &jointModes, Ice::Long timestamp, bool aValueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointCurrents(const NameValueMap &jointCurrents, Ice::Long timestamp, bool aValueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointAccelerations(const NameValueMap &jointAccelerations, Ice::Long timestamp, bool aValueChanged, const Ice::Current &c) override
void reportJointStatuses(const NameStatusMap &jointStatuses, Ice::Long timestamp, bool aValueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void onInitObserver() override
Framework hook.
static std::string ControlModeToString(ControlMode mode)
std::set< std::string > initializedChannels
std::string getDefaultName() const override
Retrieve default name of component.
ObserverPropertyDefinitions(std::string prefix)
Definition Observer.h:52
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)
const KinematicUnitDatafieldCreator jointVelocities("jointVelocities")
const KinematicUnitDatafieldCreator jointTemperatures("jointTemperatures")
const KinematicUnitDatafieldCreator jointCurrents("jointCurrents")
const KinematicUnitDatafieldCreator jointAngles("jointAngles")
const KinematicUnitDatafieldCreator jointTorques("jointTorques")
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.