YARP
Yet Another Robot Platform
Map2DLocation.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_DEV_MAP2DLOCATION_H
7 #define YARP_DEV_MAP2DLOCATION_H
8 
9 #include <sstream>
10 #include <string>
11 
12 //#include <yarp/math/Vec2D.h>
13 #include <yarp/dev/api.h>
14 #include <yarp/dev/NavTypes.h>
16 
20 namespace yarp
21 {
22  namespace dev
23  {
24  namespace Nav2D
25  {
27  {
35  Map2DLocation(const std::string& map_name, const double& inX, const double& inY, const double& inT)
36  {
37  map_id = map_name;
38  x = inX;
39  y = inY;
40  theta = inT;
41  }
42 
51  Map2DLocation(const std::string& map_name, yarp::dev::Nav2D::XYWorld location)
52  {
53  map_id = map_name;
54  x = location.x;
55  y = location.y;
56  theta = 0;
57  }
58 
63  {
64  map_id = "";
65  x = 0;
66  y = 0;
67  theta = 0;
68  }
69 
74  std::string toString() const
75  {
76  std::ostringstream stringStream;
77  stringStream.precision(-1);
78  stringStream.width(-1);
79  stringStream << std::string("map_id:") << map_id << std::string(" x:") << x << std::string(" y:") << y << std::string(" theta:") << theta;
80  return stringStream.str();
81  }
82 
87  inline bool operator!=(const Map2DLocation& r) const
88  {
89  if (
90  map_id != r.map_id ||
91  x != r.x ||
92  y != r.y ||
93  theta != r.theta
94  )
95  {
96  return true;
97  }
98  return false;
99  }
100 
105  inline bool operator==(const Map2DLocation& r) const
106  {
107  if (
108  map_id == r.map_id &&
109  x == r.x &&
110  y == r.y &&
111  theta == r.theta
112  )
113  {
114  return true;
115  }
116  return false;
117  }
118 
123  bool is_near_to(const Map2DLocation& other_loc, double linear_tolerance, double angular_tolerance) const;
124 
128  bool read(yarp::os::idl::WireReader& reader) override { return Map2DLocationData::read(reader); }
129  bool write(const yarp::os::idl::WireWriter& writer) const override { return Map2DLocationData::write(writer); }
130  bool read(yarp::os::ConnectionReader& reader) override { return Map2DLocationData::read(reader); }
131  bool write(yarp::os::ConnectionWriter& writer) const override { return Map2DLocationData::write(writer); }
132  };
133  }
134  }
135 }
136 
137 #endif // YARP_DEV_MAP2DLOCATION_H
contains definitions for common types used in navigation interfaces
bool read(yarp::os::idl::WireReader &reader) override
bool write(const yarp::os::idl::WireWriter &writer) const override
An interface for reading from a network connection.
An interface for writing to a network connection.
IDL-friendly connection reader.
Definition: WireReader.h:30
IDL-friendly connection writer.
Definition: WireWriter.h:30
The main, catch-all namespace for YARP.
Definition: dirs.h:16
bool write(const yarp::os::idl::WireWriter &writer) const override
Map2DLocation(const std::string &map_name, yarp::dev::Nav2D::XYWorld location)
A constructor which accepts a yarp::math::Vec2D, defining the location by its x,y coordinates.
Definition: Map2DLocation.h:51
bool write(yarp::os::ConnectionWriter &writer) const override
Write this object to a network connection.
bool operator==(const Map2DLocation &r) const
Compares two Map2DLocations.
bool read(yarp::os::ConnectionReader &reader) override
Read this object from a network connection.
std::string toString() const
Returns text representation of the location.
Definition: Map2DLocation.h:74
Map2DLocation(const std::string &map_name, const double &inX, const double &inY, const double &inT)
Constructor.
Definition: Map2DLocation.h:35
Map2DLocation()
Default constructor: the map name is empty, coordinates are set to zero.
Definition: Map2DLocation.h:62
bool operator!=(const Map2DLocation &r) const
Compares two Map2DLocations.
Definition: Map2DLocation.h:87
bool read(yarp::os::idl::WireReader &reader) override
Serialization methods.
#define YARP_dev_API
Definition: api.h:18