route_segments.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 #include <tf/tf.h>
36 
37 using namespace tuw::ros_msgs;
38 
40 
41 };
42 
44 {
45  segments.resize(n);
46 }
47 
48 void RouteSegments::set_ids(const std::vector<unsigned int> &id)
49 {
50  if (segments.size() != id.size())
51  segments.resize(id.size());
52  for (int i = 0; i < segments.size(); i++)
53  segments[i].id = id[i];
54 }
55 void RouteSegments::set_type(const std::vector<unsigned int> &type)
56 {
57  if (segments.size() != type.size())
58  segments.resize(type.size());
59  for (int i = 0; i < segments.size(); i++)
60  segments[i].type = type[i];
61 }
62 void RouteSegments::set_orientation(const std::vector<unsigned int> &orientation)
63 {
64  if (segments.size() != orientation.size())
65  segments.resize(orientation.size());
66  for (int i = 0; i < segments.size(); i++)
67  segments[i].orientation = orientation[i];
68 }
69 void RouteSegments::set_motion_type(const std::vector<unsigned int> &motion_type)
70 {
71  if (segments.size() != motion_type.size())
72  segments.resize(motion_type.size());
73  for (int i = 0; i < segments.size(); i++)
74  segments[i].motion_type = motion_type[i];
75 }
76 void RouteSegments::set_start(const std::vector<double> &x, const std::vector<double> &y,
77  const std::vector<double> &theta)
78 {
79  if (segments.size() != x.size())
80  segments.resize(x.size());
81  for (int i = 0; i < segments.size(); i++)
82  {
83  segments[i].start.position.x = x[i];
84  segments[i].start.position.y = y[i];
85  segments[i].start.position.z = 0;
87  q.setRPY(0, 0, theta[i]);
88  segments[i].start.orientation.x = q.getX();
89  segments[i].start.orientation.y = q.getY();
90  segments[i].start.orientation.z = q.getZ();
91  segments[i].start.orientation.w = q.getW();
92  }
93 }
94 void RouteSegments::set_end(const std::vector<double> &x, const std::vector<double> &y,
95  const std::vector<double> &theta)
96 {
97  if (segments.size() != x.size())
98  segments.resize(x.size());
99  for (int i = 0; i < segments.size(); i++)
100  {
101  segments[i].end.position.x = x[i];
102  segments[i].end.position.y = y[i];
103  segments[i].end.position.z = 0;
104  tf::Quaternion q;
105  q.setRPY(0, 0, theta[i]);
106  segments[i].end.orientation.x = q.getX();
107  segments[i].end.orientation.y = q.getY();
108  segments[i].end.orientation.z = q.getZ();
109  segments[i].end.orientation.w = q.getW();
110  }
111 }
112 void RouteSegments::set_center(const std::vector<double> &x, const std::vector<double> &y,
113  const std::vector<double> &theta)
114 {
115  if (segments.size() != x.size())
116  segments.resize(x.size());
117  for (int i = 0; i < segments.size(); i++)
118  {
119  segments[i].center.position.x = x[i];
120  segments[i].center.position.y = y[i];
121  segments[i].center.position.z = 0;
122  tf::Quaternion q;
123  q.setRPY(0, 0, theta[i]);
124  segments[i].center.orientation.x = q.getX();
125  segments[i].center.orientation.y = q.getY();
126  segments[i].center.orientation.z = q.getZ();
127  segments[i].center.orientation.w = q.getW();
128  }
129 }
130 void RouteSegments::set_level(const std::vector<int> &level)
131 {
132  if (segments.size() != level.size())
133  segments.resize(level.size());
134  for (int i = 0; i < segments.size(); i++)
135  segments[i].level = level[i];
136 }
137 
138 void RouteSegments::convert(nav_msgs::Path &path, double distance) const
139 {
140  path.header = header;
141  double offset = 0;
142  std::vector<geometry_msgs::PosePtr> waypoints;
143  for (size_t i = 0; i < segments.size(); i++)
144  {
145  const tuw::ros_msgs::RouteSegment &segment = (const tuw::ros_msgs::RouteSegment &)segments[i];
146  offset = segment.sample_equal_distance(waypoints, distance, offset);
147  }
149  if (offset > 0)
150  {
151  path.poses.resize(waypoints.size() + 1);
152  }
153  else
154  {
155  path.poses.resize(waypoints.size());
156  }
157  for (size_t i = 0; i < waypoints.size(); i++)
158  {
159  path.poses[i].header = header;
160  path.poses[i].pose = *waypoints[i];
161  }
162  if (offset > 0)
163  {
165  path.poses[waypoints.size()].header = header;
166  path.poses[waypoints.size()].pose = segments.back().end;
167  }
168 }
void set_type(const std::vector< unsigned int > &type)
void set_ids(const std::vector< unsigned int > &id)
TFSIMD_FORCE_INLINE const tfScalar & getW() const
void convert(nav_msgs::Path &path, double sample_distance) const
void set_orientation(const std::vector< unsigned int > &orientation)
void set_end(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &theta)
void setRPY(const tfScalar &roll, const tfScalar &pitch, const tfScalar &yaw)
double sample_equal_distance(std::vector< geometry_msgs::PosePtr > &poses, double distance, double distance_offset) const
void set_level(const std::vector< int > &level)
void set_motion_type(const std::vector< unsigned int > &motion_type)
void set_start(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &theta)
void set_center(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &theta)


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