YARP
Yet Another Robot Platform
RgbVisualParams_Forwarder.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 
10 
11 RgbVisualParams_Forwarder::RgbVisualParams_Forwarder(yarp::os::Port& port) :
12  m_port(port)
13 {
14 };
15 
17 {
18  yarp::os::Bottle cmd;
19  yarp::os::Bottle response;
21  cmd.addVocab32(VOCAB_GET);
23  m_port.write(cmd, response);
24  return response.get(3).asInt32();
25 }
26 
28 {
29  yarp::os::Bottle cmd;
30  yarp::os::Bottle response;
32  cmd.addVocab32(VOCAB_GET);
34  m_port.write(cmd, response);
35  return response.get(3).asInt32();
36 }
38 {
39  yarp::os::Bottle cmd;
40  yarp::os::Bottle response;
42  cmd.addVocab32(VOCAB_GET);
44  m_port.write(cmd, response);
45 
46  if ((response.get(0).asVocab32()) == VOCAB_FAILED) {
47  configurations.clear();
48  return false;
49  }
50  configurations.resize(response.get(3).asInt32());
51  for (int i = 0; i < response.get(3).asInt32(); i++) {
52  configurations[i].width = response.get(4 + i * 4).asInt32();
53  configurations[i].height = response.get(4 + i * 4 + 1).asInt32();
54  configurations[i].framerate = response.get(4 + i * 4 + 2).asFloat64();
55  configurations[i].pixelCoding = static_cast<YarpVocabPixelTypesEnum>(response.get(4 + i * 4 + 3).asVocab32());
56  }
57  return true;
58 }
59 bool RgbVisualParams_Forwarder::getRgbResolution(int& width, int& height)
60 {
61  yarp::os::Bottle cmd;
62  yarp::os::Bottle response;
64  cmd.addVocab32(VOCAB_GET);
66  m_port.write(cmd, response);
67 
68  // Minimal check on response, we suppose the response is always correctly formatted
69  if ((response.get(0).asVocab32()) == VOCAB_FAILED) {
70  width = 0;
71  height = 0;
72  return false;
73  }
74  width = response.get(3).asInt32();
75  height = response.get(4).asInt32();
76  return true;
77 }
78 
80 {
81  yarp::os::Bottle cmd;
82  yarp::os::Bottle response;
84  cmd.addVocab32(VOCAB_SET);
86  cmd.addInt32(width);
87  cmd.addInt32(height);
88  m_port.write(cmd, response);
89  return response.get(2).asBool();
90 }
91 
92 bool RgbVisualParams_Forwarder::getRgbFOV(double& horizontalFov, double& verticalFov)
93 {
94  yarp::os::Bottle cmd;
95  yarp::os::Bottle response;
97  cmd.addVocab32(VOCAB_GET);
98  cmd.addVocab32(VOCAB_FOV);
99  m_port.write(cmd, response);
100 
101  // Minimal check on response, we suppose the response is always correctly formatted
102  if ((response.get(0).asVocab32()) == VOCAB_FAILED) {
103  horizontalFov = 0;
104  verticalFov = 0;
105  return false;
106  }
107  horizontalFov = response.get(3).asFloat64();
108  verticalFov = response.get(4).asFloat64();
109  return true;
110 }
111 
112 bool RgbVisualParams_Forwarder::setRgbFOV(double horizontalFov, double verticalFov)
113 {
114  yarp::os::Bottle cmd;
115  yarp::os::Bottle response;
117  cmd.addVocab32(VOCAB_SET);
118  cmd.addVocab32(VOCAB_FOV);
119  cmd.addFloat64(horizontalFov);
120  cmd.addFloat64(verticalFov);
121  m_port.write(cmd, response);
122  return response.get(2).asBool();
123 }
124 
126 {
127  yarp::os::Bottle cmd;
128  yarp::os::Bottle response;
130  cmd.addVocab32(VOCAB_GET);
132  m_port.write(cmd, response);
133 
134  // Minimal check on response, we suppose the response is always correctly formatted
135  if ((response.get(0).asVocab32()) == VOCAB_FAILED) {
136  intrinsic.clear();
137  return false;
138  }
139  bool ret;
140  ret = yarp::os::Property::copyPortable(response.get(3), intrinsic);
141  if (!response.get(4).isNull()) {
142  yarp::os::Property& p = intrinsic.addGroup("right");
143  ret &= yarp::os::Property::copyPortable(response.get(4), p);
144  return ret;
145  }
146  return ret;
147 }
148 
150 {
151  yarp::os::Bottle cmd;
152  yarp::os::Bottle response;
154  cmd.addVocab32(VOCAB_GET);
156  m_port.write(cmd, response);
157  if ((response.get(0).asVocab32()) == VOCAB_FAILED) {
158  return false;
159  }
160  mirror = response.get(3).asBool();
161  return true;
162 }
163 
165 {
166  yarp::os::Bottle cmd;
167  yarp::os::Bottle response;
169  cmd.addVocab32(VOCAB_SET);
171  cmd.addInt32(mirror);
172  m_port.write(cmd, response);
173  return response.get(2).asBool();
174 }
constexpr yarp::conf::vocab32_t VOCAB_RGB_VISUAL_PARAMS
Definition: CameraVocabs.h:18
constexpr yarp::conf::vocab32_t VOCAB_RESOLUTION
Definition: CameraVocabs.h:104
constexpr yarp::conf::vocab32_t VOCAB_MIRROR
Definition: CameraVocabs.h:101
constexpr yarp::conf::vocab32_t VOCAB_FOV
Definition: CameraVocabs.h:105
constexpr yarp::conf::vocab32_t VOCAB_INTRINSIC_PARAM
Definition: CameraVocabs.h:106
constexpr yarp::conf::vocab32_t VOCAB_SUPPORTED_CONF
Definition: CameraVocabs.h:107
constexpr yarp::conf::vocab32_t VOCAB_WIDTH
Definition: GenericVocabs.h:41
constexpr yarp::conf::vocab32_t VOCAB_GET
Definition: GenericVocabs.h:13
constexpr yarp::conf::vocab32_t VOCAB_FAILED
Definition: GenericVocabs.h:16
constexpr yarp::conf::vocab32_t VOCAB_SET
Definition: GenericVocabs.h:12
constexpr yarp::conf::vocab32_t VOCAB_HEIGHT
Definition: GenericVocabs.h:42
bool ret
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.cpp:164
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 addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:140
A mini-server for network communication.
Definition: Port.h:47
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition: Port.cpp:427
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:34
void clear()
Remove all associations.
Definition: Property.cpp:1057
Property & addGroup(const std::string &key)
Add a nested group.
Definition: Property.cpp:1232
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 isNull() const override
Checks if the object is invalid.
Definition: Value.cpp:380
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
int getRgbHeight() override
Return the height of each frame.
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
int getRgbWidth() override
Return the width of each frame.
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
void resize(size_t size) override
Resize the vector.
Definition: Vector.h:222
YarpVocabPixelTypesEnum
Definition: Image.h:43