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 
38 namespace armarx
39 {
40  ARMARX_CREATE_CHECK(KinematicUnitObserver, equals)
41  ARMARX_CREATE_CHECK(KinematicUnitObserver, larger)
42 
44  {
45  public:
48  {
49  defineRequiredProperty<std::string>(
50  "RobotNodeSetName",
51  "Robot node set name as defined in robot xml file, e.g. 'LeftArm'");
52  defineRequiredProperty<std::string>("RobotFileName",
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)");
58  defineOptionalProperty<std::string>(
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,
89  bool aValueChanged,
90  const Ice::Current& c = Ice::emptyCurrent) override;
91  void reportJointAngles(const NameValueMap& jointAngles,
93  bool aValueChanged,
94  const Ice::Current& c = Ice::emptyCurrent) override;
95  void reportJointVelocities(const NameValueMap& jointVelocities,
97  bool aValueChanged,
98  const Ice::Current& c = Ice::emptyCurrent) override;
99  void reportJointTorques(const NameValueMap& jointTorques,
101  bool aValueChanged,
102  const Ice::Current& c = Ice::emptyCurrent) override;
103  void reportJointAccelerations(const NameValueMap& jointAccelerations,
105  bool aValueChanged,
106  const Ice::Current& c) override;
107  void reportJointCurrents(const NameValueMap& jointCurrents,
109  bool aValueChanged,
110  const Ice::Current& c = Ice::emptyCurrent) override;
111  void reportJointMotorTemperatures(const NameValueMap& jointMotorTemperatures,
113  bool aValueChanged,
114  const Ice::Current& c = Ice::emptyCurrent) override;
115  void reportJointStatuses(const NameStatusMap& jointStatuses,
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,
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 {
244  const KinematicUnitDatafieldCreator jointAngles("jointAngles");
245  const KinematicUnitDatafieldCreator jointVelocities("jointVelocities");
246  const KinematicUnitDatafieldCreator jointTorques("jointTorques");
247  const KinematicUnitDatafieldCreator jointCurrents("jointCurrents");
248  const KinematicUnitDatafieldCreator jointTemperatures("jointTemperatures");
249 } // namespace armarx::channels::KinematicUnitObserver
armarx::Observer
Baseclass for all ArmarX Observers.
Definition: Observer.h:84
armarx::KinematicUnitObserverPropertyDefinitions
Definition: KinematicUnitObserver.h:43
armarx::channels::KinematicUnitObserver::jointTemperatures
const KinematicUnitDatafieldCreator jointTemperatures("jointTemperatures")
Properties.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
Observer.h
armarx::KinematicUnitObserver::StringToControlMode
static ControlMode StringToControlMode(const std::string &mode)
Definition: KinematicUnitObserver.h:158
armarx::KinematicUnitObserver::ControlModeToString
static std::string ControlModeToString(ControlMode mode)
Definition: KinematicUnitObserver.h:132
armarx::KinematicUnitDatafieldCreator::getDatafield
DataFieldIdentifier getDatafield(const std::string &kinematicUnitObserverName, const std::string &jointName) const
Function to create a Channel Representation for a KinematicUnitObserver.
Definition: KinematicUnitObserver.h:221
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::KinematicUnitDatafieldCreator
Definition: KinematicUnitObserver.h:206
armarx::KinematicUnitDatafieldCreator::KinematicUnitDatafieldCreator
KinematicUnitDatafieldCreator(const std::string &channelName)
Definition: KinematicUnitObserver.h:209
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::channels::KinematicUnitObserver::jointVelocities
const KinematicUnitDatafieldCreator jointVelocities("jointVelocities")
ARMARX_CREATE_CHECK
#define ARMARX_CREATE_CHECK(OFFERER, NEWCHECK)
Definition: ConditionCheck.h:222
armarx::KinematicUnitObserver::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: KinematicUnitObserver.h:121
Component.h
armarx::KinematicUnitObserver::initializedChannelsMutex
std::mutex initializedChannelsMutex
Definition: KinematicUnitObserver.h:194
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:88
armarx::channels::KinematicUnitObserver::jointAngles
const KinematicUnitDatafieldCreator jointAngles("jointAngles")
armarx::channels::KinematicUnitObserver::jointCurrents
const KinematicUnitDatafieldCreator jointCurrents("jointCurrents")
armarx::KinematicUnitObserverPropertyDefinitions::KinematicUnitObserverPropertyDefinitions
KinematicUnitObserverPropertyDefinitions(std::string prefix)
Definition: KinematicUnitObserver.h:46
armarx::channels::KinematicUnitObserver
Definition: KinematicUnitObserver.h:242
IceUtil::Handle
Definition: forward_declarations.h:30
ImportExport.h
ConditionCheck.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
armarx::channels::KinematicUnitObserver::jointTorques
const KinematicUnitDatafieldCreator jointTorques("jointTorques")
armarx::KinematicUnitObserver
Observer monitoring kinematic sensor and actor values.
Definition: KinematicUnitObserver.h:76
armarx::ObserverPropertyDefinitions
Definition: Observer.h:49
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::DataFieldIdentifier
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
Definition: DataFieldIdentifier.h:48
armarx::KinematicUnitObserver::initializedChannels
std::set< std::string > initializedChannels
Definition: KinematicUnitObserver.h:193