nav_grid_message_utils.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef NAV_GRID_PUB_SUB_NAV_GRID_MESSAGE_UTILS_H
36 #define NAV_GRID_PUB_SUB_NAV_GRID_MESSAGE_UTILS_H
37 
39 #include <nav_2d_msgs/NavGridOfChars.h>
40 #include <nav_2d_msgs/NavGridOfCharsUpdate.h>
41 #include <nav_2d_msgs/NavGridOfDoubles.h>
42 #include <nav_2d_msgs/NavGridOfDoublesUpdate.h>
45 #include <nav_core2/bounds.h>
46 
47 namespace nav_grid_pub_sub
48 {
58 template<typename ROSMsgType, typename NumericType>
59 ROSMsgType toMsg(const nav_grid::NavGrid<NumericType>& grid, const ros::Time& stamp)
60 {
61  const nav_grid::NavGridInfo& info = grid.getInfo();
62 
63  ROSMsgType msg;
64  msg.stamp = stamp;
65  msg.info = nav_2d_utils::toMsg(info);
66  msg.data.resize(info.width * info.height);
67 
68  unsigned int data_index = 0;
69  for (const nav_grid::Index& index : nav_grid_iterators::WholeGrid(info))
70  {
71  msg.data[data_index++] = grid(index);
72  }
73  return msg;
74 }
75 
81 template<typename ROSMsgType, typename NumericType>
82 ROSMsgType toUpdate(const nav_grid::NavGrid<NumericType>& grid, const nav_core2::UIntBounds& bounds,
83  const ros::Time& stamp)
84 {
85  ROSMsgType update;
86  update.stamp = stamp;
87  update.bounds = nav_2d_utils::toMsg(bounds);
88  update.data.resize(bounds.getWidth() * bounds.getHeight());
89 
90  unsigned int data_index = 0;
91  const nav_grid::NavGridInfo& info = grid.getInfo();
92  for (const nav_grid::Index& index : nav_grid_iterators::SubGrid(&info, bounds))
93  {
94  update.data[data_index++] = grid(index);
95  }
96  return update;
97 }
98 
102 inline nav_2d_msgs::NavGridOfChars toMsg(const nav_grid::NavGrid<unsigned char>& grid,
103  const ros::Time& stamp = ros::Time(0))
104 {
105  return toMsg<nav_2d_msgs::NavGridOfChars>(grid, stamp);
106 }
107 
111 inline nav_2d_msgs::NavGridOfDoubles toMsg(const nav_grid::NavGrid<double>& grid, const ros::Time& stamp = ros::Time(0))
112 {
113  return toMsg<nav_2d_msgs::NavGridOfDoubles>(grid, stamp);
114 }
115 
119 inline nav_2d_msgs::NavGridOfDoubles toMsg(const nav_grid::NavGrid<float>& grid, const ros::Time& stamp = ros::Time(0))
120 {
121  return toMsg<nav_2d_msgs::NavGridOfDoubles>(grid, stamp);
122 }
123 
127 inline nav_2d_msgs::NavGridOfCharsUpdate toUpdate(const nav_grid::NavGrid<unsigned char>& grid,
128  const nav_core2::UIntBounds& bounds, const ros::Time& stamp = ros::Time(0))
129 {
130  return toUpdate<nav_2d_msgs::NavGridOfCharsUpdate>(grid, bounds, stamp);
131 }
132 
136 inline nav_2d_msgs::NavGridOfDoublesUpdate toUpdate(const nav_grid::NavGrid<double>& grid,
137  const nav_core2::UIntBounds& bounds, const ros::Time& stamp = ros::Time(0))
138 {
139  return toUpdate<nav_2d_msgs::NavGridOfDoublesUpdate>(grid, bounds, stamp);
140 }
141 
145 inline nav_2d_msgs::NavGridOfDoublesUpdate toUpdate(const nav_grid::NavGrid<float>& grid,
146  const nav_core2::UIntBounds& bounds, const ros::Time& stamp = ros::Time(0))
147 {
148  return toUpdate<nav_2d_msgs::NavGridOfDoublesUpdate>(grid, bounds, stamp);
149 }
150 
151 
152 } // namespace nav_grid_pub_sub
153 
154 #endif // NAV_GRID_PUB_SUB_NAV_GRID_MESSAGE_UTILS_H
ROSMsgType toUpdate(const nav_grid::NavGrid< NumericType > &grid, const nav_core2::UIntBounds &bounds, const ros::Time &stamp)
Generic conversion from a portion of a grid of arbitrary type to an update message of arbitrary type...
nav_2d_msgs::NavGridInfo toMsg(const nav_grid::NavGridInfo &info)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
NavGridInfo getInfo() const
unsigned int getHeight() const
unsigned int getWidth() const
ROSMsgType toMsg(const nav_grid::NavGrid< NumericType > &grid, const ros::Time &stamp)
Utilities for converting NavGrid objects to NavGridOfX messages and updates.


nav_grid_pub_sub
Author(s):
autogenerated on Wed Jun 26 2019 20:06:28