conversions.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Fadri Furrer, ASL, ETH Zurich, Switzerland
3  * Copyright 2015 Michael Burri, ASL, ETH Zurich, Switzerland
4  * Copyright 2015 Markus Achtelik, ASL, ETH Zurich, Switzerland
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11 
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef MAV_PLANNING_MSGS_CONVERSIONS_H
20 #define MAV_PLANNING_MSGS_CONVERSIONS_H
21 
22 #include <geometry_msgs/Point.h>
23 #include <geometry_msgs/Quaternion.h>
24 #include <geometry_msgs/Vector3.h>
25 
26 #include "mav_planning_msgs/PolynomialSegment4D.h"
27 #include "mav_planning_msgs/PolynomialTrajectory4D.h"
29 
30 namespace mav_planning_msgs {
31 
33 inline void vectorFromMsgArray(const PolynomialSegment4D::_x_type& array,
34  Eigen::VectorXd* x) {
35  *x = Eigen::Map<const Eigen::VectorXd>(&(array[0]), array.size());
36 }
37 
39 inline void msgArrayFromVector(const Eigen::VectorXd& x,
40  PolynomialSegment4D::_x_type* array) {
41  array->resize(x.size());
42  Eigen::Map<Eigen::VectorXd> map =
43  Eigen::Map<Eigen::VectorXd>(&((*array)[0]), array->size());
44  map = x;
45 }
46 
48 inline void eigenPolynomialSegmentFromMsg(const PolynomialSegment4D& msg,
49  EigenPolynomialSegment* segment) {
50  assert(segment != NULL);
51 
52  vectorFromMsgArray(msg.x, &(segment->x));
53  vectorFromMsgArray(msg.y, &(segment->y));
54  vectorFromMsgArray(msg.z, &(segment->z));
55  vectorFromMsgArray(msg.yaw, &(segment->yaw));
56 
57  segment->segment_time_ns = msg.segment_time.toNSec();
58  segment->num_coeffs = msg.num_coeffs;
59 }
60 
63  const PolynomialTrajectory4D& msg,
64  EigenPolynomialTrajectory* eigen_trajectory) {
65  assert(eigen_trajectory != NULL);
66  eigen_trajectory->clear();
67  eigen_trajectory->reserve(msg.segments.size());
68  for (PolynomialTrajectory4D::_segments_type::const_iterator it =
69  msg.segments.begin();
70  it != msg.segments.end(); ++it) {
71  EigenPolynomialSegment segment;
72  eigenPolynomialSegmentFromMsg(*it, &segment);
73  eigen_trajectory->push_back(segment);
74  }
75 }
76 
80  PolynomialSegment4D* msg) {
81  assert(msg != NULL);
82  msgArrayFromVector(segment.x, &(msg->x));
83  msgArrayFromVector(segment.y, &(msg->y));
84  msgArrayFromVector(segment.z, &(msg->z));
85  msgArrayFromVector(segment.yaw, &(msg->yaw));
86 
87  msg->segment_time.fromNSec(segment.segment_time_ns);
88  msg->num_coeffs = segment.num_coeffs;
89 }
90 
94  const EigenPolynomialTrajectory& eigen_trajectory,
95  PolynomialTrajectory4D* msg) {
96  assert(msg != NULL);
97  msg->segments.reserve(eigen_trajectory.size());
98  for (EigenPolynomialTrajectory::const_iterator it = eigen_trajectory.begin();
99  it != eigen_trajectory.end(); ++it) {
100  PolynomialSegment4D segment;
101  polynomialSegmentMsgFromEigen(*it, &segment);
102  msg->segments.push_back(segment);
103  }
104 }
105 
106 } // namespace mav_planning_msgs
107 
108 #endif // MAV_PLANNING_MSGS_CONVERSIONS_H
void eigenPolynomialSegmentFromMsg(const PolynomialSegment4D &msg, EigenPolynomialSegment *segment)
Converts a PolynomialSegment message to an EigenPolynomialSegment structure.
Definition: conversions.h:48
void msgArrayFromVector(const Eigen::VectorXd &x, PolynomialSegment4D::_x_type *array)
Converts an Eigen::VectorXd to a PolynomialSegment double array.
Definition: conversions.h:39
void polynomialSegmentMsgFromEigen(const EigenPolynomialSegment &segment, PolynomialSegment4D *msg)
Definition: conversions.h:79
std::vector< EigenPolynomialSegment > EigenPolynomialTrajectory
void eigenPolynomialTrajectoryFromMsg(const PolynomialTrajectory4D &msg, EigenPolynomialTrajectory *eigen_trajectory)
Converts a PolynomialTrajectory message to a EigenPolynomialTrajectory.
Definition: conversions.h:62
void vectorFromMsgArray(const PolynomialSegment4D::_x_type &array, Eigen::VectorXd *x)
Converts a PolynomialSegment double array to an Eigen::VectorXd.
Definition: conversions.h:33
void polynomialTrajectoryMsgFromEigen(const EigenPolynomialTrajectory &eigen_trajectory, PolynomialTrajectory4D *msg)
Definition: conversions.h:93


mav_planning_msgs
Author(s): Simon Lynen, Markus Achtelik, Pascal Gohl, Sammy Omari, Michael Burri, Fadri Furrer, Helen Oleynikova, Karen Bodie, Rik Bähnemann
autogenerated on Sat Jun 15 2019 19:55:14