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  // Give source text for class, ROS will need this
198  static std::string typeText()
199  {
200  return std::string("\
201  # Measurement of the Magnetic Field vector at a specific location.\n\
202 \n\
203  # If the covariance of the measurement is known, it should be filled in\n\
204  # (if all you know is the variance of each measurement, e.g. from the datasheet,\n\
205  #just put those along the diagonal)\n\
206  # A covariance matrix of all zeros will be interpreted as \"covariance unknown\",\n\
207  # and to use the data a covariance will have to be assumed or gotten from some\n\
208  # other source\n\
209 \n\
210 \n\
211  Header header # timestamp is the time the\n\
212  # field was measured\n\
213  # frame_id is the location and orientation\n\
214  # of the field measurement\n\
215 \n\
216  geometry_msgs/Vector3 magnetic_field # x, y, and z components of the\n\
217  # field vector in Tesla\n\
218  # If your sensor does not output 3 axes,\n\
219  # put NaNs in the components not reported.\n\
220 \n\
221  float64[9] magnetic_field_covariance # Row major about x, y, z axes\n\
222  # 0 is interpreted as variance unknown") + std::string("\n\
223 ================================================================================\n\
224 MSG: std_msgs/Header\n\
225 ") + yarp::rosmsg::std_msgs::Header::typeText() + std::string("\n\
226 ================================================================================\n\
227 MSG: geometry_msgs/Vector3\n\
229  }
230 
231  std::string getTypeText() const
232  {
234  }
235 
236  // Name the class, ROS will need this
237  yarp::os::Type getType() const override
238  {
239  yarp::os::Type typ = yarp::os::Type::byName("sensor_msgs/MagneticField", "sensor_msgs/MagneticField");
240  typ.addProperty("md5sum", yarp::os::Value("2f3b0b43eed0c9501de0fa3ff89a45aa"));
241  typ.addProperty("message_definition", yarp::os::Value(getTypeText()));
242  return typ;
243  }
244 };
245 
246 } // namespace sensor_msgs
247 } // namespace rosmsg
248 } // namespace yarp
249 
250 #endif // YARP_ROSMSG_sensor_msgs_MagneticField_h
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static std::string typeText()
Definition: Header.h:174
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
static std::string typeText()
Definition: Vector3.h:152
bool writeBare(yarp::os::ConnectionWriter &connection) const override
yarp::os::Type getType() const override
static Type byName(const char *name)
Definition: Type.cpp:165
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:127
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.
yarp::rosmsg::std_msgs::Header header
Definition: MagneticField.h:54
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:30
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
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:40
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:37
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.