|
23 | 23 | #include <geometry_msgs/Quaternion.h> |
24 | 24 | #include <geometry_msgs/Vector3.h> |
25 | 25 |
|
26 | | -#include "planning_msgs/WayPoint.h" |
27 | | -#include "planning_msgs/WayPointArray.h" |
28 | | -#include "planning_msgs/WaypointType.h" |
| 26 | +#include "planning_msgs/PolynomialSegment4D.h" |
| 27 | +#include "planning_msgs/PolynomialTrajectory4D.h" |
29 | 28 | #include "planning_msgs/eigen_planning_msgs.h" |
30 | 29 |
|
31 | 30 | namespace planning_msgs { |
32 | 31 |
|
33 | | -/// Converts a WayPoint double array to an Eigen::VectorXd. |
34 | | -inline void vectorFromMsgArray(const WayPoint::_x_type& array, |
| 32 | +/// Converts a PolynomialSegment double array to an Eigen::VectorXd. |
| 33 | +inline void vectorFromMsgArray(const PolynomialSegment4D::_x_type& array, |
35 | 34 | Eigen::VectorXd* x) { |
36 | 35 | *x = Eigen::Map<const Eigen::VectorXd>(&(array[0]), array.size()); |
37 | 36 | } |
38 | 37 |
|
39 | | -/// Converts an Eigen::VectorXd to a WayPoint double array. |
| 38 | +/// Converts an Eigen::VectorXd to a PolynomialSegment double array. |
40 | 39 | inline void msgArrayFromVector(const Eigen::VectorXd& x, |
41 | | - WayPoint::_x_type* array) { |
| 40 | + PolynomialSegment4D::_x_type* array) { |
42 | 41 | array->resize(x.size()); |
43 | 42 | Eigen::Map<Eigen::VectorXd> map = |
44 | 43 | Eigen::Map<Eigen::VectorXd>(&((*array)[0]), array->size()); |
45 | 44 | map = x; |
46 | 45 | } |
47 | 46 |
|
48 | | -/// Converts a WayPoint message to an EigenWayPoint structure. |
49 | | -inline void eigenWaypointFromMsg(const WayPoint& msg, EigenWayPoint* waypoint) { |
50 | | - assert(waypoint != NULL); |
| 47 | +/// Converts a PolynomialSegment message to an EigenPolynomialSegment structure. |
| 48 | +inline void eigenPolynomialSegmentFromMsg( |
| 49 | + const PolynomialSegment4D& msg, EigenPolynomialSegment* segment) { |
| 50 | + assert(segment != NULL); |
51 | 51 |
|
52 | | - vectorFromMsgArray(msg.x, &(waypoint->x)); |
53 | | - vectorFromMsgArray(msg.y, &(waypoint->y)); |
54 | | - vectorFromMsgArray(msg.z, &(waypoint->z)); |
55 | | - vectorFromMsgArray(msg.yaw, &(waypoint->yaw)); |
| 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 | 56 |
|
57 | | - waypoint->time = msg.time; |
58 | | - waypoint->type = msg.type; |
| 57 | + segment->segment_time_ns = msg.segment_time.toNSec(); |
| 58 | + segment->num_coeffs = msg.num_coeffs; |
59 | 59 | } |
60 | 60 |
|
61 | | -/// Converts a WayPointArray message to a EigenWayPointArray |
62 | | -inline void eigenWaypointArrayFromMsg(const WayPointArray& msg, |
63 | | - EigenWaypointArray* waypoint_array) { |
64 | | - assert(waypoint_array != NULL); |
65 | | - waypoint_array->clear(); |
66 | | - waypoint_array->reserve(msg.waypoints.size()); |
67 | | - for (WayPointArray::_waypoints_type::const_iterator it = |
68 | | - msg.waypoints.begin(); |
69 | | - it != msg.waypoints.end(); ++it) { |
70 | | - EigenWayPoint wp; |
71 | | - eigenWaypointFromMsg(*it, &wp); |
72 | | - waypoint_array->push_back(wp); |
| 61 | +/// Converts a PolynomialTrajectory message to a EigenPolynomialTrajectory |
| 62 | +inline void eigenPolynomialTrajectoryFromMsg( |
| 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); |
73 | 74 | } |
74 | 75 | } |
75 | 76 |
|
76 | | -/// Converts an EigenWayPoint to a WayPoint message. Does NOT set the header! |
77 | | -inline void wayPointMsgFromEigen(const EigenWayPoint& waypoint, WayPoint* msg) { |
| 77 | +/// Converts an EigenPolynomialSegment to a PolynomialSegment message. Does NOT |
| 78 | +/// set the header! |
| 79 | +inline void polynomialSegmentMsgFromEigen( |
| 80 | + const EigenPolynomialSegment& segment, PolynomialSegment4D* msg) { |
78 | 81 | assert(msg != NULL); |
79 | | - msgArrayFromVector(waypoint.x, &(msg->x)); |
80 | | - msgArrayFromVector(waypoint.y, &(msg->y)); |
81 | | - msgArrayFromVector(waypoint.z, &(msg->z)); |
82 | | - msgArrayFromVector(waypoint.yaw, &(msg->yaw)); |
| 82 | + msgArrayFromVector(segment.x, &(msg->x)); |
| 83 | + msgArrayFromVector(segment.y, &(msg->y)); |
| 84 | + msgArrayFromVector(segment.z, &(msg->z)); |
| 85 | + msgArrayFromVector(segment.yaw, &(msg->yaw)); |
83 | 86 |
|
84 | | - msg->time = waypoint.time; |
85 | | - msg->type = waypoint.type; |
| 87 | + msg->segment_time.fromNSec(segment.segment_time_ns); |
| 88 | + msg->num_coeffs = segment.num_coeffs; |
86 | 89 | } |
87 | 90 |
|
88 | | -/// Converts an EigenWayPointArray to a WayPointArray message. Does NOT set the |
89 | | -/// header! |
90 | | -inline void waypointArrayMsgFromEigen(const EigenWaypointArray& waypoint_array, |
91 | | - WayPointArray* msg) { |
| 91 | +/// Converts an EigenPolynomialTrajectory to a PolynomialTrajectory message. |
| 92 | +/// Does NOT set the header! |
| 93 | +inline void polynomialTrajectoryMsgFromEigen( |
| 94 | + const EigenPolynomialTrajectory& eigen_trajectory, |
| 95 | + PolynomialTrajectory4D* msg) { |
92 | 96 | assert(msg != NULL); |
93 | | - msg->waypoints.reserve(waypoint_array.size()); |
94 | | - for (EigenWaypointArray::const_iterator it = waypoint_array.begin(); |
95 | | - it != waypoint_array.end(); ++it) { |
96 | | - WayPoint wp; |
97 | | - wayPointMsgFromEigen(*it, &wp); |
98 | | - msg->waypoints.push_back(wp); |
| 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); |
99 | 103 | } |
100 | 104 | } |
101 | 105 | } |
|
0 commit comments