YARP
Yet Another Robot Platform
Imu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 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 // This is an automatically generated file.
10 
11 // Generated from the following "sensor_msgs/Imu" msg definition:
12 // # This is a message to hold data from an IMU (Inertial Measurement Unit)
13 // #
14 // # Accelerations should be in m/s^2 (not in g's), and rotational velocity should be in rad/sec
15 // #
16 // # If the covariance of the measurement is known, it should be filled in (if all you know is the
17 // # variance of each measurement, e.g. from the datasheet, just put those along the diagonal)
18 // # A covariance matrix of all zeros will be interpreted as "covariance unknown", and to use the
19 // # data a covariance will have to be assumed or gotten from some other source
20 // #
21 // # If you have no estimate for one of the data elements (e.g. your IMU doesn't produce an orientation
22 // # estimate), please set element 0 of the associated covariance matrix to -1
23 // # If you are interpreting this message, please check for a value of -1 in the first element of each
24 // # covariance matrix, and disregard the associated estimate.
25 //
26 // Header header
27 //
28 // geometry_msgs/Quaternion orientation
29 // float64[9] orientation_covariance # Row major about x, y, z axes
30 //
31 // geometry_msgs/Vector3 angular_velocity
32 // float64[9] angular_velocity_covariance # Row major about x, y, z axes
33 //
34 // geometry_msgs/Vector3 linear_acceleration
35 // float64[9] linear_acceleration_covariance # Row major x, y z
36 // Instances of this class can be read and written with YARP ports,
37 // using a ROS-compatible format.
38 
39 #ifndef YARP_ROSMSG_sensor_msgs_Imu_h
40 #define YARP_ROSMSG_sensor_msgs_Imu_h
41 
42 #include <yarp/os/Wire.h>
43 #include <yarp/os/Type.h>
44 #include <yarp/os/idl/WireTypes.h>
45 #include <string>
46 #include <vector>
50 
51 namespace yarp {
52 namespace rosmsg {
53 namespace sensor_msgs {
54 
56 {
57 public:
60  std::vector<yarp::conf::float64_t> orientation_covariance;
62  std::vector<yarp::conf::float64_t> angular_velocity_covariance;
64  std::vector<yarp::conf::float64_t> linear_acceleration_covariance;
65 
66  Imu() :
67  header(),
68  orientation(),
69  orientation_covariance(),
70  angular_velocity(),
71  angular_velocity_covariance(),
72  linear_acceleration(),
73  linear_acceleration_covariance()
74  {
75  orientation_covariance.resize(9, 0.0);
76  angular_velocity_covariance.resize(9, 0.0);
77  linear_acceleration_covariance.resize(9, 0.0);
78  }
79 
80  void clear()
81  {
82  // *** header ***
83  header.clear();
84 
85  // *** orientation ***
86  orientation.clear();
87 
88  // *** orientation_covariance ***
89  orientation_covariance.clear();
90  orientation_covariance.resize(9, 0.0);
91 
92  // *** angular_velocity ***
93  angular_velocity.clear();
94 
95  // *** angular_velocity_covariance ***
96  angular_velocity_covariance.clear();
97  angular_velocity_covariance.resize(9, 0.0);
98 
99  // *** linear_acceleration ***
100  linear_acceleration.clear();
101 
102  // *** linear_acceleration_covariance ***
103  linear_acceleration_covariance.clear();
104  linear_acceleration_covariance.resize(9, 0.0);
105  }
106 
107  bool readBare(yarp::os::ConnectionReader& connection) override
108  {
109  // *** header ***
110  if (!header.read(connection)) {
111  return false;
112  }
113 
114  // *** orientation ***
115  if (!orientation.read(connection)) {
116  return false;
117  }
118 
119  // *** orientation_covariance ***
120  int len = 9;
121  orientation_covariance.resize(len);
122  if (len > 0 && !connection.expectBlock((char*)&orientation_covariance[0], sizeof(yarp::conf::float64_t)*len)) {
123  return false;
124  }
125 
126  // *** angular_velocity ***
127  if (!angular_velocity.read(connection)) {
128  return false;
129  }
130 
131  // *** angular_velocity_covariance ***
132  len = 9;
133  angular_velocity_covariance.resize(len);
134  if (len > 0 && !connection.expectBlock((char*)&angular_velocity_covariance[0], sizeof(yarp::conf::float64_t)*len)) {
135  return false;
136  }
137 
138  // *** linear_acceleration ***
139  if (!linear_acceleration.read(connection)) {
140  return false;
141  }
142 
143  // *** linear_acceleration_covariance ***
144  len = 9;
145  linear_acceleration_covariance.resize(len);
146  if (len > 0 && !connection.expectBlock((char*)&linear_acceleration_covariance[0], sizeof(yarp::conf::float64_t)*len)) {
147  return false;
148  }
149 
150  return !connection.isError();
151  }
152 
153  bool readBottle(yarp::os::ConnectionReader& connection) override
154  {
155  connection.convertTextMode();
156  yarp::os::idl::WireReader reader(connection);
157  if (!reader.readListHeader(7)) {
158  return false;
159  }
160 
161  // *** header ***
162  if (!header.read(connection)) {
163  return false;
164  }
165 
166  // *** orientation ***
167  if (!orientation.read(connection)) {
168  return false;
169  }
170 
171  // *** orientation_covariance ***
172  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_FLOAT64)) {
173  return false;
174  }
175  int len = connection.expectInt32();
176  orientation_covariance.resize(len);
177  for (int i=0; i<len; i++) {
178  orientation_covariance[i] = (yarp::conf::float64_t)connection.expectFloat64();
179  }
180 
181  // *** angular_velocity ***
182  if (!angular_velocity.read(connection)) {
183  return false;
184  }
185 
186  // *** angular_velocity_covariance ***
187  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_FLOAT64)) {
188  return false;
189  }
190  len = connection.expectInt32();
191  angular_velocity_covariance.resize(len);
192  for (int i=0; i<len; i++) {
193  angular_velocity_covariance[i] = (yarp::conf::float64_t)connection.expectFloat64();
194  }
195 
196  // *** linear_acceleration ***
197  if (!linear_acceleration.read(connection)) {
198  return false;
199  }
200 
201  // *** linear_acceleration_covariance ***
202  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_FLOAT64)) {
203  return false;
204  }
205  len = connection.expectInt32();
206  linear_acceleration_covariance.resize(len);
207  for (int i=0; i<len; i++) {
208  linear_acceleration_covariance[i] = (yarp::conf::float64_t)connection.expectFloat64();
209  }
210 
211  return !connection.isError();
212  }
213 
215  bool read(yarp::os::ConnectionReader& connection) override
216  {
217  return (connection.isBareMode() ? readBare(connection)
218  : readBottle(connection));
219  }
220 
221  bool writeBare(yarp::os::ConnectionWriter& connection) const override
222  {
223  // *** header ***
224  if (!header.write(connection)) {
225  return false;
226  }
227 
228  // *** orientation ***
229  if (!orientation.write(connection)) {
230  return false;
231  }
232 
233  // *** orientation_covariance ***
234  if (orientation_covariance.size()>0) {
235  connection.appendExternalBlock((char*)&orientation_covariance[0], sizeof(yarp::conf::float64_t)*orientation_covariance.size());
236  }
237 
238  // *** angular_velocity ***
239  if (!angular_velocity.write(connection)) {
240  return false;
241  }
242 
243  // *** angular_velocity_covariance ***
244  if (angular_velocity_covariance.size()>0) {
245  connection.appendExternalBlock((char*)&angular_velocity_covariance[0], sizeof(yarp::conf::float64_t)*angular_velocity_covariance.size());
246  }
247 
248  // *** linear_acceleration ***
249  if (!linear_acceleration.write(connection)) {
250  return false;
251  }
252 
253  // *** linear_acceleration_covariance ***
254  if (linear_acceleration_covariance.size()>0) {
255  connection.appendExternalBlock((char*)&linear_acceleration_covariance[0], sizeof(yarp::conf::float64_t)*linear_acceleration_covariance.size());
256  }
257 
258  return !connection.isError();
259  }
260 
261  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
262  {
263  connection.appendInt32(BOTTLE_TAG_LIST);
264  connection.appendInt32(7);
265 
266  // *** header ***
267  if (!header.write(connection)) {
268  return false;
269  }
270 
271  // *** orientation ***
272  if (!orientation.write(connection)) {
273  return false;
274  }
275 
276  // *** orientation_covariance ***
278  connection.appendInt32(orientation_covariance.size());
279  for (size_t i=0; i<orientation_covariance.size(); i++) {
280  connection.appendFloat64(orientation_covariance[i]);
281  }
282 
283  // *** angular_velocity ***
284  if (!angular_velocity.write(connection)) {
285  return false;
286  }
287 
288  // *** angular_velocity_covariance ***
290  connection.appendInt32(angular_velocity_covariance.size());
291  for (size_t i=0; i<angular_velocity_covariance.size(); i++) {
292  connection.appendFloat64(angular_velocity_covariance[i]);
293  }
294 
295  // *** linear_acceleration ***
296  if (!linear_acceleration.write(connection)) {
297  return false;
298  }
299 
300  // *** linear_acceleration_covariance ***
302  connection.appendInt32(linear_acceleration_covariance.size());
303  for (size_t i=0; i<linear_acceleration_covariance.size(); i++) {
304  connection.appendFloat64(linear_acceleration_covariance[i]);
305  }
306 
307  connection.convertTextMode();
308  return !connection.isError();
309  }
310 
312  bool write(yarp::os::ConnectionWriter& connection) const override
313  {
314  return (connection.isBareMode() ? writeBare(connection)
315  : writeBottle(connection));
316  }
317 
318  // This class will serialize ROS style or YARP style depending on protocol.
319  // If you need to force a serialization style, use one of these classes:
322 
323  // The name for this message, ROS will need this
324  static constexpr const char* typeName = "sensor_msgs/Imu";
325 
326  // The checksum for this message, ROS will need this
327  static constexpr const char* typeChecksum = "6a62c6daae103f4ff57a132d6f95cec2";
328 
329  // The source text for this message, ROS will need this
330  static constexpr const char* typeText = "\
331 # This is a message to hold data from an IMU (Inertial Measurement Unit)\n\
332 #\n\
333 # Accelerations should be in m/s^2 (not in g's), and rotational velocity should be in rad/sec\n\
334 #\n\
335 # If the covariance of the measurement is known, it should be filled in (if all you know is the \n\
336 # variance of each measurement, e.g. from the datasheet, just put those along the diagonal)\n\
337 # A covariance matrix of all zeros will be interpreted as \"covariance unknown\", and to use the\n\
338 # data a covariance will have to be assumed or gotten from some other source\n\
339 #\n\
340 # If you have no estimate for one of the data elements (e.g. your IMU doesn't produce an orientation \n\
341 # estimate), please set element 0 of the associated covariance matrix to -1\n\
342 # If you are interpreting this message, please check for a value of -1 in the first element of each \n\
343 # covariance matrix, and disregard the associated estimate.\n\
344 \n\
345 Header header\n\
346 \n\
347 geometry_msgs/Quaternion orientation\n\
348 float64[9] orientation_covariance # Row major about x, y, z axes\n\
349 \n\
350 geometry_msgs/Vector3 angular_velocity\n\
351 float64[9] angular_velocity_covariance # Row major about x, y, z axes\n\
352 \n\
353 geometry_msgs/Vector3 linear_acceleration\n\
354 float64[9] linear_acceleration_covariance # Row major x, y z \n\
355 \n\
356 ================================================================================\n\
357 MSG: std_msgs/Header\n\
358 # Standard metadata for higher-level stamped data types.\n\
359 # This is generally used to communicate timestamped data \n\
360 # in a particular coordinate frame.\n\
361 # \n\
362 # sequence ID: consecutively increasing ID \n\
363 uint32 seq\n\
364 #Two-integer timestamp that is expressed as:\n\
365 # * stamp.sec: seconds (stamp_secs) since epoch (in Python the variable is called 'secs')\n\
366 # * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs')\n\
367 # time-handling sugar is provided by the client library\n\
368 time stamp\n\
369 #Frame this data is associated with\n\
370 # 0: no frame\n\
371 # 1: global frame\n\
372 string frame_id\n\
373 \n\
374 ================================================================================\n\
375 MSG: geometry_msgs/Quaternion\n\
376 # This represents an orientation in free space in quaternion form.\n\
377 \n\
378 float64 x\n\
379 float64 y\n\
380 float64 z\n\
381 float64 w\n\
382 \n\
383 ================================================================================\n\
384 MSG: geometry_msgs/Vector3\n\
385 # This represents a vector in free space. \n\
386 # It is only meant to represent a direction. Therefore, it does not\n\
387 # make sense to apply a translation to it (e.g., when applying a \n\
388 # generic rigid transformation to a Vector3, tf2 will only apply the\n\
389 # rotation). If you want your data to be translatable too, use the\n\
390 # geometry_msgs/Point message instead.\n\
391 \n\
392 float64 x\n\
393 float64 y\n\
394 float64 z\n\
395 ";
396 
397  yarp::os::Type getType() const override
398  {
399  yarp::os::Type typ = yarp::os::Type::byName(typeName, typeName);
400  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
401  typ.addProperty("message_definition", yarp::os::Value(typeText));
402  return typ;
403  }
404 };
405 
406 } // namespace sensor_msgs
407 } // namespace rosmsg
408 } // namespace yarp
409 
410 #endif // YARP_ROSMSG_sensor_msgs_Imu_h
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Quaternion.h:106
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
yarp::os::Type getType() const override
Definition: Imu.h:397
static Type byName(const char *name)
Definition: Type.cpp:179
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:141
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: Imu.h:221
virtual bool isError() const =0
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: Imu.h:153
The main, catch-all namespace for YARP.
Definition: numeric.h:47
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary...
yarp::rosmsg::geometry_msgs::Vector3 linear_acceleration
Definition: Imu.h:63
virtual bool isBareMode() const =0
Check if the connection is bare mode.
std::vector< yarp::conf::float64_t > angular_velocity_covariance
Definition: Imu.h:62
An interface for writing to a network connection.
virtual bool write(const yarp::os::idl::WireWriter &writer) const
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Quaternion.h:155
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
virtual bool read(yarp::os::idl::WireReader &reader)
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
virtual bool isError() const =0
yarp::os::idl::BottleStyle< yarp::rosmsg::sensor_msgs::Imu > bottleStyle
Definition: Imu.h:321
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Header.h:162
#define BOTTLE_TAG_FLOAT64
Definition: Bottle.h:27
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:30
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::Imu > rosStyle
Definition: Imu.h:320
std::vector< yarp::conf::float64_t > orientation_covariance
Definition: Imu.h:60
An interface for reading from a network connection.
static constexpr const char * typeText
Definition: Imu.h:330
double float64_t
Definition: numeric.h:51
A single value (typically within a Bottle).
Definition: Value.h:40
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Imu.h:215
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: Imu.h:261
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Vector3.h:140
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
std::vector< yarp::conf::float64_t > linear_acceleration_covariance
Definition: Imu.h:64
yarp::rosmsg::geometry_msgs::Vector3 angular_velocity
Definition: Imu.h:61
yarp::rosmsg::std_msgs::Header header
Definition: Imu.h:58
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: Imu.h:107
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Vector3.h:98
static constexpr const char * typeChecksum
Definition: Imu.h:327
static constexpr const char * typeName
Definition: Imu.h:324
IDL-friendly connection reader.
Definition: WireReader.h:37
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Header.h:115
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Imu.h:312
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
yarp::rosmsg::geometry_msgs::Quaternion orientation
Definition: Imu.h:59