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
66 bool return_helper{false};
67 };
68
69 using funcptr_t = bool (*)(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{"bool 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.writeListHeader(s_reply_len)) {
301 return false;
302 }
303 if (!writer.writeBool(return_helper)) {
304 return false;
305 }
306 }
307 return true;
308}
309
311{
312 if (!reader.readListReturn()) {
313 return false;
314 }
315 if (reader.noMore()) {
316 reader.fail();
317 return false;
318 }
319 if (!reader.readBool(return_helper)) {
320 reader.fail();
321 return false;
322 }
323 return true;
324}
325
330
331// getLastVelocityCommandRPC helper class implementation
336
341
343{
344 yarp::os::idl::WireWriter writer(connection);
345 if (!writer.writeListHeader(s_cmd_len)) {
346 return false;
347 }
348 return write(writer);
349}
350
352{
353 yarp::os::idl::WireReader reader(connection);
354 if (!reader.readListHeader()) {
355 reader.fail();
356 return false;
357 }
358 return read(reader);
359}
360
362{
363 if (!writeTag(writer)) {
364 return false;
365 }
366 if (!writeArgs(writer)) {
367 return false;
368 }
369 return true;
370}
371
373{
374 if (!writer.writeTag(s_tag, 1, s_tag_len)) {
375 return false;
376 }
377 return true;
378}
379
384
386{
387 if (!readTag(reader)) {
388 return false;
389 }
390 if (!readArgs(reader)) {
391 return false;
392 }
393 return true;
394}
395
397{
398 std::string tag = reader.readTag(s_tag_len);
399 if (reader.isError()) {
400 return false;
401 }
402 if (tag != s_tag) {
403 reader.fail();
404 return false;
405 }
406 return true;
407}
408
410{
411 if (!reader.noMore()) {
412 reader.fail();
413 return false;
414 }
415 return true;
416}
417
423
429
431{
432 if (!writer.isNull()) {
433 if (!writer.writeListHeader(s_reply_len)) {
434 return false;
435 }
436 if (!writer.write(return_helper)) {
437 return false;
438 }
439 }
440 return true;
441}
442
444{
445 if (!reader.readListReturn()) {
446 return false;
447 }
448 if (reader.noMore()) {
449 reader.fail();
450 return false;
451 }
452 if (!reader.read(return_helper)) {
453 reader.fail();
454 return false;
455 }
456 return true;
457}
458
463
464// Constructor
469
470bool MobileBaseVelocityControlRPC::applyVelocityCommandRPC(const double x_vel, const double y_vel, const double theta_vel, const double timeout)
471{
472 if (!yarp().canWrite()) {
474 }
475 MobileBaseVelocityControlRPC_applyVelocityCommandRPC_helper helper{x_vel, y_vel, theta_vel, timeout};
476 bool ok = yarp().write(helper, helper);
477 return ok ? helper.reply.return_helper : bool{};
478}
479
481{
482 if (!yarp().canWrite()) {
484 }
486 bool ok = yarp().write(helper, helper);
487 return ok ? helper.reply.return_helper : return_getLastVelocityCommand{};
488}
489
490// help method
491std::vector<std::string> MobileBaseVelocityControlRPC::help(const std::string& functionName)
492{
493 bool showAll = (functionName == "--all");
494 std::vector<std::string> helpString;
495 if (showAll) {
496 helpString.emplace_back("*** Available commands:");
499 helpString.emplace_back("help");
500 } else {
503 }
506 }
507 if (functionName == "help") {
508 helpString.emplace_back("std::vector<std::string> help(const std::string& functionName = \"--all\")");
509 helpString.emplace_back("Return list of available commands, or help message for a specific function");
510 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");
511 helpString.emplace_back("@return list of strings (one string per line)");
512 }
513 }
514 if (helpString.empty()) {
515 helpString.emplace_back("Command not found");
516 }
517 return helpString;
518}
519
520// read from ConnectionReader
522{
523 constexpr size_t max_tag_len = 1;
524 size_t tag_len = 1;
525
526 yarp::os::idl::WireReader reader(connection);
527 reader.expectAccept();
528 if (!reader.readListHeader()) {
529 reader.fail();
530 return false;
531 }
532
533 std::string tag = reader.readTag(1);
534 bool direct = (tag == "__direct__");
535 if (direct) {
536 tag = reader.readTag(1);
537 }
538 while (tag_len <= max_tag_len && !reader.isError()) {
541 if (!helper.cmd.readArgs(reader)) {
542 return false;
543 }
544
545 helper.call(this);
546
547 yarp::os::idl::WireWriter writer(reader);
548 if (!helper.reply.write(writer)) {
549 return false;
550 }
551 reader.accept();
552 return true;
553 }
556 if (!helper.cmd.readArgs(reader)) {
557 return false;
558 }
559
560 helper.call(this);
561
562 yarp::os::idl::WireWriter writer(reader);
563 if (!helper.reply.write(writer)) {
564 return false;
565 }
566 reader.accept();
567 return true;
568 }
569 if (tag == "help") {
570 std::string functionName;
571 if (!reader.readString(functionName)) {
572 functionName = "--all";
573 }
574 auto help_strings = help(functionName);
575 yarp::os::idl::WireWriter writer(reader);
576 if (!writer.isNull()) {
577 if (!writer.writeListHeader(2)) {
578 return false;
579 }
580 if (!writer.writeTag("many", 1, 0)) {
581 return false;
582 }
583 if (!writer.writeListBegin(0, help_strings.size())) {
584 return false;
585 }
586 for (const auto& help_string : help_strings) {
587 if (!writer.writeString(help_string)) {
588 return false;
589 }
590 }
591 if (!writer.writeListEnd()) {
592 return false;
593 }
594 }
595 reader.accept();
596 return true;
597 }
598 if (reader.noMore()) {
599 reader.fail();
600 return false;
601 }
602 std::string next_tag = reader.readTag(1);
603 if (next_tag.empty()) {
604 break;
605 }
606 tag.append("_").append(next_tag);
607 tag_len = std::count(tag.begin(), tag.end(), '_') + 1;
608 }
609 return false;
610}
#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.
bool(*)(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 bool 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 writeBool(bool x, bool skip_tag=false) const
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