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
55yarp::dev::ReturnValue 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
61yarp::dev::ReturnValue 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
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
132{
134 {
135 return ReturnValue_ok;
136 }
137 return ReturnValue::return_code::return_value_error_method_failed;
138}
139
141{
142 if (this->start())
143 {
144 return ReturnValue_ok;
145 }
146 return ReturnValue::return_code::return_value_error_method_failed;
147}
148
150{
151 this->askToStop();
152 do
153 {
155 }
156 while (this->isRunning());
157 return ReturnValue_ok;
158}
#define ReturnValue_ok
Definition ReturnValue.h:77
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.
yarp::dev::ReturnValue setTransforms(const std::vector< yarp::math::FrameTransform > &transforms) override
Save some frame transforms in a storage.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue clearAll() override
Delete all transforms in a storage.
yarp::dev::ReturnValue deleteTransform(std::string t1, std::string t2) override
Delete a single transform in the storage.
yarp::dev::ReturnValue startStorageThread() override
yarp::dev::ReturnValue size(size_t &size) const override
yarp::dev::ReturnValue getTransforms(std::vector< yarp::math::FrameTransform > &transforms) const override
Obtains all frame transforms saved in a storage.
bool detach() override
Detach the object (you must have first called attach).
yarp::dev::ReturnValue setTransform(const yarp::math::FrameTransform &transform) override
Save a frame transform in a storage.
yarp::dev::ReturnValue getInternalContainer(yarp::dev::FrameTransformContainer *&container) override
yarp::dev::ReturnValue stopStorageThread() 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...
yarp::dev::ReturnValue getTransforms(std::vector< yarp::math::FrameTransform > &transforms) const override
Obtains all frame transforms saved in a storage.
yarp::dev::ReturnValue setTransform(const yarp::math::FrameTransform &transform) override
Save a frame transform in a storage.
yarp::dev::ReturnValue setTransforms(const std::vector< yarp::math::FrameTransform > &transforms) override
Save some frame transforms in a storage.
yarp::dev::ReturnValue clearAll() override
Delete all transforms in a storage.
yarp::dev::ReturnValue deleteTransform(std::string t1, std::string t2) override
Delete a single transform in the storage.
virtual yarp::dev::ReturnValue 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.
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.