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>
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//------------------------------------------------------------------------------------------------------------------------------
22{
23 container = &m_tf_container;
24 return true;
25}
26
28{
29 std::string sstr = config.toString();
30
31 if (config.check("FrameTransform_verbose_debug") &&
32 config.find("FrameTransform_verbose_debug").asInt32() == 1)
33 {
35 m_tf_container.m_name = this->id() + ".container";
36 }
37
38 yCTrace(FRAMETRANSFORSTORAGE);
39 bool b = this->start();
40 return b;
41}
42
44{
45 return true;
46}
47
48bool FrameTransformStorage::getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const
49{
50 std::lock_guard <std::mutex> lg(m_pd_mutex);
51 return m_tf_container.getTransforms(transforms);
52}
53
54bool FrameTransformStorage::setTransforms(const std::vector<yarp::math::FrameTransform>& transforms)
55{
56 std::lock_guard <std::mutex> lg(m_pd_mutex);
57 return m_tf_container.setTransforms(transforms);
58}
59
61{
62 std::lock_guard <std::mutex> lg(m_pd_mutex);
64}
65
66bool FrameTransformStorage::deleteTransform(std::string t1, std::string t2)
67{
68 std::lock_guard <std::mutex> lg(m_pd_mutex);
69 return m_tf_container.deleteTransform(t1,t2);
70}
71
72void FrameTransformStorage::run()
73{
74 std::lock_guard <std::mutex> lg(m_pd_mutex);
75
76 // remove expired non static transforms
78
79 // get new transforms
80 if (iGetIf)
81 {
82 std::vector<yarp::math::FrameTransform> tfs;
83 bool b=iGetIf->getTransforms(tfs);
84 if (b)
85 {
87 }
88 }
89}
90
92{
93 std::lock_guard <std::mutex> lg(m_pd_mutex);
94 iGetIf = nullptr;
95 pDriver = nullptr;
96 if(isRunning())
97 {
98 stop();
99 }
100 return true;
101}
102
104{
105 std::lock_guard <std::mutex> lg(m_pd_mutex);
106 if (driver->isValid())
107 {
108 pDriver = driver;
109 pDriver->view(iGetIf);
110 if(iGetIf)
111 {
112 return true;
113 }
114 }
115
116 return false;
117}
118
120{
121 return m_tf_container.clearAll();
122}
123
124bool FrameTransformStorage::size(size_t& size) const
125{
126 return m_tf_container.size(size);
127}
128
130{
131 return this->start();
132}
133
135{
136 this->askToStop();
137 do
138 {
140 }
141 while (this->isRunning());
142 return true;
143}
float t
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 size(size_t &size) const
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.
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.
FrameTransformContainer m_tf_container
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.
Definition: DeviceDriver.h:88
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.
Definition: PolyDriver.cpp:196
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:56
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
#define yCTrace(component,...)
Definition: LogComponent.h:84
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76
For streams capable of holding different kinds of content, check what they actually have.
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.