route_segment.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by Markus Bader <markus.bader@tuwien.ac.at> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
35 
36 using namespace tuw::ros_msgs;
37 
39 
40 };
41 
42 double RouteSegment::sample_equal_distance(std::vector<geometry_msgs::PosePtr> &poses, double distance_resolution,
43  double distance_offset) const
44 {
45  if (type == LINE)
46  {
47  double dx = end.position.x - start.position.x, dy = end.position.y - start.position.y;
48  double d = sqrt(dx * dx + dy * dy);
49  double ux = dx / d, uy = dy / d;
51  double l = distance_offset;
52  while (l < d)
53  {
54  pose.setXYZ(start.position.x + ux * l, start.position.y + uy * l, 0);
55  pose.setRPY(0, 0, atan2(uy, ux));
56  poses.push_back(pose.create());
57  l += distance_resolution;
58  }
59  distance_offset = l - d;
60  }
61  else if (type == ARC)
62  {
63  static const double LEFT = -1.;
64  static const double RIGHT = +1.;
65  double direction = LEFT;
66  if (orientation == tuw::ros_msgs::RouteSegment::CLOCKWISE)
67  direction = LEFT;
68  else if (orientation == tuw::ros_msgs::RouteSegment::COUNTER_CLOCKWISE)
69  direction = RIGHT;
70  else
71  throw 0;
72 
73  double dx0 = start.position.x - center.position.x, dy0 = start.position.y - center.position.y;
74  double a0 = atan2(dy0, dx0);
75  double radius = sqrt(dx0 * dx0 + dy0 * dy0);
76  double dx1 = end.position.x - center.position.x, dy1 = end.position.y - center.position.y;
77  double a1 = atan2(dy1, dx1);
78 
79  double da = atan2(sin(a0 - a1), cos(a0 - a1));
80  if (direction == RIGHT)
81  {
82  da = da < 0 ? da : da - 2 * M_PI;
83  }
84  else
85  {
86  da = da >= 0 ? da : da + 2 * M_PI;
87  }
88  double d = fabs(da) * radius;
89 
91  double l = distance_offset;
92  while (l < d)
93  {
94  double a = a0 + l / radius * direction;
95  pose.setXYZ(center.position.x + cos(a) * radius, center.position.y + sin(a) * radius, 0);
96  pose.setRPY(0, 0, a + (M_PI / 2. * direction));
97  poses.push_back(pose.create());
98  l += distance_resolution;
99  }
100  distance_offset = l - d;
101  }
102  return distance_offset;
103 }
104 
105 double RouteSegment::sample_equal_angle(std::vector<geometry_msgs::PosePtr> &poses, double angle_resolution,
106  double distance_offset) const
107 {
108  if (type == ARC)
109  {
110  double radius = tuw::Distance(start.position, center.position);
111  double distance_resolution = angle_resolution * radius;
112  return sample_equal_distance(poses, distance_resolution, distance_offset);
113  }
114  if (type == LINE)
115  {
116  double distance_resolution = tuw::Distance(start.position, end.position);
117  return sample_equal_distance(poses, distance_resolution, distance_offset);
118  }
119 }
d
static const unsigned int ARC
Definition: route_segment.h:50
double Distance(const geometry_msgs::Point &a, const geometry_msgs::Point &b)
static const unsigned int COUNTER_CLOCKWISE
Definition: route_segment.h:54
static const unsigned int LINE
Definition: route_segment.h:49
double sample_equal_angle(std::vector< geometry_msgs::PosePtr > &poses, double angle, double distance_offset) const
double sample_equal_distance(std::vector< geometry_msgs::PosePtr > &poses, double distance, double distance_offset) const
Pose & setXYZ(double x, double y, double z)
Pose & setRPY(double roll, double pitch, double yaw)
static const unsigned int CLOCKWISE
Definition: route_segment.h:53
geometry_msgs::PosePtr create()


tuw_nav_msgs
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:37:22