NJointControllerWithTripleBuffer.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "NJointControllerBase.h"
6 
7 namespace 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:
76  WriteBufferedTripleBuffer<ControlDataStruct> controlDataTripleBuffer;
77  };
78 
79  template <typename ControlDataStruct>
82 
83 } // namespace armarx
armarx::NJointControllerWithTripleBuffer::reinitTripleBuffer
void reinitTripleBuffer(const ControlDataStruct &initial)
Definition: NJointControllerWithTripleBuffer.h:68
armarx::NJointControllerWithTripleBuffer::rtGetControlStruct
const ControlDataStruct & rtGetControlStruct() const
Definition: NJointControllerWithTripleBuffer.h:32
NJointControllerBase.h
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
armarx::SynchronousNJointController
Definition: NJointControllerBase.h:1145
armarx::WriteBufferedTripleBuffer::commitWrite
void commitWrite()
Definition: TripleBuffer.h:326
armarx::WriteBufferedTripleBuffer::updateReadBuffer
bool updateReadBuffer() const
Swaps in the hidden buffer if it contains new data.
Definition: TripleBuffer.h:321
armarx::NJointControllerWithTripleBuffer::getWriterControlStruct
ControlDataStruct & getWriterControlStruct()
Definition: NJointControllerWithTripleBuffer.h:54
armarx::NJointControllerWithTripleBuffer< NJointTaskSpaceAdaptiveDMPControllerControlData >::LockGuardType
std::lock_guard< std::recursive_mutex > LockGuardType
Definition: NJointControllerWithTripleBuffer.h:14
armarx::SynchronousNJointController::rtRun
virtual void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)=0
TODO make protected and use attorneys.
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::NJointControllerWithTripleBuffer::rtUpdateControlStruct
bool rtUpdateControlStruct()
Definition: NJointControllerWithTripleBuffer.h:38
armarx::NJointControllerWithTripleBuffer::writeControlStruct
void writeControlStruct()
Definition: NJointControllerWithTripleBuffer.h:44
armarx::WriteBufferedTripleBuffer::getWriteBuffer
T & getWriteBuffer()
Definition: TripleBuffer.h:280
armarx::NJointControllerWithTripleBuffer::controlDataMutex
MutexType controlDataMutex
Definition: NJointControllerWithTripleBuffer.h:73
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TripleBuffer.h
armarx::WriteBufferedTripleBuffer::reinitAllBuffers
void reinitAllBuffers(const T &init)
Definition: TripleBuffer.h:332
armarx::NJointControllerWithTripleBuffer::rtSwapBufferAndRun
void rtSwapBufferAndRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
Definition: NJointControllerWithTripleBuffer.h:23
armarx::NJointControllerWithTripleBuffer::setControlStruct
void setControlStruct(const ControlDataStruct &newStruct)
Definition: NJointControllerWithTripleBuffer.h:60
armarx::NJointControllerWithTripleBuffer< NJointTaskSpaceAdaptiveDMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::WriteBufferedTripleBuffer< ControlDataStruct >
armarx::WriteBufferedTripleBuffer::getReadBuffer
const T & getReadBuffer() const
Definition: TripleBuffer.h:291
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::NJointControllerWithTripleBuffer::NJointControllerWithTripleBuffer
NJointControllerWithTripleBuffer(const ControlDataStruct &initialCommands=ControlDataStruct())
Definition: NJointControllerWithTripleBuffer.h:16