JointController.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 RobotAPI::ArmarXObjects::JointController
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
26 
27 #include <Ice/ProxyHandle.h>
28 
29 #include <memory>
30 #include <atomic>
31 
32 namespace IceProxy::armarx
33 {
34  class DebugDrawerInterface;
35  class DebugObserverInterface;
36 }
37 
38 namespace armarx
39 {
41  typedef ::IceInternal::ProxyHandle< ::IceProxy::armarx::DebugDrawerInterface> DebugDrawerInterfacePrx;
42  typedef ::IceInternal::ProxyHandle< ::IceProxy::armarx::DebugObserverInterface> DebugObserverInterfacePrx;
43 
50  {
51  public:
52  virtual ~JointController() = default;
53 
54  virtual ControlTargetBase* getControlTarget() = 0;
55 
56  virtual const ControlTargetBase* getControlTarget() const;
57 
59  template<class T>
60  const T* getControlTarget() const
61  {
62  return getControlTarget()->asA<const T*>();
63  }
64 
65  virtual void rtResetTarget();
66 
67  virtual bool rtIsTargetValid() const;
68 
69  virtual const std::string& getControlMode() const;
70 
71  virtual std::string getHardwareControlMode() const;
72 
73  std::size_t getControlModeHash() const;
74  std::size_t rtGetControlModeHash() const;
75  std::size_t getHardwareControlModeHash() const;
76  std::size_t rtGetHardwareControlModeHash() const;
77 
78  ControlDevice& getParent() const;
79 
91  virtual StringVariantBaseMap publish(const DebugDrawerInterfacePrx& draw, const DebugObserverInterfacePrx& observer) const;
92 
93  ControlDevice& rtGetParent() const;
94  template<class T>
95  T& rtGetParent() const
96  {
97  return dynamic_cast<T&>(rtGetParent);
98  }
99  protected:
100  //called by the owning ControlDevice
102  virtual void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) = 0;
104  virtual void rtPreActivateController();
105  virtual void rtPostDeactivateController();
107  private:
108  friend class ControlDevice;
109  std::atomic_bool activated {false};
110  ControlDevice* parent {nullptr};
111  std::size_t controlModeHash {0};
112  std::size_t hardwareControlModeHash {0};
113  void rtActivate();
114  void rtDeactivate();
115  };
116 
117  template<class ControlTargetType>
119  {
120  static_assert(std::is_base_of<ControlTargetBase, ControlTargetType>::value, "ControlTargetType has to inherit SensorValueBase");
121  public:
122  using JointController::JointController;
123 
124  ControlTargetType* getControlTarget() final;
125 
126  ControlTargetType controlTarget;
127  };
128 }
129 
130 //inline functions
131 namespace armarx
132 {
134  {
135  return const_cast<const ControlTargetBase*>(const_cast<JointController*>(this)->getControlTarget());
136  }
137 
139  {
140  getControlTarget()->reset();
141  }
142 
144  {
145  return getControlTarget()->isValid();
146  }
147 
148  inline const std::string& JointController::getControlMode() const
149  {
150  return getControlTarget()->getControlMode();
151  }
152 
153  inline std::string JointController::getHardwareControlMode() const
154  {
155  return "";
156  }
157 
158  inline std::size_t JointController::getControlModeHash() const
159  {
160  return controlModeHash;
161  }
162 
163  inline std::size_t JointController::rtGetControlModeHash() const
164  {
165  return controlModeHash;
166  }
167 
169  {
170  return hardwareControlModeHash;
171  }
172 
174  {
175  return hardwareControlModeHash;
176  }
177 
179  {
180  return *parent;
181  }
182 
184  {
185 
186  }
187 
189  {
190 
191  }
192 
193  inline void JointController::rtActivate()
194  {
196  activated = true;
197  }
198 
199  inline void JointController::rtDeactivate()
200  {
201  activated = false;
203  rtResetTarget();
204  }
205 
206  template<class ControlTargetType>
208  {
209  return &controlTarget;
210  }
211 }
armarx::ControlTargetBase::asA
const T * asA() const
Definition: ControlTargetBase.h:75
armarx::JointController::publish
virtual StringVariantBaseMap publish(const DebugDrawerInterfacePrx &draw, const DebugObserverInterfacePrx &observer) const
Hook for publishing data from JointController, mainly for debugging purposes.
Definition: JointController.cpp:35
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:113
IceProxy::armarx
Definition: LogSender.h:38
armarx::JointController::rtRun
virtual void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)=0
called when this JointController is run
armarx::JointControllerTemplate::controlTarget
ControlTargetType controlTarget
Definition: JointController.h:126
armarx::ControlTargetBase
Brief description of class JointControlTargetBase.
Definition: ControlTargetBase.h:48
ControlTargetBase.h
armarx::ControlDevice
The ControlDevice class represents a logical unit accepting commands via its JointControllers.
Definition: ControlDevice.h:60
armarx::JointController::rtPostDeactivateController
virtual void rtPostDeactivateController()
Definition: JointController.h:188
armarx::JointControllerTemplate
Definition: JointController.h:118
armarx::DebugObserverInterfacePrx
::IceInternal::ProxyHandle< ::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
Definition: JointController.h:42
armarx::JointController
The JointController class represents one joint in one control mode.
Definition: JointController.h:49
armarx::ControlTargetBase::getControlMode
virtual const std::string & getControlMode() const =0
armarx::JointController::rtGetHardwareControlModeHash
std::size_t rtGetHardwareControlModeHash() const
Definition: JointController.h:173
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::JointControllerTemplate::getControlTarget
ControlTargetType * getControlTarget() final
Definition: JointController.h:207
armarx::ControlTargetBase::reset
virtual void reset()=0
armarx::JointController::getHardwareControlMode
virtual std::string getHardwareControlMode() const
Definition: JointController.h:153
armarx::ControlTargetBase::isValid
virtual bool isValid() const =0
armarx::JointController::rtPreActivateController
virtual void rtPreActivateController()
called when this JointController is activated
Definition: JointController.h:183
armarx::JointController::rtIsTargetValid
virtual bool rtIsTargetValid() const
Definition: JointController.h:143
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::JointController::getControlTarget
const T * getControlTarget() const
Definition: JointController.h:60
armarx::JointController::rtGetParent
ControlDevice & rtGetParent() const
Definition: JointController.h:178
armarx::JointController::getHardwareControlModeHash
std::size_t getHardwareControlModeHash() const
Definition: JointController.h:168
armarx::JointController::~JointController
virtual ~JointController()=default
armarx::JointController::rtGetControlModeHash
std::size_t rtGetControlModeHash() const
Definition: JointController.h:163
armarx::JointController::getControlMode
virtual const std::string & getControlMode() const
Definition: JointController.h:148
armarx::JointController::getControlTarget
virtual ControlTargetBase * getControlTarget()=0
Definition: JointController.h:133
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::DebugDrawerInterfacePrx
::IceInternal::ProxyHandle< ::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
Definition: JointController.h:40
armarx::JointController::rtGetParent
T & rtGetParent() const
Definition: JointController.h:95
armarx::JointController::rtResetTarget
virtual void rtResetTarget()
Definition: JointController.h:138
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::JointController::getParent
ControlDevice & getParent() const
Definition: JointController.cpp:29
armarx::JointController::getControlModeHash
std::size_t getControlModeHash() const
Definition: JointController.h:158