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
26#include "../util/RtTiming.h"
27#include "SensorDevice.h"
28
30{
32}
33
34namespace armarx
35{
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
59
62
65
68
69
72
75
76 virtual void rtMarkRtResetAllTargetsStart() = 0;
77 virtual void rtMarkRtResetAllTargetsEnd() = 0;
78 };
79
80 template <class SensorValueType = SensorValueRTThreadTimings>
82 {
83 public:
84 static_assert(std::is_base_of<SensorValueRTThreadTimings, SensorValueType>::value,
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
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;
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:
161 IceUtil::Time rtLoopStart;
162 };
163
164} // namespace armarx
#define TYPEDEF_PTRS_SHARED(T)
#define TYPEDEF_PTRS_HANDLE(T)
make_markRT_X_Start_End(SwitchControllerSetup)
make_markRT_X_Start_End(RunJointControllers)
make_markRT_X_Start_End(ReadSensorDeviceValues)
make_markRT_X_Start_End(RunNJointControllers)
make_markRT_X_Start_End(UpdateSensorAndControlBuffer)
make_markRT_X_Start_End(HandleInvalidTargets)
const SensorValueBase * getSensorValue() const override
virtual void rtMarkRtHandleInvalidTargetsEnd()=0
virtual void rtMarkRtRunJointControllersEnd()=0
virtual void rtMarkRtBusSendReceiveStart()=0
virtual void rtMarkRtBusSendReceiveEnd()=0
virtual void rtMarkRtHandleInvalidTargetsStart()=0
virtual void rtMarkRtUpdateSensorAndControlBufferEnd()=0
virtual void rtMarkRtRunNJointControllersStart()=0
const SensorValueBase * getSensorValue() const override=0
virtual void rtMarkRtReadSensorDeviceValuesEnd()=0
virtual void rtMarkRtResetAllTargetsStart()=0
virtual void rtMarkRtUpdateSensorAndControlBufferStart()=0
virtual void rtMarkRtReadSensorDeviceValuesStart()=0
virtual void rtMarkRtRunNJointControllersEnd()=0
virtual void rtMarkRtRunJointControllersStart()=0
virtual void rtMarkRtSwitchControllerSetupEnd()=0
virtual void rtMarkRtSwitchControllerSetupStart()=0
virtual void rtMarkRtResetAllTargetsEnd()=0
This Module manages the ControlThread.
This class represents some part of the robot providing sensor values.
SensorDevice(const std::string &name)
Create a SensorDevice with the given name.
The SensorValueBase class.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Time rtNow()
Definition RtTiming.h:40