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