YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FrameWriter_nws_yarp.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7
9#include <yarp/os/LogStream.h>
10
11#include <yarp/dev/PolyDriver.h>
12
13namespace {
14YARP_LOG_COMPONENT(FRAMEWRITER_NWS_YARP, "yarp.device.frameWriter_nws_yarp")
15} // namespace
16
17using namespace yarp::sig;
18
19static constexpr double DEFAULT_THREAD_PERIOD = 0.033; // seconds
20
25
26
31
32
34{
35 detach();
36
37 m_portProc.close();
38 rpcPort.close();
39
40 return true;
41}
42
43
45{
46 if (!this->parseParams(config)) { return false; }
47
48 PeriodicThread::setPeriod(0.010);
49
50 // Check "name" option and open ports
51 std::string pImg_Name = m_name;
52 std::string rpcPort_Name = pImg_Name + "/rpc";
53
54 if (!rpcPort.open(rpcPort_Name)) {
55 yCError(FRAMEWRITER_NWS_YARP) << "Unable to open rpc Port" << rpcPort_Name.c_str();
56 return false;
57 }
58
59 if (!m_portProc.open(pImg_Name)) {
60 yCError(FRAMEWRITER_NWS_YARP) << "Unable to open image input Port" << pImg_Name.c_str();
61 return false;
62 }
63 m_portProc.useCallback();
64
65 yCInfo(FRAMEWRITER_NWS_YARP) << "Running, waiting for attach...";
66
67 return true;
68}
69
71{
72 if (!poly->isValid()) {
73 yCError(FRAMEWRITER_NWS_YARP) << "Device " << poly << " to attach to is not valid ... cannot proceed";
74 return false;
75 }
76
77 poly->view(iFrameWriterImage);
78
79 return PeriodicThread::start();
80}
81
82
84{
87 }
88
89 iFrameWriterImage = nullptr;
90
91 return true;
92}
93
95{
96 return true;
97}
98
99// Processes the received images
101{
102 std::vector<yarp::sig::FlexImage> vec;
103 m_portProc.getLast(vec);
104
105 for (auto it = vec.begin(); it != vec.end(); it++)
106 {
107 if (it->getPixelCode() == VOCAB_PIXEL_RGB) {
109 iFrameWriterImage->putImage(img);
110 }
111 else
112 {
113 yCError(FRAMEWRITER_NWS_YARP) << "Unsupported image type received";
114 }
115 }
116}
static constexpr double DEFAULT_THREAD_PERIOD
@ VOCAB_PIXEL_RGB
Definition Image.h:44
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool detach() override
Detach the object (you must have first called attach).
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
void run() override
Loop function.
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
bool threadInit() override
Initialization method.
void getLast(std::vector< yarp::sig::FlexImage > &img)
bool view(T *&x)
Get an interface to the device driver.
virtual bool putImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)=0
Write an image to the device.
A container for a device driver.
Definition PolyDriver.h:23
bool isValid() const
Check if device is valid.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void close() override
Stop port activity.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void useCallback(TypedReaderCallback< T > &callback) override
Set an object whose onRead method will be called when data is available.
bool isRunning() const
Returns true when the thread is started, false otherwise.
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
Typed image class.
Definition Image.h:605
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)