YARP
Yet Another Robot Platform
FrameTransformStorage.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: LGPL-2.1-or-later
4  */
5 
7 #include <yarp/os/Log.h>
8 #include <yarp/os/LogComponent.h>
9 #include <yarp/os/LogStream.h>
10 
11 using namespace yarp::dev;
12 using namespace yarp::os;
13 using namespace yarp::sig;
14 using namespace yarp::math;
15 
16 namespace {
17 YARP_LOG_COMPONENT(FRAMETRANSFORSTORAGE, "yarp.device.frameTransformStorage")
18 }
19 
20 //------------------------------------------------------------------------------------------------------------------------------
22 {
23  container = &m_tf_container;
24  return true;
25 }
26 
28 {
29  std::string sstr = config.toString();
30 
31  yCTrace(FRAMETRANSFORSTORAGE);
32  bool b = this->start();
33  return b;
34 }
35 
37 {
38  return true;
39 }
40 
41 bool FrameTransformStorage::getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const
42 {
43  std::lock_guard <std::mutex> lg(m_pd_mutex);
44  return m_tf_container.getTransforms(transforms);
45 }
46 
47 bool FrameTransformStorage::setTransforms(const std::vector<yarp::math::FrameTransform>& transforms)
48 {
49  std::lock_guard <std::mutex> lg(m_pd_mutex);
50  return m_tf_container.setTransforms(transforms);
51 }
52 
54 {
55  std::lock_guard <std::mutex> lg(m_pd_mutex);
56  return m_tf_container.setTransform (t);
57 }
58 
59 bool FrameTransformStorage::deleteTransform(std::string t1, std::string t2)
60 {
61  std::lock_guard <std::mutex> lg(m_pd_mutex);
62  return m_tf_container.deleteTransform(t1,t2);
63 }
64 
65 void FrameTransformStorage::run()
66 {
67  std::lock_guard <std::mutex> lg(m_pd_mutex);
68 
69  // remove expired non static transforms
70  m_tf_container.checkAndRemoveExpired();
71 
72  // get new transforms
73  if (iGetIf)
74  {
75  std::vector<yarp::math::FrameTransform> tfs;
76  bool b=iGetIf->getTransforms(tfs);
77  if (b)
78  {
79  m_tf_container.setTransforms(tfs);
80  }
81  }
82 }
83 
85 {
86  std::lock_guard <std::mutex> lg(m_pd_mutex);
87  iGetIf = nullptr;
88  pDriver = nullptr;
89  if(isRunning())
90  {
91  stop();
92  }
93  return true;
94 }
95 
97 {
98  std::lock_guard <std::mutex> lg(m_pd_mutex);
99  if (driver->isValid())
100  {
101  pDriver = driver;
102  pDriver->view(iGetIf);
103  if(iGetIf)
104  {
105  return true;
106  }
107  }
108 
109  return false;
110 }
111 
113 {
114  return m_tf_container.clearAll();
115 }
116 
117 bool FrameTransformStorage::size(size_t& size) const
118 {
119  return m_tf_container.size(size);
120 }
121 
123 {
124  return this->start();
125 }
126 
128 {
129  this->askToStop();
130  do
131  {
132  yarp::os::Time::delay(0.001);
133  }
134  while (this->isRunning());
135  return true;
136 }
float t
FrameTransformContainer: A class that contains a vector of frame transformations and exposes yarp::de...
bool close() override
Close the DeviceDriver.
bool getInternalContainer(FrameTransformContainer *&container) override
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool setTransform(const yarp::math::FrameTransform &transform) override
Save a frame transform in a storage.
bool getTransforms(std::vector< yarp::math::FrameTransform > &transforms) const override
Obtains all frame transforms saved in a storage.
bool deleteTransform(std::string t1, std::string t2) override
Delete a single transform in the storage.
bool detach() override
Detach the object (you must have first called attach).
bool clearAll() override
Delete all transforms in a storage.
bool setTransforms(const std::vector< yarp::math::FrameTransform > &transforms) override
Save some frame transforms in a storage.
bool size(size_t &size) const override
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:74
A container for a device driver.
Definition: PolyDriver.h:24
bool isValid() const
Check if device is valid.
Definition: PolyDriver.cpp:196
A base class for nested structures that can be searched.
Definition: Searchable.h:66
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
#define yCTrace(component,...)
Definition: LogComponent.h:85
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:77
An interface for the device drivers.
void delay(double seconds)
Wait for a certain number of seconds.
Definition: Time.cpp:111
An interface to the operating system, including Port based communication.
Signal processing.
Definition: Image.h:22