YARP
Yet Another Robot Platform
Imu.h
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 // 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(),
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 ***
87 
88  // *** orientation_covariance ***
89  orientation_covariance.clear();
90  orientation_covariance.resize(9, 0.0);
91 
92  // *** angular_velocity ***
94 
95  // *** angular_velocity_covariance ***
97  angular_velocity_covariance.resize(9, 0.0);
98 
99  // *** linear_acceleration ***
101 
102  // *** linear_acceleration_covariance ***
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++) {
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++) {
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++) {
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) {
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) {
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) {
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++) {
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++) {
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  {
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
yarp::rosmsg::sensor_msgs::Imu::rosStyle
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::Imu > rosStyle
Definition: Imu.h:320
yarp::rosmsg::sensor_msgs::Imu::bottleStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::sensor_msgs::Imu > bottleStyle
Definition: Imu.h:321
yarp::rosmsg::sensor_msgs::Imu::readBottle
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: Imu.h:153
yarp::rosmsg::std_msgs::Header::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Header.h:115
yarp::rosmsg::sensor_msgs::Imu::angular_velocity_covariance
std::vector< yarp::conf::float64_t > angular_velocity_covariance
Definition: Imu.h:62
WireTypes.h
BOTTLE_TAG_LIST
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
Quaternion.h
yarp::rosmsg::geometry_msgs::Vector3
Definition: Vector3.h:38
yarp::rosmsg::geometry_msgs::Vector3::clear
void clear()
Definition: Vector3.h:51
yarp::os::ConnectionWriter::appendFloat64
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
yarp::os::idl::BottleStyle
Definition: BottleStyle.h:22
yarp::os::Type
Definition: Type.h:24
yarp::os::idl::WirePortable::read
virtual bool read(yarp::os::idl::WireReader &reader)
Definition: WirePortable.cpp:14
Header.h
yarp::os::ConnectionReader::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
yarp::rosmsg::std_msgs::Header::clear
void clear()
Definition: Header.h:58
Wire.h
yarp::rosmsg::sensor_msgs::Imu::Imu
Imu()
Definition: Imu.h:66
yarp::rosmsg::geometry_msgs::Vector3::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Vector3.h:98
yarp::rosmsg::sensor_msgs::Imu::linear_acceleration_covariance
std::vector< yarp::conf::float64_t > linear_acceleration_covariance
Definition: Imu.h:64
yarp::rosmsg::geometry_msgs::Quaternion::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Quaternion.h:106
yarp::rosmsg::sensor_msgs::Imu::orientation
yarp::rosmsg::geometry_msgs::Quaternion orientation
Definition: Imu.h:59
yarp::rosmsg::geometry_msgs::Quaternion
Definition: Quaternion.h:35
yarp::rosmsg::sensor_msgs::Imu::angular_velocity
yarp::rosmsg::geometry_msgs::Vector3 angular_velocity
Definition: Imu.h:61
yarp::rosmsg::sensor_msgs::Imu::clear
void clear()
Definition: Imu.h:80
yarp::rosmsg::sensor_msgs::Imu::readBare
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: Imu.h:107
yarp::os::ConnectionReader::expectFloat64
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
yarp::os::Type::byName
static Type byName(const char *name)
Definition: Type.cpp:174
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::Type::addProperty
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:137
Type.h
yarp::rosmsg::sensor_msgs::Imu::typeChecksum
static constexpr const char * typeChecksum
Definition: Imu.h:327
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::rosmsg::sensor_msgs::Imu
Definition: Imu.h:56
yarp::os::ConnectionReader::isError
virtual bool isError() const =0
yarp::rosmsg::sensor_msgs::Imu::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Imu.h:215
yarp::rosmsg::sensor_msgs::Imu::typeText
static constexpr const char * typeText
Definition: Imu.h:330
Vector3.h
yarp::rosmsg::sensor_msgs::Imu::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Imu.h:312
yarp::rosmsg::geometry_msgs::Quaternion::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Quaternion.h:155
yarp::os::ConnectionReader::convertTextMode
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
yarp::rosmsg::sensor_msgs::Imu::linear_acceleration
yarp::rosmsg::geometry_msgs::Vector3 linear_acceleration
Definition: Imu.h:63
yarp::os::idl::WirePortable
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:26
yarp::os::ConnectionWriter::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
yarp::rosmsg::geometry_msgs::Quaternion::clear
void clear()
Definition: Quaternion.h:50
yarp::rosmsg::sensor_msgs::Imu::writeBare
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: Imu.h:221
yarp::rosmsg::std_msgs::Header::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Header.h:162
yarp::os::ConnectionWriter::convertTextMode
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
yarp::os::ConnectionWriter::appendInt32
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
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::BareStyle
Definition: BareStyle.h:22
BOTTLE_TAG_FLOAT64
#define BOTTLE_TAG_FLOAT64
Definition: Bottle.h:27
yarp::rosmsg::sensor_msgs::Imu::orientation_covariance
std::vector< yarp::conf::float64_t > orientation_covariance
Definition: Imu.h:60
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::conf::float64_t
double float64_t
Definition: numeric.h:51
yarp::os::ConnectionWriter::appendExternalBlock
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
yarp::rosmsg::sensor_msgs::Imu::header
yarp::rosmsg::std_msgs::Header header
Definition: Imu.h:58
yarp::rosmsg::sensor_msgs::Imu::writeBottle
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: Imu.h:261
yarp::os::ConnectionReader::expectBlock
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
sensor_msgs
Definition: BatteryState.h:22
yarp::rosmsg::sensor_msgs::Imu::typeName
static constexpr const char * typeName
Definition: Imu.h:324
yarp::rosmsg::sensor_msgs::Imu::getType
yarp::os::Type getType() const override
Definition: Imu.h:397
yarp::rosmsg::std_msgs::Header
Definition: Header.h:45
yarp::rosmsg::geometry_msgs::Vector3::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Vector3.h:140
yarp::os::idl::WireReader::readListHeader
bool readListHeader()
Definition: WireReader.cpp:470
yarp::os::idl::WirePortable::write
virtual bool write(const yarp::os::idl::WireWriter &writer) const
Definition: WirePortable.cpp:20