RTThreadTimingsSensorDevice.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
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 
25 #include "../SensorValues/SensorValueRTThreadTimings.h"
26 #include "../util/RtTiming.h"
27 #include "SensorDevice.h"
28 
30 {
31  TYPEDEF_PTRS_HANDLE(ControlThread);
32 }
33 
34 namespace armarx
35 {
36  TYPEDEF_PTRS_SHARED(RTThreadTimingsSensorDevice);
37 
39  {
40  public:
41  RTThreadTimingsSensorDevice(const std::string& name) : DeviceBase(name), SensorDevice(name)
42  {
43  }
44 
45  const SensorValueBase* getSensorValue() const override = 0;
46 
47  virtual void rtMarkRtLoopStart() = 0;
48  virtual void rtMarkRtLoopPreSleep() = 0;
49 
50  virtual void rtMarkRtBusSendReceiveStart() = 0;
51  virtual void rtMarkRtBusSendReceiveEnd() = 0;
52 
53  protected:
54  friend class RobotUnit;
56 
57  virtual void rtMarkRtSwitchControllerSetupStart() = 0;
58  virtual void rtMarkRtSwitchControllerSetupEnd() = 0;
59 
60  virtual void rtMarkRtRunNJointControllersStart() = 0;
61  virtual void rtMarkRtRunNJointControllersEnd() = 0;
62 
63  virtual void rtMarkRtHandleInvalidTargetsStart() = 0;
64  virtual void rtMarkRtHandleInvalidTargetsEnd() = 0;
65 
66  virtual void rtMarkRtRunJointControllersStart() = 0;
67  virtual void rtMarkRtRunJointControllersEnd() = 0;
68 
69 
70  virtual void rtMarkRtReadSensorDeviceValuesStart() = 0;
71  virtual void rtMarkRtReadSensorDeviceValuesEnd() = 0;
72 
74  virtual void rtMarkRtUpdateSensorAndControlBufferEnd() = 0;
75 
76  virtual void rtMarkRtResetAllTargetsStart() = 0;
77  virtual void rtMarkRtResetAllTargetsEnd() = 0;
78  };
79 
80  template <class SensorValueType = SensorValueRTThreadTimings>
82  {
83  public:
85  "The template parameter of RTThreadTimingsSensorDeviceImpl should be derived "
86  "from SensorValueRTThreadTimings");
87 
88  RTThreadTimingsSensorDeviceImpl(const std::string& name) :
90  {
91  }
92 
93  const SensorValueBase*
94  getSensorValue() const override
95  {
96  return &value;
97  }
98 
99  SensorValueType value;
100 
101  void
102  rtMarkRtLoopStart() override
103  {
104  const auto now = armarx::rtNow();
105  value.rtLoopRoundTripTime = now - rtLoopStart;
106  rtLoopStart = now;
107  }
108 
109  void
111  {
112  value.rtLoopDuration = armarx::rtNow() - rtLoopStart;
113  }
114 
115  void
117  {
118  const IceUtil::Time now = armarx::rtNow();
119  value.rtBusSendReceiveRoundTripTime = now - rtBusSendReceiveStart;
120  rtBusSendReceiveStart = now;
121  }
122 
123  void
125  {
126  value.rtBusSendReceiveDuration = armarx::rtNow() - rtBusSendReceiveStart;
127  }
128 
129  protected:
130 #define make_markRT_X_Start_End(name) \
131  virtual void rtMarkRt##name##Start() override \
132  { \
133  const IceUtil::Time now = armarx::rtNow(); \
134  value.rt##name##RoundTripTime = now - rt##name##Start; \
135  rt##name##Start = now; \
136  } \
137  virtual void rtMarkRt##name##End() override \
138  { \
139  value.rt##name##Duration = armarx::rtNow() - rt##name##Start; \
140  } \
141  static_assert(true, "force trailing semi-colon")
142 
143  make_markRT_X_Start_End(SwitchControllerSetup);
144  make_markRT_X_Start_End(RunNJointControllers);
145  make_markRT_X_Start_End(HandleInvalidTargets);
146  make_markRT_X_Start_End(RunJointControllers);
147  make_markRT_X_Start_End(ReadSensorDeviceValues);
148  make_markRT_X_Start_End(UpdateSensorAndControlBuffer);
149  make_markRT_X_Start_End(ResetAllTargets);
150 #undef make_markRT_X_Start_End
151 
152  protected:
162  };
163 
164 } // namespace armarx
armarx::RTThreadTimingsSensorDevice::rtMarkRtRunNJointControllersStart
virtual void rtMarkRtRunNJointControllersStart()=0
SensorDevice.h
armarx::SensorValueBase
The SensorValueBase class.
Definition: SensorValueBase.h:40
armarx::RTThreadTimingsSensorDevice::rtMarkRtBusSendReceiveStart
virtual void rtMarkRtBusSendReceiveStart()=0
armarx::RTThreadTimingsSensorDeviceImpl::RTThreadTimingsSensorDeviceImpl
RTThreadTimingsSensorDeviceImpl(const std::string &name)
Definition: RTThreadTimingsSensorDevice.h:88
armarx::RTThreadTimingsSensorDevice::rtMarkRtResetAllTargetsEnd
virtual void rtMarkRtResetAllTargetsEnd()=0
armarx::RTThreadTimingsSensorDevice::rtMarkRtLoopPreSleep
virtual void rtMarkRtLoopPreSleep()=0
armarx::RTThreadTimingsSensorDeviceImpl::value
SensorValueType value
Definition: RTThreadTimingsSensorDevice.h:99
armarx::RTThreadTimingsSensorDevice::rtMarkRtHandleInvalidTargetsStart
virtual void rtMarkRtHandleInvalidTargetsStart()=0
armarx::RTThreadTimingsSensorDevice::rtMarkRtSwitchControllerSetupStart
virtual void rtMarkRtSwitchControllerSetupStart()=0
armarx::RTThreadTimingsSensorDeviceImpl::rtRunNJointControllersStart
IceUtil::Time rtRunNJointControllersStart
Definition: RTThreadTimingsSensorDevice.h:154
armarx::RTThreadTimingsSensorDevice::rtMarkRtRunJointControllersStart
virtual void rtMarkRtRunJointControllersStart()=0
armarx::DeviceBase
Definition: DeviceBase.h:29
armarx::RTThreadTimingsSensorDeviceImpl::rtMarkRtLoopStart
void rtMarkRtLoopStart() override
Definition: RTThreadTimingsSensorDevice.h:102
armarx::RTThreadTimingsSensorDeviceImpl::rtLoopStart
IceUtil::Time rtLoopStart
Definition: RTThreadTimingsSensorDevice.h:161
armarx::RobotUnitModule::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(Devices)
armarx::RTThreadTimingsSensorDevice::rtMarkRtLoopStart
virtual void rtMarkRtLoopStart()=0
armarx::TYPEDEF_PTRS_SHARED
TYPEDEF_PTRS_SHARED(ControlDevice)
armarx::RTThreadTimingsSensorDevice::rtMarkRtHandleInvalidTargetsEnd
virtual void rtMarkRtHandleInvalidTargetsEnd()=0
armarx::RTThreadTimingsSensorDevice
Definition: RTThreadTimingsSensorDevice.h:38
armarx::RobotUnitModule::ControlThread
This Module manages the ControlThread.
Definition: RobotUnitModuleControlThread.h:83
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::RTThreadTimingsSensorDeviceImpl::rtMarkRtLoopPreSleep
void rtMarkRtLoopPreSleep() override
Definition: RTThreadTimingsSensorDevice.h:110
armarx::RTThreadTimingsSensorDeviceImpl::rtResetAllTargetsStart
IceUtil::Time rtResetAllTargetsStart
Definition: RTThreadTimingsSensorDevice.h:160
armarx::SensorDevice
This class represents some part of the robot providing sensor values.
Definition: SensorDevice.h:59
armarx::RTThreadTimingsSensorDevice::rtMarkRtReadSensorDeviceValuesStart
virtual void rtMarkRtReadSensorDeviceValuesStart()=0
armarx::RTThreadTimingsSensorDeviceImpl::getSensorValue
const SensorValueBase * getSensorValue() const override
Definition: RTThreadTimingsSensorDevice.h:94
armarx::RTThreadTimingsSensorDeviceImpl::rtSwitchControllerSetupStart
IceUtil::Time rtSwitchControllerSetupStart
Definition: RTThreadTimingsSensorDevice.h:153
armarx::RTThreadTimingsSensorDevice::rtMarkRtResetAllTargetsStart
virtual void rtMarkRtResetAllTargetsStart()=0
armarx::RTThreadTimingsSensorDeviceImpl::rtHandleInvalidTargetsStart
IceUtil::Time rtHandleInvalidTargetsStart
Definition: RTThreadTimingsSensorDevice.h:155
armarx::RTThreadTimingsSensorDeviceImpl::rtMarkRtBusSendReceiveEnd
void rtMarkRtBusSendReceiveEnd() override
Definition: RTThreadTimingsSensorDevice.h:124
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::RTThreadTimingsSensorDeviceImpl::rtReadSensorDeviceValuesStart
IceUtil::Time rtReadSensorDeviceValuesStart
Definition: RTThreadTimingsSensorDevice.h:158
armarx::RTThreadTimingsSensorDeviceImpl::rtRunJointControllersStart
IceUtil::Time rtRunJointControllersStart
Definition: RTThreadTimingsSensorDevice.h:156
armarx::RTThreadTimingsSensorDeviceImpl::rtBusSendReceiveStart
IceUtil::Time rtBusSendReceiveStart
Definition: RTThreadTimingsSensorDevice.h:157
armarx::RTThreadTimingsSensorDevice::rtMarkRtReadSensorDeviceValuesEnd
virtual void rtMarkRtReadSensorDeviceValuesEnd()=0
armarx::RTThreadTimingsSensorDeviceImpl::rtUpdateSensorAndControlBufferStart
IceUtil::Time rtUpdateSensorAndControlBufferStart
Definition: RTThreadTimingsSensorDevice.h:159
armarx::RTThreadTimingsSensorDevice::rtMarkRtRunNJointControllersEnd
virtual void rtMarkRtRunNJointControllersEnd()=0
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
armarx::RTThreadTimingsSensorDevice::rtMarkRtBusSendReceiveEnd
virtual void rtMarkRtBusSendReceiveEnd()=0
armarx::RTThreadTimingsSensorDeviceImpl
Definition: RTThreadTimingsSensorDevice.h:81
armarx::RTThreadTimingsSensorDevice::rtMarkRtRunJointControllersEnd
virtual void rtMarkRtRunJointControllersEnd()=0
armarx::RobotUnitModule
Definition: ControlDevice.h:34
armarx::RTThreadTimingsSensorDeviceImpl::make_markRT_X_Start_End
make_markRT_X_Start_End(SwitchControllerSetup)
armarx::RTThreadTimingsSensorDevice::rtMarkRtUpdateSensorAndControlBufferEnd
virtual void rtMarkRtUpdateSensorAndControlBufferEnd()=0
armarx::RTThreadTimingsSensorDevice::RTThreadTimingsSensorDevice
RTThreadTimingsSensorDevice(const std::string &name)
Definition: RTThreadTimingsSensorDevice.h:41
armarx::RTThreadTimingsSensorDevice::rtMarkRtSwitchControllerSetupEnd
virtual void rtMarkRtSwitchControllerSetupEnd()=0
armarx::RTThreadTimingsSensorDeviceImpl::rtMarkRtBusSendReceiveStart
void rtMarkRtBusSendReceiveStart() override
Definition: RTThreadTimingsSensorDevice.h:116
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RTThreadTimingsSensorDevice::getSensorValue
const SensorValueBase * getSensorValue() const override=0
armarx::RTThreadTimingsSensorDevice::rtMarkRtUpdateSensorAndControlBufferStart
virtual void rtMarkRtUpdateSensorAndControlBufferStart()=0
armarx::rtNow
IceUtil::Time rtNow()
Definition: RtTiming.h:40