YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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>
9#include <yarp/os/LogStream.h>
10
11using namespace yarp::dev;
12using namespace yarp::os;
13using namespace yarp::sig;
14using namespace yarp::math;
15
16namespace {
17YARP_LOG_COMPONENT(FRAMETRANSFORSTORAGE, "yarp.device.frameTransformStorage")
18}
19
20//------------------------------------------------------------------------------------------------------------------------------
26
28{
29 if (!this->parseParams(config)) { return false; }
30
31 std::string sstr = config.toString();
32
34 {
36 m_tf_container.m_name = this->id() + ".container";
37 }
38
39 //if (m_FrameTransform_container_timeout>0) //should I check?
40 {
42 }
43
45 bool b = this->start();
46 return b;
47}
48
50{
51 detach();
52 return true;
53}
54
55bool FrameTransformStorage::getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const
56{
57 std::lock_guard <std::mutex> lg(m_pd_mutex);
58 return m_tf_container.getTransforms(transforms);
59}
60
61bool FrameTransformStorage::setTransforms(const std::vector<yarp::math::FrameTransform>& transforms)
62{
63 std::lock_guard <std::mutex> lg(m_pd_mutex);
64 return m_tf_container.setTransforms(transforms);
65}
66
68{
69 std::lock_guard <std::mutex> lg(m_pd_mutex);
71}
72
73bool FrameTransformStorage::deleteTransform(std::string t1, std::string t2)
74{
75 std::lock_guard <std::mutex> lg(m_pd_mutex);
76 return m_tf_container.deleteTransform(t1,t2);
77}
78
79void FrameTransformStorage::run()
80{
81 std::lock_guard <std::mutex> lg(m_pd_mutex);
82
83 // remove expired non static transforms
85
86 // get new transforms
87 if (iGetIf)
88 {
89 std::vector<yarp::math::FrameTransform> tfs;
90 bool b=iGetIf->getTransforms(tfs);
91 if (b)
92 {
94 }
95 }
96}
97
99{
100 std::lock_guard <std::mutex> lg(m_pd_mutex);
101 iGetIf = nullptr;
102 pDriver = nullptr;
103 if(isRunning())
104 {
105 stop();
106 }
107 return true;
108}
109
111{
112 std::lock_guard <std::mutex> lg(m_pd_mutex);
113 if (driver->isValid())
114 {
115 pDriver = driver;
116 pDriver->view(iGetIf);
117 if(iGetIf)
118 {
119 return true;
120 }
121 }
122
123 return false;
124}
125
130
131bool FrameTransformStorage::size(size_t& size) const
132{
133 return m_tf_container.size(size);
134}
135
137{
138 return this->start();
139}
140
142{
143 this->askToStop();
144 do
145 {
147 }
148 while (this->isRunning());
149 return true;
150}
float t
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool close() override
Close the DeviceDriver.
yarp::dev::FrameTransformContainer m_tf_container
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 getInternalContainer(yarp::dev::FrameTransformContainer *&container) override
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
virtual std::string id() const
Return the id assigned to the PolyDriver.
bool view(T *&x)
Get an interface to the device driver.
FrameTransformContainer: A class that contains a vector of frame transformations and exposes yarp::de...
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 setTransforms(const std::vector< yarp::math::FrameTransform > &transforms) override
Save some frame transforms in a storage.
bool deleteTransform(std::string t1, std::string t2) override
Delete a single transform in the storage.
bool clearAll() override
Delete all transforms in a storage.
virtual bool getTransforms(std::vector< yarp::math::FrameTransform > &transforms) const =0
Obtains all frame transforms saved in a storage.
A container for a device driver.
Definition PolyDriver.h:23
bool isValid() const
Check if device is valid.
A mini-server for performing network communication in the background.
bool isRunning() const
Returns true when the thread is started, false otherwise.
void askToStop()
Stop the thread.
bool start()
Call this to start the thread.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
#define yCTrace(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
Definition jointData.cpp:13
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.