YARP
Yet Another Robot Platform
MobileBaseVelocity.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 // Autogenerated by Thrift Compiler (0.12.0-yarped)
10 //
11 // This is an automatically generated file.
12 // It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
13 
15 
16 namespace yarp {
17 namespace dev {
18 
19 // Default constructor
21  WirePortable(),
22  vel_x(0),
23  vel_y(0),
24  vel_theta(0)
25 {
26 }
27 
28 // Constructor with field values
30  const double vel_y,
31  const double vel_theta) :
32  WirePortable(),
33  vel_x(vel_x),
34  vel_y(vel_y),
35  vel_theta(vel_theta)
36 {
37 }
38 
39 // Read structure on a Wire
41 {
42  if (!read_vel_x(reader)) {
43  return false;
44  }
45  if (!read_vel_y(reader)) {
46  return false;
47  }
48  if (!read_vel_theta(reader)) {
49  return false;
50  }
51  return !reader.isError();
52 }
53 
54 // Read structure on a Connection
56 {
57  yarp::os::idl::WireReader reader(connection);
58  if (!reader.readListHeader(3)) {
59  return false;
60  }
61  return read(reader);
62 }
63 
64 // Write structure on a Wire
66 {
67  if (!write_vel_x(writer)) {
68  return false;
69  }
70  if (!write_vel_y(writer)) {
71  return false;
72  }
73  if (!write_vel_theta(writer)) {
74  return false;
75  }
76  return !writer.isError();
77 }
78 
79 // Write structure on a Connection
81 {
82  yarp::os::idl::WireWriter writer(connection);
83  if (!writer.writeListHeader(3)) {
84  return false;
85  }
86  return write(writer);
87 }
88 
89 // Convert to a printable string
90 std::string MobileBaseVelocity::toString() const
91 {
93  b.read(*this);
94  return b.toString();
95 }
96 
97 // Editor: default constructor
99 {
100  group = 0;
101  obj_owned = true;
102  obj = new MobileBaseVelocity;
103  dirty_flags(false);
104  yarp().setOwner(*this);
105 }
106 
107 // Editor: constructor with base class
109 {
110  group = 0;
111  obj_owned = false;
112  edit(obj, false);
113  yarp().setOwner(*this);
114 }
115 
116 // Editor: destructor
118 {
119  if (obj_owned) {
120  delete obj;
121  }
122 }
123 
124 // Editor: edit
126 {
127  if (obj_owned) {
128  delete this->obj;
129  }
130  this->obj = &obj;
131  obj_owned = false;
132  dirty_flags(dirty);
133  return true;
134 }
135 
136 // Editor: validity check
138 {
139  return obj != nullptr;
140 }
141 
142 // Editor: state
144 {
145  return *obj;
146 }
147 
148 // Editor: grouping begin
150 {
151  group++;
152 }
153 
154 // Editor: grouping end
156 {
157  group--;
158  if (group == 0 && is_dirty) {
159  communicate();
160  }
161 }
162 // Editor: vel_x setter
164 {
165  will_set_vel_x();
166  obj->vel_x = vel_x;
167  mark_dirty_vel_x();
168  communicate();
169  did_set_vel_x();
170 }
171 
172 // Editor: vel_x getter
174 {
175  return obj->vel_x;
176 }
177 
178 // Editor: vel_x will_set
180 {
181  return true;
182 }
183 
184 // Editor: vel_x did_set
186 {
187  return true;
188 }
189 
190 // Editor: vel_y setter
192 {
193  will_set_vel_y();
194  obj->vel_y = vel_y;
195  mark_dirty_vel_y();
196  communicate();
197  did_set_vel_y();
198 }
199 
200 // Editor: vel_y getter
202 {
203  return obj->vel_y;
204 }
205 
206 // Editor: vel_y will_set
208 {
209  return true;
210 }
211 
212 // Editor: vel_y did_set
214 {
215  return true;
216 }
217 
218 // Editor: vel_theta setter
220 {
221  will_set_vel_theta();
222  obj->vel_theta = vel_theta;
223  mark_dirty_vel_theta();
224  communicate();
225  did_set_vel_theta();
226 }
227 
228 // Editor: vel_theta getter
230 {
231  return obj->vel_theta;
232 }
233 
234 // Editor: vel_theta will_set
236 {
237  return true;
238 }
239 
240 // Editor: vel_theta did_set
242 {
243  return true;
244 }
245 
246 // Editor: clean
248 {
249  dirty_flags(false);
250 }
251 
252 // Editor: read
254 {
255  if (!isValid()) {
256  return false;
257  }
258  yarp::os::idl::WireReader reader(connection);
259  reader.expectAccept();
260  if (!reader.readListHeader()) {
261  return false;
262  }
263  int len = reader.getLength();
264  if (len == 0) {
265  yarp::os::idl::WireWriter writer(reader);
266  if (writer.isNull()) {
267  return true;
268  }
269  if (!writer.writeListHeader(1)) {
270  return false;
271  }
272  writer.writeString("send: 'help' or 'patch (param1 val1) (param2 val2)'");
273  return true;
274  }
275  std::string tag;
276  if (!reader.readString(tag)) {
277  return false;
278  }
279  if (tag == "help") {
280  yarp::os::idl::WireWriter writer(reader);
281  if (writer.isNull()) {
282  return true;
283  }
284  if (!writer.writeListHeader(2)) {
285  return false;
286  }
287  if (!writer.writeTag("many", 1, 0)) {
288  return false;
289  }
290  if (reader.getLength() > 0) {
291  std::string field;
292  if (!reader.readString(field)) {
293  return false;
294  }
295  if (field == "vel_x") {
296  if (!writer.writeListHeader(2)) {
297  return false;
298  }
299  if (!writer.writeString("double vel_x")) {
300  return false;
301  }
302  if (!writer.writeString("velocity of the robot [m/s]")) {
303  return false;
304  }
305  }
306  if (field == "vel_y") {
307  if (!writer.writeListHeader(2)) {
308  return false;
309  }
310  if (!writer.writeString("double vel_y")) {
311  return false;
312  }
313  if (!writer.writeString("velocity of the robot [m/s]")) {
314  return false;
315  }
316  }
317  if (field == "vel_theta") {
318  if (!writer.writeListHeader(2)) {
319  return false;
320  }
321  if (!writer.writeString("double vel_theta")) {
322  return false;
323  }
324  if (!writer.writeString("angular velocity of the robot [deg/s]")) {
325  return false;
326  }
327  }
328  }
329  if (!writer.writeListHeader(4)) {
330  return false;
331  }
332  writer.writeString("*** Available fields:");
333  writer.writeString("vel_x");
334  writer.writeString("vel_y");
335  writer.writeString("vel_theta");
336  return true;
337  }
338  bool nested = true;
339  bool have_act = false;
340  if (tag != "patch") {
341  if (((len - 1) % 2) != 0) {
342  return false;
343  }
344  len = 1 + ((len - 1) / 2);
345  nested = false;
346  have_act = true;
347  }
348  for (int i = 1; i < len; ++i) {
349  if (nested && !reader.readListHeader(3)) {
350  return false;
351  }
352  std::string act;
353  std::string key;
354  if (have_act) {
355  act = tag;
356  } else if (!reader.readString(act)) {
357  return false;
358  }
359  if (!reader.readString(key)) {
360  return false;
361  }
362  if (key == "vel_x") {
363  will_set_vel_x();
364  if (!obj->nested_read_vel_x(reader)) {
365  return false;
366  }
367  did_set_vel_x();
368  } else if (key == "vel_y") {
369  will_set_vel_y();
370  if (!obj->nested_read_vel_y(reader)) {
371  return false;
372  }
373  did_set_vel_y();
374  } else if (key == "vel_theta") {
375  will_set_vel_theta();
376  if (!obj->nested_read_vel_theta(reader)) {
377  return false;
378  }
379  did_set_vel_theta();
380  } else {
381  // would be useful to have a fallback here
382  }
383  }
384  reader.accept();
385  yarp::os::idl::WireWriter writer(reader);
386  if (writer.isNull()) {
387  return true;
388  }
389  writer.writeListHeader(1);
390  writer.writeVocab(yarp::os::createVocab('o', 'k'));
391  return true;
392 }
393 
394 // Editor: write
396 {
397  if (!isValid()) {
398  return false;
399  }
400  yarp::os::idl::WireWriter writer(connection);
401  if (!writer.writeListHeader(dirty_count + 1)) {
402  return false;
403  }
404  if (!writer.writeString("patch")) {
405  return false;
406  }
407  if (is_dirty_vel_x) {
408  if (!writer.writeListHeader(3)) {
409  return false;
410  }
411  if (!writer.writeString("set")) {
412  return false;
413  }
414  if (!writer.writeString("vel_x")) {
415  return false;
416  }
417  if (!obj->nested_write_vel_x(writer)) {
418  return false;
419  }
420  }
421  if (is_dirty_vel_y) {
422  if (!writer.writeListHeader(3)) {
423  return false;
424  }
425  if (!writer.writeString("set")) {
426  return false;
427  }
428  if (!writer.writeString("vel_y")) {
429  return false;
430  }
431  if (!obj->nested_write_vel_y(writer)) {
432  return false;
433  }
434  }
435  if (is_dirty_vel_theta) {
436  if (!writer.writeListHeader(3)) {
437  return false;
438  }
439  if (!writer.writeString("set")) {
440  return false;
441  }
442  if (!writer.writeString("vel_theta")) {
443  return false;
444  }
445  if (!obj->nested_write_vel_theta(writer)) {
446  return false;
447  }
448  }
449  return !writer.isError();
450 }
451 
452 // Editor: send if possible
453 void MobileBaseVelocity::Editor::communicate()
454 {
455  if (group != 0) {
456  return;
457  }
458  if (yarp().canWrite()) {
459  yarp().write(*this);
460  clean();
461  }
462 }
463 
464 // Editor: mark dirty overall
465 void MobileBaseVelocity::Editor::mark_dirty()
466 {
467  is_dirty = true;
468 }
469 
470 // Editor: vel_x mark_dirty
471 void MobileBaseVelocity::Editor::mark_dirty_vel_x()
472 {
473  if (is_dirty_vel_x) {
474  return;
475  }
476  dirty_count++;
477  is_dirty_vel_x = true;
478  mark_dirty();
479 }
480 
481 // Editor: vel_y mark_dirty
482 void MobileBaseVelocity::Editor::mark_dirty_vel_y()
483 {
484  if (is_dirty_vel_y) {
485  return;
486  }
487  dirty_count++;
488  is_dirty_vel_y = true;
489  mark_dirty();
490 }
491 
492 // Editor: vel_theta mark_dirty
493 void MobileBaseVelocity::Editor::mark_dirty_vel_theta()
494 {
495  if (is_dirty_vel_theta) {
496  return;
497  }
498  dirty_count++;
499  is_dirty_vel_theta = true;
500  mark_dirty();
501 }
502 
503 // Editor: dirty_flags
504 void MobileBaseVelocity::Editor::dirty_flags(bool flag)
505 {
506  is_dirty = flag;
507  is_dirty_vel_x = flag;
508  is_dirty_vel_y = flag;
509  is_dirty_vel_theta = flag;
510  dirty_count = flag ? 3 : 0;
511 }
512 
513 // read vel_x field
514 bool MobileBaseVelocity::read_vel_x(yarp::os::idl::WireReader& reader)
515 {
516  if (!reader.readFloat64(vel_x)) {
517  reader.fail();
518  return false;
519  }
520  return true;
521 }
522 
523 // write vel_x field
524 bool MobileBaseVelocity::write_vel_x(const yarp::os::idl::WireWriter& writer) const
525 {
526  if (!writer.writeFloat64(vel_x)) {
527  return false;
528  }
529  return true;
530 }
531 
532 // read (nested) vel_x field
533 bool MobileBaseVelocity::nested_read_vel_x(yarp::os::idl::WireReader& reader)
534 {
535  if (!reader.readFloat64(vel_x)) {
536  reader.fail();
537  return false;
538  }
539  return true;
540 }
541 
542 // write (nested) vel_x field
543 bool MobileBaseVelocity::nested_write_vel_x(const yarp::os::idl::WireWriter& writer) const
544 {
545  if (!writer.writeFloat64(vel_x)) {
546  return false;
547  }
548  return true;
549 }
550 
551 // read vel_y field
552 bool MobileBaseVelocity::read_vel_y(yarp::os::idl::WireReader& reader)
553 {
554  if (!reader.readFloat64(vel_y)) {
555  reader.fail();
556  return false;
557  }
558  return true;
559 }
560 
561 // write vel_y field
562 bool MobileBaseVelocity::write_vel_y(const yarp::os::idl::WireWriter& writer) const
563 {
564  if (!writer.writeFloat64(vel_y)) {
565  return false;
566  }
567  return true;
568 }
569 
570 // read (nested) vel_y field
571 bool MobileBaseVelocity::nested_read_vel_y(yarp::os::idl::WireReader& reader)
572 {
573  if (!reader.readFloat64(vel_y)) {
574  reader.fail();
575  return false;
576  }
577  return true;
578 }
579 
580 // write (nested) vel_y field
581 bool MobileBaseVelocity::nested_write_vel_y(const yarp::os::idl::WireWriter& writer) const
582 {
583  if (!writer.writeFloat64(vel_y)) {
584  return false;
585  }
586  return true;
587 }
588 
589 // read vel_theta field
590 bool MobileBaseVelocity::read_vel_theta(yarp::os::idl::WireReader& reader)
591 {
592  if (!reader.readFloat64(vel_theta)) {
593  reader.fail();
594  return false;
595  }
596  return true;
597 }
598 
599 // write vel_theta field
600 bool MobileBaseVelocity::write_vel_theta(const yarp::os::idl::WireWriter& writer) const
601 {
602  if (!writer.writeFloat64(vel_theta)) {
603  return false;
604  }
605  return true;
606 }
607 
608 // read (nested) vel_theta field
609 bool MobileBaseVelocity::nested_read_vel_theta(yarp::os::idl::WireReader& reader)
610 {
611  if (!reader.readFloat64(vel_theta)) {
612  reader.fail();
613  return false;
614  }
615  return true;
616 }
617 
618 // write (nested) vel_theta field
619 bool MobileBaseVelocity::nested_write_vel_theta(const yarp::os::idl::WireWriter& writer) const
620 {
621  if (!writer.writeFloat64(vel_theta)) {
622  return false;
623  }
624  return true;
625 }
626 
627 } // namespace yarp
628 } // namespace dev
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::dev::MobileBaseVelocity::Editor::set_vel_y
void set_vel_y(const double vel_y)
Definition: MobileBaseVelocity.cpp:191
yarp::os::Bottle::toString
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:214
yarp::os::idl::WireReader::readString
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:339
yarp::os::createVocab
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
Definition: Vocab.h:22
yarp::dev::MobileBaseVelocity::Editor::will_set_vel_theta
virtual bool will_set_vel_theta()
Definition: MobileBaseVelocity.cpp:235
yarp::os::idl::WireWriter::writeFloat64
bool writeFloat64(yarp::conf::float64_t x) const
Definition: WireWriter.cpp:117
yarp::dev::MobileBaseVelocity::Editor::stop_editing
void stop_editing()
Definition: MobileBaseVelocity.cpp:155
yarp::dev::MobileBaseVelocity::Editor::isValid
bool isValid() const
Definition: MobileBaseVelocity.cpp:137
yarp::dev::MobileBaseVelocity::vel_y
double vel_y
velocity of the robot [m/s]
Definition: MobileBaseVelocity.h:37
yarp::dev::MobileBaseVelocity::Editor::get_vel_x
double get_vel_x() const
Definition: MobileBaseVelocity.cpp:173
yarp::dev::MobileBaseVelocity::Editor::get_vel_theta
double get_vel_theta() const
Definition: MobileBaseVelocity.cpp:229
yarp::dev::MobileBaseVelocity::Editor::will_set_vel_x
virtual bool will_set_vel_x()
Definition: MobileBaseVelocity.cpp:179
yarp::os::Time::isValid
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:317
yarp::dev::MobileBaseVelocity::write
bool write(const yarp::os::idl::WireWriter &writer) const override
Definition: MobileBaseVelocity.cpp:65
yarp::dev::MobileBaseVelocity::Editor::did_set_vel_y
virtual bool did_set_vel_y()
Definition: MobileBaseVelocity.cpp:213
yarp::dev::MobileBaseVelocity::Editor::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: MobileBaseVelocity.cpp:253
yarp::os::idl::WireWriter::writeString
bool writeString(const std::string &tag) const
Definition: WireWriter.cpp:166
yarp::dev::MobileBaseVelocity::Editor::set_vel_theta
void set_vel_theta(const double vel_theta)
Definition: MobileBaseVelocity.cpp:219
yarp::os::idl::WireWriter::isNull
bool isNull() const
Definition: WireWriter.cpp:50
yarp::dev::MobileBaseVelocity::Editor::Editor
Editor()
Definition: MobileBaseVelocity.cpp:98
yarp::os::idl::WireWriter::isError
bool isError() const
Definition: WireWriter.cpp:136
yarp::os::idl::WireWriter::writeListHeader
bool writeListHeader(int len) const
Definition: WireWriter.cpp:183
yarp::os::idl::WireWriter
IDL-friendly connection writer.
Definition: WireWriter.h:33
yarp::dev::MobileBaseVelocity::Editor::start_editing
void start_editing()
Definition: MobileBaseVelocity.cpp:149
yarp::dev::MobileBaseVelocity::vel_theta
double vel_theta
angular velocity of the robot [deg/s]
Definition: MobileBaseVelocity.h:41
yarp::dev::MobileBaseVelocity::Editor::did_set_vel_theta
virtual bool did_set_vel_theta()
Definition: MobileBaseVelocity.cpp:241
yarp::dev::MobileBaseVelocity::Editor::will_set_vel_y
virtual bool will_set_vel_y()
Definition: MobileBaseVelocity.cpp:207
yarp::dev::MobileBaseVelocity::Editor::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: MobileBaseVelocity.cpp:395
yarp::dev::MobileBaseVelocity::Editor::edit
bool edit(MobileBaseVelocity &obj, bool dirty=true)
Definition: MobileBaseVelocity.cpp:125
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::idl::WireReader::expectAccept
void expectAccept()
Definition: WireReader.cpp:43
yarp::dev::MobileBaseVelocity::Editor::state
MobileBaseVelocity & state()
Definition: MobileBaseVelocity.cpp:143
yarp::dev::MobileBaseVelocity::Editor::set_vel_x
void set_vel_x(const double vel_x)
Definition: MobileBaseVelocity.cpp:163
yarp::dev::MobileBaseVelocity::Editor::get_vel_y
double get_vel_y() const
Definition: MobileBaseVelocity.cpp:201
yarp::dev::MobileBaseVelocity::read
bool read(yarp::os::idl::WireReader &reader) override
Definition: MobileBaseVelocity.cpp:40
yarp::dev::MobileBaseVelocity
Definition: MobileBaseVelocity.h:27
yarp::os::idl::WireWriter::writeTag
bool writeTag(const char *tag, int split, int len) const
Definition: WireWriter.cpp:141
yarp::os::idl::WireReader
IDL-friendly connection reader.
Definition: WireReader.h:33
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::idl::WireReader::fail
void fail()
Definition: WireReader.cpp:74
yarp::dev::MobileBaseVelocity::Editor::did_set_vel_x
virtual bool did_set_vel_x()
Definition: MobileBaseVelocity.cpp:185
yarp::os::Wire::yarp
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition: Wire.h:34
yarp::dev::MobileBaseVelocity::vel_x
double vel_x
velocity of the robot [m/s]
Definition: MobileBaseVelocity.h:33
yarp::os::idl::WireWriter::writeVocab
bool writeVocab(std::int32_t x) const
Definition: WireWriter.cpp:124
yarp::os::idl::WireReader::accept
void accept()
Definition: WireReader.cpp:49
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::Bottle::read
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition: Bottle.cpp:243
yarp::os::idl::WireReader::getLength
int getLength() const
Definition: WireReader.h:153
yarp::os::idl::WireReader::readFloat64
bool readFloat64(yarp::conf::float64_t &x)
Definition: WireReader.cpp:279
yarp::dev::MobileBaseVelocity::toString
std::string toString() const
Definition: MobileBaseVelocity.cpp:90
MobileBaseVelocity.h
yarp::dev::MobileBaseVelocity::MobileBaseVelocity
MobileBaseVelocity()
Definition: MobileBaseVelocity.cpp:20
yarp::dev::MobileBaseVelocity::Editor::clean
void clean()
Definition: MobileBaseVelocity.cpp:247
yarp::dev::MobileBaseVelocity::Editor::~Editor
~Editor() override
Definition: MobileBaseVelocity.cpp:117
yarp::os::idl::WireReader::readListHeader
bool readListHeader()
Definition: WireReader.cpp:470
yarp::os::idl::WireReader::isError
bool isError()
Definition: WireReader.cpp:547