grid_metric_converter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, the neonavigation authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef PLANNER_CSPACE_PLANNER_3D_GRID_METRIC_CONVERTER_H
31 #define PLANNER_CSPACE_PLANNER_3D_GRID_METRIC_CONVERTER_H
32 
33 #include <costmap_cspace_msgs/MapMetaData3D.h>
34 #include <nav_msgs/Path.h>
36 
38 
39 #include <list>
40 #include <memory>
41 
43 {
44 template <typename T>
46  const costmap_cspace_msgs::MapMetaData3D& map_info,
47  const T x, const T y, const T yaw,
48  float& gx, float& gy, float& gyaw)
49 {
50  static_assert(
51  std::is_same<float, T>() || std::is_same<int, T>(), "T must be float or int");
52 
53  gx = (x + 0.5) * map_info.linear_resolution + map_info.origin.position.x;
54  gy = (y + 0.5) * map_info.linear_resolution + map_info.origin.position.y;
55  gyaw = yaw * map_info.angular_resolution;
56 }
57 inline void metric2Grid(
58  const costmap_cspace_msgs::MapMetaData3D& map_info,
59  int& x, int& y, int& yaw,
60  const float gx, const float gy, const float gyaw)
61 {
62  x = static_cast<int>(floor((gx - map_info.origin.position.x) / map_info.linear_resolution));
63  y = static_cast<int>(floor((gy - map_info.origin.position.y) / map_info.linear_resolution));
64  yaw = lroundf(gyaw / map_info.angular_resolution);
65 }
66 
67 template <template <class, class> class STL_CONTAINER = std::list>
69  const costmap_cspace_msgs::MapMetaData3D& map_info,
70  const STL_CONTAINER<CyclicVecFloat<3, 2>,
72  nav_msgs::Path& path)
73 {
74  for (const auto& p : path_grid)
75  {
76  float x, y, yaw;
77  grid2Metric(map_info, p[0], p[1], p[2], x, y, yaw);
78  geometry_msgs::PoseStamped ps;
79  ps.header = path.header;
80 
81  ps.pose.position.x = x;
82  ps.pose.position.y = y;
83  ps.pose.position.z = 0;
84  ps.pose.orientation =
85  tf2::toMsg(tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), yaw));
86  path.poses.push_back(ps);
87  }
88 }
89 } // namespace grid_metric_converter
90 
91 #endif // PLANNER_CSPACE_PLANNER_3D_GRID_METRIC_CONVERTER_H
TFSIMD_FORCE_INLINE const tfScalar & y() const
void metric2Grid(const costmap_cspace_msgs::MapMetaData3D &map_info, int &x, int &y, int &yaw, const float gx, const float gy, const float gyaw)
TFSIMD_FORCE_INLINE const tfScalar & x() const
void grid2Metric(const costmap_cspace_msgs::MapMetaData3D &map_info, const T x, const T y, const T yaw, float &gx, float &gy, float &gyaw)
B toMsg(const A &a)
void grid2MetricPath(const costmap_cspace_msgs::MapMetaData3D &map_info, const STL_CONTAINER< CyclicVecFloat< 3, 2 >, std::allocator< CyclicVecFloat< 3, 2 >>> &path_grid, nav_msgs::Path &path)


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Tue Jul 9 2019 05:00:13