NJointControllerWithTripleBuffer.h
Go to the documentation of this file.
1#pragma once
2
4
6
7namespace armarx
8{
9 template <typename ControlDataStruct>
11 {
12 public:
13 using MutexType = std::recursive_mutex;
14 using LockGuardType = std::lock_guard<std::recursive_mutex>;
15
17 const ControlDataStruct& initialCommands = ControlDataStruct()) :
18 controlDataTripleBuffer{initialCommands}
19 {
20 }
21
22 void
23 rtSwapBufferAndRun(const IceUtil::Time& sensorValuesTimestamp,
24 const IceUtil::Time& timeSinceLastIteration) override
25 {
27 rtRun(sensorValuesTimestamp, timeSinceLastIteration);
28 }
29
30 protected:
31 const ControlDataStruct&
33 {
34 return controlDataTripleBuffer.getReadBuffer();
35 }
36
37 bool
39 {
40 return controlDataTripleBuffer.updateReadBuffer();
41 }
42
43 void
45 {
46 //just lock to be save and reduce the impact of an error
47 //also this allows code to unlock the mutex before calling this function
48 //(can happen if some lockguard in a scope is used)
50 controlDataTripleBuffer.commitWrite();
51 }
52
53 ControlDataStruct&
55 {
56 return controlDataTripleBuffer.getWriteBuffer();
57 }
58
59 void
60 setControlStruct(const ControlDataStruct& newStruct)
61 {
63 getWriterControlStruct() = newStruct;
65 }
66
67 void
68 reinitTripleBuffer(const ControlDataStruct& initial)
69 {
70 controlDataTripleBuffer.reinitAllBuffers(initial);
71 }
72
74
75 private:
77 };
78
79 template <typename ControlDataStruct>
82
83} // namespace armarx
void rtSwapBufferAndRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
std::lock_guard< std::recursive_mutex > LockGuardType
void setControlStruct(const ControlDataStruct &newStruct)
NJointControllerWithTripleBuffer(const ControlDataStruct &initialCommands=ControlDataStruct())
void reinitTripleBuffer(const ControlDataStruct &initial)
virtual void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)=0
TODO make protected and use attorneys.
Same as the TripleBuffer, but partial writes of the data structure are ok. The write operation may be...
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< NJointControllerWithTripleBuffer< ControlDataStruct > > NJointControllerWithTripleBufferPtr