YARP
Yet Another Robot Platform
MagneticField.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/MagneticField" msg definition:
12 // # Measurement of the Magnetic Field vector at a specific location.
13 //
14 // # If the covariance of the measurement is known, it should be filled in
15 // # (if all you know is the variance of each measurement, e.g. from the datasheet,
16 // #just put those along the diagonal)
17 // # A covariance matrix of all zeros will be interpreted as "covariance unknown",
18 // # and to use the data a covariance will have to be assumed or gotten from some
19 // # other source
20 //
21 //
22 // Header header # timestamp is the time the
23 // # field was measured
24 // # frame_id is the location and orientation
25 // # of the field measurement
26 //
27 // geometry_msgs/Vector3 magnetic_field # x, y, and z components of the
28 // # field vector in Tesla
29 // # If your sensor does not output 3 axes,
30 // # put NaNs in the components not reported.
31 //
32 // float64[9] magnetic_field_covariance # Row major about x, y, z axes
33 // # 0 is interpreted as variance unknown// Instances of this class can be read and written with YARP ports,
34 // using a ROS-compatible format.
35 
36 #ifndef YARP_ROSMSG_sensor_msgs_MagneticField_h
37 #define YARP_ROSMSG_sensor_msgs_MagneticField_h
38 
39 #include <yarp/os/Wire.h>
40 #include <yarp/os/Type.h>
41 #include <yarp/os/idl/WireTypes.h>
42 #include <string>
43 #include <vector>
46 
47 namespace yarp {
48 namespace rosmsg {
49 namespace sensor_msgs {
50 
52 {
53 public:
56  std::vector<yarp::conf::float64_t> magnetic_field_covariance;
57 
59  header(),
60  magnetic_field(),
61  magnetic_field_covariance()
62  {
63  magnetic_field_covariance.resize(9, 0.0);
64  }
65 
66  void clear()
67  {
68  // *** header ***
69  header.clear();
70 
71  // *** magnetic_field ***
72  magnetic_field.clear();
73 
74  // *** magnetic_field_covariance ***
75  magnetic_field_covariance.clear();
76  magnetic_field_covariance.resize(9, 0.0);
77  }
78 
79  bool readBare(yarp::os::ConnectionReader& connection) override
80  {
81  // *** header ***
82  if (!header.read(connection)) {
83  return false;
84  }
85 
86  // *** magnetic_field ***
87  if (!magnetic_field.read(connection)) {
88  return false;
89  }
90 
91  // *** magnetic_field_covariance ***
92  int len = 9;
93  magnetic_field_covariance.resize(len);
94  if (len > 0 && !connection.expectBlock((char*)&magnetic_field_covariance[0], sizeof(yarp::conf::float64_t)*len)) {
95  return false;
96  }
97 
98  return !connection.isError();
99  }
100 
101  bool readBottle(yarp::os::ConnectionReader& connection) override
102  {
103  connection.convertTextMode();
104  yarp::os::idl::WireReader reader(connection);
105  if (!reader.readListHeader(3)) {
106  return false;
107  }
108 
109  // *** header ***
110  if (!header.read(connection)) {
111  return false;
112  }
113 
114  // *** magnetic_field ***
115  if (!magnetic_field.read(connection)) {
116  return false;
117  }
118 
119  // *** magnetic_field_covariance ***
120  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_FLOAT64)) {
121  return false;
122  }
123  int len = connection.expectInt32();
124  magnetic_field_covariance.resize(len);
125  for (int i=0; i<len; i++) {
126  magnetic_field_covariance[i] = (yarp::conf::float64_t)connection.expectFloat64();
127  }
128 
129  return !connection.isError();
130  }
131 
133  bool read(yarp::os::ConnectionReader& connection) override
134  {
135  return (connection.isBareMode() ? readBare(connection)
136  : readBottle(connection));
137  }
138 
139  bool writeBare(yarp::os::ConnectionWriter& connection) const override
140  {
141  // *** header ***
142  if (!header.write(connection)) {
143  return false;
144  }
145 
146  // *** magnetic_field ***
147  if (!magnetic_field.write(connection)) {
148  return false;
149  }
150 
151  // *** magnetic_field_covariance ***
152  if (magnetic_field_covariance.size()>0) {
153  connection.appendExternalBlock((char*)&magnetic_field_covariance[0], sizeof(yarp::conf::float64_t)*magnetic_field_covariance.size());
154  }
155 
156  return !connection.isError();
157  }
158 
159  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
160  {
161  connection.appendInt32(BOTTLE_TAG_LIST);
162  connection.appendInt32(3);
163 
164  // *** header ***
165  if (!header.write(connection)) {
166  return false;
167  }
168 
169  // *** magnetic_field ***
170  if (!magnetic_field.write(connection)) {
171  return false;
172  }
173 
174  // *** magnetic_field_covariance ***
176  connection.appendInt32(magnetic_field_covariance.size());
177  for (size_t i=0; i<magnetic_field_covariance.size(); i++) {
178  connection.appendFloat64(magnetic_field_covariance[i]);
179  }
180 
181  connection.convertTextMode();
182  return !connection.isError();
183  }
184 
186  bool write(yarp::os::ConnectionWriter& connection) const override
187  {
188  return (connection.isBareMode() ? writeBare(connection)
189  : writeBottle(connection));
190  }
191 
192  // This class will serialize ROS style or YARP style depending on protocol.
193  // If you need to force a serialization style, use one of these classes:
196 
197  // The name for this message, ROS will need this
198  static constexpr const char* typeName = "sensor_msgs/MagneticField";
199 
200  // The checksum for this message, ROS will need this
201  static constexpr const char* typeChecksum = "2f3b0b43eed0c9501de0fa3ff89a45aa";
202 
203  // The source text for this message, ROS will need this
204  static constexpr const char* typeText = "\
205  # Measurement of the Magnetic Field vector at a specific location.\n\
206 \n\
207  # If the covariance of the measurement is known, it should be filled in\n\
208  # (if all you know is the variance of each measurement, e.g. from the datasheet,\n\
209  #just put those along the diagonal)\n\
210  # A covariance matrix of all zeros will be interpreted as \"covariance unknown\",\n\
211  # and to use the data a covariance will have to be assumed or gotten from some\n\
212  # other source\n\
213 \n\
214 \n\
215  Header header # timestamp is the time the\n\
216  # field was measured\n\
217  # frame_id is the location and orientation\n\
218  # of the field measurement\n\
219 \n\
220  geometry_msgs/Vector3 magnetic_field # x, y, and z components of the\n\
221  # field vector in Tesla\n\
222  # If your sensor does not output 3 axes,\n\
223  # put NaNs in the components not reported.\n\
224 \n\
225  float64[9] magnetic_field_covariance # Row major about x, y, z axes\n\
226  # 0 is interpreted as variance unknown\n\
227 ================================================================================\n\
228 MSG: std_msgs/Header\n\
229 # Standard metadata for higher-level stamped data types.\n\
230 # This is generally used to communicate timestamped data \n\
231 # in a particular coordinate frame.\n\
232 # \n\
233 # sequence ID: consecutively increasing ID \n\
234 uint32 seq\n\
235 #Two-integer timestamp that is expressed as:\n\
236 # * stamp.sec: seconds (stamp_secs) since epoch (in Python the variable is called 'secs')\n\
237 # * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs')\n\
238 # time-handling sugar is provided by the client library\n\
239 time stamp\n\
240 #Frame this data is associated with\n\
241 # 0: no frame\n\
242 # 1: global frame\n\
243 string frame_id\n\
244 \n\
245 ================================================================================\n\
246 MSG: geometry_msgs/Vector3\n\
247 # This represents a vector in free space. \n\
248 # It is only meant to represent a direction. Therefore, it does not\n\
249 # make sense to apply a translation to it (e.g., when applying a \n\
250 # generic rigid transformation to a Vector3, tf2 will only apply the\n\
251 # rotation). If you want your data to be translatable too, use the\n\
252 # geometry_msgs/Point message instead.\n\
253 \n\
254 float64 x\n\
255 float64 y\n\
256 float64 z\n\
257 ";
258 
259  yarp::os::Type getType() const override
260  {
261  yarp::os::Type typ = yarp::os::Type::byName(typeName, typeName);
262  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
263  typ.addProperty("message_definition", yarp::os::Value(typeText));
264  return typ;
265  }
266 };
267 
268 } // namespace sensor_msgs
269 } // namespace rosmsg
270 } // namespace yarp
271 
272 #endif // YARP_ROSMSG_sensor_msgs_MagneticField_h
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
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::idl::BottleStyle< yarp::rosmsg::sensor_msgs::MagneticField > bottleStyle
bool writeBare(yarp::os::ConnectionWriter &connection) const override
yarp::os::Type getType() const override
static Type byName(const char *name)
Definition: Type.cpp:176
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:138
bool readBottle(yarp::os::ConnectionReader &connection) override
virtual bool isError() const =0
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...
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: MagneticField.h:79
virtual bool isBareMode() const =0
Check if the connection is bare mode.
static constexpr const char * typeText
yarp::rosmsg::std_msgs::Header header
Definition: MagneticField.h:54
static constexpr const char * typeName
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.
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
std::vector< yarp::conf::float64_t > magnetic_field_covariance
Definition: MagneticField.h:56
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:33
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
static constexpr const char * typeChecksum
An interface for reading from a network connection.
double float64_t
Definition: numeric.h:51
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::MagneticField > rosStyle
A single value (typically within a Bottle).
Definition: Value.h:46
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
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Vector3.h:98
yarp::rosmsg::geometry_msgs::Vector3 magnetic_field
Definition: MagneticField.h:55
IDL-friendly connection reader.
Definition: WireReader.h:32
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Header.h:115
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.