22
22
#include < nav_msgs/msg/occupancy_grid.hpp>
23
23
24
24
#include < pybind11/pybind11.h>
25
+ #include < pybind11/stl.h>
25
26
26
27
using namespace freespace_planning_algorithms ;
27
28
29
+ struct PlannerWaypointsVector
30
+ {
31
+ std::vector<std::vector<double >> waypoints;
32
+ double length;
33
+ };
34
+
35
+
28
36
class AstarSearchPython : public AstarSearch
29
37
{
30
38
using AstarSearch::AstarSearch;
@@ -71,12 +79,33 @@ class AstarSearchPython : public AstarSearch
71
79
72
80
return AstarSearch::makePlan (start_pose, goal_pose);
73
81
}
82
+
83
+ PlannerWaypointsVector getWaypointsAsVector ()
84
+ {
85
+ PlannerWaypoints waypoints = AstarSearch::getWaypoints ();
86
+ PlannerWaypointsVector waypoints_vector;
87
+ for (const auto & waypoint : waypoints.waypoints )
88
+ {
89
+ // NOTE: it was difficult to return the deserialized pose_byte and serialize the pose_byte on
90
+ // python-side. So this function returns [*position, *quaternion] as double array
91
+ const auto & xyz = waypoint.pose .pose .position ;
92
+ const auto & quat = waypoint.pose .pose .orientation ;
93
+ waypoints_vector.waypoints .push_back (std::vector<double >({xyz.x , xyz.y , xyz.z , quat.x , quat.y , quat.z , quat.w }));
94
+ }
95
+ waypoints_vector.length = waypoints.compute_length ();
96
+ return waypoints_vector;
97
+ }
74
98
};
75
99
76
100
namespace py = pybind11;
77
101
78
- PYBIND11_MODULE (freespace_planning_algorithms_python , p)
102
+ PYBIND11_MODULE (freespace_planning_algorithms_pybind , p)
79
103
{
104
+ auto pyPlannerWaypointsVector =
105
+ py::class_<PlannerWaypointsVector>(p, " PlannerWaypointsVector" , py::dynamic_attr ())
106
+ .def (py::init<>())
107
+ .def_readwrite (" waypoints" , &PlannerWaypointsVector::waypoints)
108
+ .def_readwrite (" length" , &PlannerWaypointsVector::length);
80
109
auto pyAstarParam =
81
110
py::class_<AstarParam>(p, " AstarParam" , py::dynamic_attr ())
82
111
.def (py::init<>())
@@ -97,17 +126,19 @@ PYBIND11_MODULE(freespace_planning_algorithms_python, p)
97
126
.def_readwrite (" longitudinal_goal_range" , &PlannerCommonParam::longitudinal_goal_range)
98
127
.def_readwrite (" angle_goal_range" , &PlannerCommonParam::angle_goal_range)
99
128
.def_readwrite (" obstacle_threshold" , &PlannerCommonParam::obstacle_threshold);
100
- auto pyVSehicleShape = py::class_<VehicleShape>(p, " VehicleShape" , py::dynamic_attr ())
101
- .def (py::init<>())
102
- .def (py::init<double , double , double >())
103
- .def_readwrite (" length" , &VehicleShape::length)
104
- .def_readwrite (" width" , &VehicleShape::width)
105
- .def_readwrite (" base2back" , &VehicleShape::base2back);
129
+ auto pyVSehicleShape =
130
+ py::class_<VehicleShape>(p, " VehicleShape" , py::dynamic_attr ())
131
+ .def (py::init<>())
132
+ .def (py::init<double , double , double >())
133
+ .def_readwrite (" length" , &VehicleShape::length)
134
+ .def_readwrite (" width" , &VehicleShape::width)
135
+ .def_readwrite (" base2back" , &VehicleShape::base2back);
106
136
107
137
py::class_<AbstractPlanningAlgorithm>(p, " AbstractPlanningAlgorithm" );
108
138
py::class_<AstarSearch, AbstractPlanningAlgorithm>(p, " AstarSearchCpp" );
109
139
py::class_<AstarSearchPython, AstarSearch>(p, " AstarSearch" )
110
140
.def (py::init<PlannerCommonParam &, VehicleShape &, AstarParam &>())
111
141
.def (" setMap" , &AstarSearchPython::setMapByte)
112
- .def (" makePlan" , &AstarSearchPython::makePlanByte);
142
+ .def (" makePlan" , &AstarSearchPython::makePlanByte)
143
+ .def (" getWaypoints" , &AstarSearchPython::getWaypointsAsVector);
113
144
}
0 commit comments