YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RgbVisualParams_Responder.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include "CameraVocabs.h"
8
9#include <yarp/os/LogStream.h>
10
12
14{
15 bool ret = false;
16 if (interface) {
17 iRgbVisual = interface;
18 ret = true;
19 } else {
20 iRgbVisual = nullptr;
21 ret = false;
22 }
23 return ret;
24}
25
27{
28 bool ret = false;
29 response.clear();
30 if (!iRgbVisual) {
31 yError() << "Rgb Visual parameter Parser has not been correctly configures. IRgbVisualParams interface is not valid";
32 response.addVocab32(VOCAB_FAILED);
33 return false;
34 }
35
36 int code = cmd.get(0).asVocab32();
37 if (code != VOCAB_RGB_VISUAL_PARAMS) {
38 yError() << "Rgb Visual Params Parser received a command not belonging to this interface. Required interface is " << yarp::os::Vocab32::decode(code);
39 response.addVocab32(VOCAB_FAILED);
40 return false;
41 }
42
43 switch (cmd.get(1).asVocab32()) {
44 case VOCAB_GET: {
45 switch (cmd.get(2).asVocab32()) {
46 case VOCAB_HEIGHT:
48 response.addVocab32(VOCAB_HEIGHT);
49 response.addVocab32(VOCAB_IS);
50 response.addInt32(iRgbVisual->getRgbHeight());
51 ret = true;
52 break;
53
54 case VOCAB_WIDTH:
56 response.addVocab32(VOCAB_WIDTH);
57 response.addVocab32(VOCAB_IS);
58 response.addInt32(iRgbVisual->getRgbWidth());
59 ret = true;
60 break;
61
64 ret = iRgbVisual->getRgbSupportedConfigurations(conf);
65 if (ret) {
68 response.addVocab32(VOCAB_IS);
69 response.addInt32(conf.size());
70 for (const auto& i : conf) {
71 response.addInt32(i.width);
72 response.addInt32(i.height);
73 response.addFloat64(i.framerate);
74 response.addVocab32(i.pixelCoding);
75 }
76 } else {
77 response.addVocab32(VOCAB_FAILED);
78 }
79 } break;
80
81
82 case VOCAB_RESOLUTION: {
83 int width;
84 int height;
85 ret = iRgbVisual->getRgbResolution(width, height);
86 if (ret) {
89 response.addVocab32(VOCAB_IS);
90 response.addInt32(width);
91 response.addInt32(height);
92 } else {
93 response.addVocab32(VOCAB_FAILED);
94 }
95 } break;
96
97 case VOCAB_FOV: {
98 double hFov;
99 double vFov;
100 ret = iRgbVisual->getRgbFOV(hFov, vFov);
101 if (ret) {
103 response.addVocab32(VOCAB_FOV);
104 response.addVocab32(VOCAB_IS);
105 response.addFloat64(hFov);
106 response.addFloat64(vFov);
107 } else {
108 response.addVocab32(VOCAB_FAILED);
109 }
110 } break;
111
113 yarp::os::Property params;
114 ret = iRgbVisual->getRgbIntrinsicParam(params);
115 if (ret) {
118 response.addVocab32(VOCAB_IS);
119 yarp::os::Bottle& tmp = response.addList();
121 } else {
122 response.addVocab32(VOCAB_FAILED);
123 }
124 } break;
125
126 case VOCAB_MIRROR: {
127 bool mirror;
128 ret = iRgbVisual->getRgbMirroring(mirror);
129 if (ret) {
131 response.addVocab32(VOCAB_MIRROR);
132 response.addVocab32(VOCAB_IS);
133 response.addInt32(mirror);
134 } else {
135 response.addVocab32(VOCAB_FAILED);
136 }
137 } break;
138
139 default:
140 {
141 yError() << "Rgb Visual Parameter interface parser received an unknown GET command. Command is " << cmd.toString();
142 response.addVocab32(VOCAB_FAILED);
143 ret = false;
144 } break;
145 }
146 } break;
147
148 case VOCAB_SET: {
149 switch (cmd.get(2).asVocab32()) {
150 case VOCAB_RESOLUTION:
151 ret = iRgbVisual->setRgbResolution(cmd.get(3).asInt32(), cmd.get(4).asInt32());
153 response.addVocab32(VOCAB_SET);
154 response.addInt32(ret);
155 break;
156
157 case VOCAB_FOV:
158 ret = iRgbVisual->setRgbFOV(cmd.get(3).asFloat64(), cmd.get(4).asFloat64());
160 response.addVocab32(VOCAB_SET);
161 response.addInt32(ret);
162 break;
163
164 case VOCAB_MIRROR: {
165 ret = iRgbVisual->setRgbMirroring(cmd.get(3).asBool());
167 response.addVocab32(VOCAB_SET);
168 response.addInt32(ret);
169 } break;
170
171 default:
172 {
173 yError() << "Rgb Visual Parameter interface parser received am unknown SET command. Command is " << cmd.toString();
174 response.addVocab32(VOCAB_FAILED);
175 ret = false;
176 } break;
177 }
178 } // end VOCAB
179 break;
180
181 default:
182 {
183 yError() << "Rgb Visual parameter interface Parser received a malformed request. Command should either be 'set' or 'get', received " << cmd.toString();
184 response.addVocab32(VOCAB_FAILED);
185 ret = false;
186 } break;
187 }
188 return ret;
189}
constexpr yarp::conf::vocab32_t VOCAB_RGB_VISUAL_PARAMS
constexpr yarp::conf::vocab32_t VOCAB_RESOLUTION
constexpr yarp::conf::vocab32_t VOCAB_MIRROR
constexpr yarp::conf::vocab32_t VOCAB_FOV
constexpr yarp::conf::vocab32_t VOCAB_INTRINSIC_PARAM
constexpr yarp::conf::vocab32_t VOCAB_SUPPORTED_CONF
constexpr yarp::conf::vocab32_t VOCAB_IS
constexpr yarp::conf::vocab32_t VOCAB_WIDTH
constexpr yarp::conf::vocab32_t VOCAB_GET
constexpr yarp::conf::vocab32_t VOCAB_FAILED
constexpr yarp::conf::vocab32_t VOCAB_SET
constexpr yarp::conf::vocab32_t VOCAB_HEIGHT
bool ret
#define yError(...)
Definition Log.h:361
An interface for retrieving intrinsic parameter from a rgb camera.
virtual bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations)
Get the possible configurations of the camera.
virtual bool setRgbMirroring(bool mirror)=0
Set the mirroring setting of the sensor.
virtual bool getRgbIntrinsicParam(yarp::os::Property &intrinsic)=0
Get the intrinsic parameters of the rgb camera.
virtual bool getRgbResolution(int &width, int &height)
Get the resolution of the rgb image from the camera.
virtual bool setRgbResolution(int width, int height)=0
Set the resolution of the rgb image from the camera.
virtual bool getRgbMirroring(bool &mirror)=0
Get the mirroring setting of the sensor.
virtual int getRgbHeight()=0
Return the height of each frame.
virtual bool getRgbFOV(double &horizontalFov, double &verticalFov)=0
Get the field of view (FOV) of the rgb camera.
virtual bool setRgbFOV(double horizontalFov, double verticalFov)=0
Set the field of view (FOV) of the rgb camera.
virtual int getRgbWidth()=0
Return the width of each frame.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition Bottle.cpp:164
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
Definition Bottle.cpp:182
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Definition Bottle.cpp:158
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
void clear()
Empties the bottle of any objects it contains.
Definition Bottle.cpp:121
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition Bottle.cpp:140
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:211
static bool copyPortable(const PortWriter &writer, PortReader &reader)
Copy one portable to another, via writing and reading.
Definition Portable.cpp:16
A class for storing options and configuration information.
Definition Property.h:33
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition Value.cpp:222
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
Definition Value.cpp:228
virtual bool asBool() const
Get boolean value.
Definition Value.cpp:186
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition Value.cpp:204
bool configure(yarp::dev::IRgbVisualParams *interface)
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
size_t size() const
Definition Vector.h:341
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition Vocab.cpp:33