YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
MobileBaseVelocityControlRPC.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
6// Autogenerated by Thrift Compiler (0.14.1-yarped)
7//
8// This is an automatically generated file.
9// It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
10
12
14
15#include <algorithm>
16
17// applyVelocityCommandRPC helper class declaration
20{
21public:
23 MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper(const double x_vel, const double y_vel, const double theta_vel, const double timeout);
24 bool write(yarp::os::ConnectionWriter& connection) const override;
25 bool read(yarp::os::ConnectionReader& connection) override;
26
27 class Command :
29 {
30 public:
31 Command() = default;
32 Command(const double x_vel, const double y_vel, const double theta_vel, const double timeout);
33
34 ~Command() override = default;
35
36 bool write(yarp::os::ConnectionWriter& connection) const override;
37 bool read(yarp::os::ConnectionReader& connection) override;
38
39 bool write(const yarp::os::idl::WireWriter& writer) const override;
40 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
41 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
42
43 bool read(yarp::os::idl::WireReader& reader) override;
46
47 double x_vel{0.0};
48 double y_vel{0.0};
49 double theta_vel{0.0};
50 double timeout{0.0};
51 };
52
53 class Reply :
55 {
56 public:
57 Reply() = default;
58 ~Reply() override = default;
59
60 bool write(yarp::os::ConnectionWriter& connection) const override;
61 bool read(yarp::os::ConnectionReader& connection) override;
62
63 bool write(const yarp::os::idl::WireWriter& writer) const override;
64 bool read(yarp::os::idl::WireReader& reader) override;
65
67 };
68
69 using funcptr_t = yarp::dev::ReturnValue (*)(const double, const double, const double, const double);
71
74
75 static constexpr const char* s_tag{"applyVelocityCommandRPC"};
76 static constexpr size_t s_tag_len{1};
77 static constexpr size_t s_cmd_len{5};
78 static constexpr size_t s_reply_len{1};
79 static constexpr const char* s_prototype{"yarp::dev::ReturnValue MobileBaseVelocityControlRPC::applyVelocityCommandRPC(const double x_vel, const double y_vel, const double theta_vel, const double timeout)"};
80 static constexpr const char* s_help{""};
81};
82
83// getLastVelocityCommandRPC helper class declaration
86{
87public:
89 bool write(yarp::os::ConnectionWriter& connection) const override;
90 bool read(yarp::os::ConnectionReader& connection) override;
91
92 class Command :
94 {
95 public:
96 Command() = default;
97 ~Command() override = default;
98
99 bool write(yarp::os::ConnectionWriter& connection) const override;
100 bool read(yarp::os::ConnectionReader& connection) override;
101
102 bool write(const yarp::os::idl::WireWriter& writer) const override;
103 bool writeTag(const yarp::os::idl::WireWriter& writer) const;
104 bool writeArgs(const yarp::os::idl::WireWriter& writer) const;
105
106 bool read(yarp::os::idl::WireReader& reader) override;
109 };
110
111 class Reply :
113 {
114 public:
115 Reply() = default;
116 ~Reply() override = default;
117
118 bool write(yarp::os::ConnectionWriter& connection) const override;
119 bool read(yarp::os::ConnectionReader& connection) override;
120
121 bool write(const yarp::os::idl::WireWriter& writer) const override;
122 bool read(yarp::os::idl::WireReader& reader) override;
123
125 };
126
129
132
133 static constexpr const char* s_tag{"getLastVelocityCommandRPC"};
134 static constexpr size_t s_tag_len{1};
135 static constexpr size_t s_cmd_len{1};
136 static constexpr size_t s_reply_len{4};
137 static constexpr const char* s_prototype{"return_getLastVelocityCommand MobileBaseVelocityControlRPC::getLastVelocityCommandRPC()"};
138 static constexpr const char* s_help{""};
139};
140
141// applyVelocityCommandRPC helper class implementation
142MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper::MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper(const double x_vel, const double y_vel, const double theta_vel, const double timeout) :
143 cmd{x_vel, y_vel, theta_vel, timeout}
144{
145}
146
151
156
157MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper::Command::Command(const double x_vel, const double y_vel, const double theta_vel, const double timeout) :
158 x_vel{x_vel},
159 y_vel{y_vel},
160 theta_vel{theta_vel},
161 timeout{timeout}
162{
163}
164
166{
167 yarp::os::idl::WireWriter writer(connection);
168 if (!writer.writeListHeader(s_cmd_len)) {
169 return false;
170 }
171 return write(writer);
172}
173
175{
176 yarp::os::idl::WireReader reader(connection);
177 if (!reader.readListHeader()) {
178 reader.fail();
179 return false;
180 }
181 return read(reader);
182}
183
185{
186 if (!writeTag(writer)) {
187 return false;
188 }
189 if (!writeArgs(writer)) {
190 return false;
191 }
192 return true;
193}
194
196{
197 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
198 return false;
199 }
200 return true;
201}
202
204{
205 if (!writer.writeFloat64(x_vel)) {
206 return false;
207 }
208 if (!writer.writeFloat64(y_vel)) {
209 return false;
210 }
211 if (!writer.writeFloat64(theta_vel)) {
212 return false;
213 }
214 if (!writer.writeFloat64(timeout)) {
215 return false;
216 }
217 return true;
218}
219
221{
222 if (!readTag(reader)) {
223 return false;
224 }
225 if (!readArgs(reader)) {
226 return false;
227 }
228 return true;
229}
230
232{
233 std::string tag = reader.readTag(s_tag_len);
234 if (reader.isError()) {
235 return false;
236 }
237 if (tag != s_tag) {
238 reader.fail();
239 return false;
240 }
241 return true;
242}
243
245{
246 if (reader.noMore()) {
247 reader.fail();
248 return false;
249 }
250 if (!reader.readFloat64(x_vel)) {
251 reader.fail();
252 return false;
253 }
254 if (reader.noMore()) {
255 reader.fail();
256 return false;
257 }
258 if (!reader.readFloat64(y_vel)) {
259 reader.fail();
260 return false;
261 }
262 if (reader.noMore()) {
263 reader.fail();
264 return false;
265 }
266 if (!reader.readFloat64(theta_vel)) {
267 reader.fail();
268 return false;
269 }
270 if (reader.noMore()) {
271 reader.fail();
272 return false;
273 }
274 if (!reader.readFloat64(timeout)) {
275 reader.fail();
276 return false;
277 }
278 if (!reader.noMore()) {
279 reader.fail();
280 return false;
281 }
282 return true;
283}
284
290
296
298{
299 if (!writer.isNull()) {
300 if (!writer.write(return_helper)) {
301 return false;
302 }
303 }
304 return true;
305}
306
308{
309 if (reader.noMore()) {
310 reader.fail();
311 return false;
312 }
313 if (!reader.read(return_helper)) {
314 reader.fail();
315 return false;
316 }
317 return true;
318}
319
324
325// getLastVelocityCommandRPC helper class implementation
330
335
337{
338 yarp::os::idl::WireWriter writer(connection);
339 if (!writer.writeListHeader(s_cmd_len)) {
340 return false;
341 }
342 return write(writer);
343}
344
346{
347 yarp::os::idl::WireReader reader(connection);
348 if (!reader.readListHeader()) {
349 reader.fail();
350 return false;
351 }
352 return read(reader);
353}
354
356{
357 if (!writeTag(writer)) {
358 return false;
359 }
360 if (!writeArgs(writer)) {
361 return false;
362 }
363 return true;
364}
365
367{
368 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
369 return false;
370 }
371 return true;
372}
373
378
380{
381 if (!readTag(reader)) {
382 return false;
383 }
384 if (!readArgs(reader)) {
385 return false;
386 }
387 return true;
388}
389
391{
392 std::string tag = reader.readTag(s_tag_len);
393 if (reader.isError()) {
394 return false;
395 }
396 if (tag != s_tag) {
397 reader.fail();
398 return false;
399 }
400 return true;
401}
402
404{
405 if (!reader.noMore()) {
406 reader.fail();
407 return false;
408 }
409 return true;
410}
411
417
423
425{
426 if (!writer.isNull()) {
427 if (!writer.writeListHeader(s_reply_len)) {
428 return false;
429 }
430 if (!writer.write(return_helper)) {
431 return false;
432 }
433 }
434 return true;
435}
436
438{
439 if (!reader.readListReturn()) {
440 return false;
441 }
442 if (reader.noMore()) {
443 reader.fail();
444 return false;
445 }
446 if (!reader.read(return_helper)) {
447 reader.fail();
448 return false;
449 }
450 return true;
451}
452
457
458// Constructor
463
464yarp::dev::ReturnValue MobileBaseVelocityControlRPC::applyVelocityCommandRPC(const double x_vel, const double y_vel, const double theta_vel, const double timeout)
465{
466 if (!yarp().canWrite()) {
468 }
469 MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper helper{x_vel, y_vel, theta_vel, timeout};
470 bool ok = yarp().write(helper, helper);
471 return ok ? helper.reply.return_helper : yarp::dev::ReturnValue{};
472}
473
475{
476 if (!yarp().canWrite()) {
478 }
480 bool ok = yarp().write(helper, helper);
481 return ok ? helper.reply.return_helper : return_getLastVelocityCommand{};
482}
483
484// help method
485std::vector<std::string> MobileBaseVelocityControlRPC::help(const std::string& functionName)
486{
487 bool showAll = (functionName == "--all");
488 std::vector<std::string> helpString;
489 if (showAll) {
490 helpString.emplace_back("*** Available commands:");
493 helpString.emplace_back("help");
494 } else {
497 }
500 }
501 if (functionName == "help") {
502 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
503 helpString.emplace_back("Return list of available commands, or help message for a specific function");
504 helpString.emplace_back("@param functionName name of command for which to get a detailed description. If none or '--all' is provided, print list of available commands");
505 helpString.emplace_back("@return list of strings (one string per line)");
506 }
507 }
508 if (helpString.empty()) {
509 helpString.emplace_back("Command not found");
510 }
511 return helpString;
512}
513
514// read from ConnectionReader
516{
517 constexpr size_t max_tag_len = 1;
518 size_t tag_len = 1;
519
520 yarp::os::idl::WireReader reader(connection);
521 reader.expectAccept();
522 if (!reader.readListHeader()) {
523 reader.fail();
524 return false;
525 }
526
527 std::string tag = reader.readTag(1);
528 bool direct = (tag == "__direct__");
529 if (direct) {
530 tag = reader.readTag(1);
531 }
532 while (tag_len <= max_tag_len && !reader.isError()) {
535 if (!helper.cmd.readArgs(reader)) {
536 return false;
537 }
538
539 helper.call(this);
540
541 yarp::os::idl::WireWriter writer(reader);
542 if (!helper.reply.write(writer)) {
543 return false;
544 }
545 reader.accept();
546 return true;
547 }
550 if (!helper.cmd.readArgs(reader)) {
551 return false;
552 }
553
554 helper.call(this);
555
556 yarp::os::idl::WireWriter writer(reader);
557 if (!helper.reply.write(writer)) {
558 return false;
559 }
560 reader.accept();
561 return true;
562 }
563 if (tag == "help") {
564 std::string functionName;
565 if (!reader.readString(functionName)) {
566 functionName = "--all";
567 }
568 auto help_strings = help(functionName);
569 yarp::os::idl::WireWriter writer(reader);
570 if (!writer.isNull()) {
571 if (!writer.writeListHeader(2)) {
572 return false;
573 }
574 if (!writer.writeTag("many", 1, 0)) {
575 return false;
576 }
577 if (!writer.writeListBegin(0, help_strings.size())) {
578 return false;
579 }
580 for (const auto& help_string : help_strings) {
581 if (!writer.writeString(help_string)) {
582 return false;
583 }
584 }
585 if (!writer.writeListEnd()) {
586 return false;
587 }
588 }
589 reader.accept();
590 return true;
591 }
592 if (reader.noMore()) {
593 reader.fail();
594 return false;
595 }
596 std::string next_tag = reader.readTag(1);
597 if (next_tag.empty()) {
598 break;
599 }
600 tag.append("_").append(next_tag);
601 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
602 }
603 return false;
604}
#define yError(...)
Definition Log.h:361
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
yarp::dev::ReturnValue(*)(const double, const double, const double, const double) funcptr_t
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
virtual std::vector< std::string > help(const std::string &functionName="--all")
virtual yarp::dev::ReturnValue applyVelocityCommandRPC(const double x_vel, const double y_vel, const double theta_vel, const double timeout)
virtual return_getLastVelocityCommand getLastVelocityCommandRPC()
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
IDL-friendly connection reader.
Definition WireReader.h:27
bool readString(std::string &str, bool *is_vocab=nullptr)
std::string readTag(size_t len=static_cast< size_t >(-1))
bool read(WirePortable &obj)
bool readFloat64(yarp::conf::float64_t &x)
IDL-friendly connection writer.
Definition WireWriter.h:28
bool write(const WirePortable &obj) const
bool writeListHeader(int len) const
bool writeTag(const char *tag, int split, int len) const
bool writeFloat64(yarp::conf::float64_t x, bool skip_tag=false) const
bool writeString(const std::string &str, bool skip_tag=false) const
bool writeListBegin(int tag, size_t len) const
The main, catch-all namespace for YARP.
Definition dirs.h:16