12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- #include " freespace_planning_algorithms/astar_search.hpp"
16
15
#include " freespace_planning_algorithms/abstract_algorithm.hpp"
16
+ #include " freespace_planning_algorithms/astar_search.hpp"
17
+
17
18
#include < rclcpp/rclcpp.hpp>
18
19
#include < rclcpp/serialization.hpp>
19
20
@@ -26,85 +27,87 @@ using namespace freespace_planning_algorithms;
26
27
27
28
class AstarSearchPython : public AstarSearch
28
29
{
29
- using AstarSearch::AstarSearch;
30
- public:
31
- void setMapByte (const std::string & costmap_byte)
32
- {
33
- rclcpp::SerializedMessage serialized_msg;
34
- static constexpr size_t message_header_length = 8u ;
35
- serialized_msg.reserve (message_header_length + costmap_byte.size ());
36
- serialized_msg.get_rcl_serialized_message ().buffer_length = costmap_byte.size ();
37
- for (size_t i = 0 ; i < costmap_byte.size (); ++i) {
38
- serialized_msg.get_rcl_serialized_message ().buffer [i] = costmap_byte[i];
39
- }
40
- nav_msgs::msg::OccupancyGrid costmap;
41
- static rclcpp::Serialization<nav_msgs::msg::OccupancyGrid> serializer;
42
- serializer.deserialize_message (&serialized_msg, &costmap);
43
-
44
- AstarSearch::setMap (costmap);
45
- }
46
-
47
- bool makePlanByte (const std::string & start_pose_byte, const std::string & goal_pose_byte)
48
- {
49
- rclcpp::SerializedMessage serialized_start_msg;
50
- static constexpr size_t message_header_length = 8u ;
51
- serialized_start_msg.reserve (message_header_length + start_pose_byte.size ());
52
- serialized_start_msg.get_rcl_serialized_message ().buffer_length = start_pose_byte.size ();
53
- for (size_t i = 0 ; i < start_pose_byte.size (); ++i) {
54
- serialized_start_msg.get_rcl_serialized_message ().buffer [i] = start_pose_byte[i];
55
- }
56
- geometry_msgs::msg::Pose start_pose;
57
- static rclcpp::Serialization<geometry_msgs::msg::Pose> start_serializer;
58
- start_serializer.deserialize_message (&serialized_start_msg, &start_pose);
59
-
60
- rclcpp::SerializedMessage serialized_goal_msg;
61
- serialized_goal_msg.reserve (message_header_length + goal_pose_byte.size ());
62
- serialized_goal_msg.get_rcl_serialized_message ().buffer_length = goal_pose_byte.size ();
63
- for (size_t i = 0 ; i < goal_pose_byte.size (); ++i) {
64
- serialized_goal_msg.get_rcl_serialized_message ().buffer [i] = goal_pose_byte[i];
65
- }
66
- geometry_msgs::msg::Pose goal_pose;
67
- static rclcpp::Serialization<geometry_msgs::msg::Pose> goal_serializer;
68
- goal_serializer.deserialize_message (&serialized_goal_msg, &goal_pose);
69
-
70
- return AstarSearch::makePlan (start_pose, goal_pose);
71
- }
30
+ using AstarSearch::AstarSearch;
31
+
32
+ public:
33
+ void setMapByte (const std::string & costmap_byte)
34
+ {
35
+ rclcpp::SerializedMessage serialized_msg;
36
+ static constexpr size_t message_header_length = 8u ;
37
+ serialized_msg.reserve (message_header_length + costmap_byte.size ());
38
+ serialized_msg.get_rcl_serialized_message ().buffer_length = costmap_byte.size ();
39
+ for (size_t i = 0 ; i < costmap_byte.size (); ++i) {
40
+ serialized_msg.get_rcl_serialized_message ().buffer [i] = costmap_byte[i];
41
+ }
42
+ nav_msgs::msg::OccupancyGrid costmap;
43
+ static rclcpp::Serialization<nav_msgs::msg::OccupancyGrid> serializer;
44
+ serializer.deserialize_message (&serialized_msg, &costmap);
45
+
46
+ AstarSearch::setMap (costmap);
47
+ }
48
+
49
+ bool makePlanByte (const std::string & start_pose_byte, const std::string & goal_pose_byte)
50
+ {
51
+ rclcpp::SerializedMessage serialized_start_msg;
52
+ static constexpr size_t message_header_length = 8u ;
53
+ serialized_start_msg.reserve (message_header_length + start_pose_byte.size ());
54
+ serialized_start_msg.get_rcl_serialized_message ().buffer_length = start_pose_byte.size ();
55
+ for (size_t i = 0 ; i < start_pose_byte.size (); ++i) {
56
+ serialized_start_msg.get_rcl_serialized_message ().buffer [i] = start_pose_byte[i];
57
+ }
58
+ geometry_msgs::msg::Pose start_pose;
59
+ static rclcpp::Serialization<geometry_msgs::msg::Pose> start_serializer;
60
+ start_serializer.deserialize_message (&serialized_start_msg, &start_pose);
61
+
62
+ rclcpp::SerializedMessage serialized_goal_msg;
63
+ serialized_goal_msg.reserve (message_header_length + goal_pose_byte.size ());
64
+ serialized_goal_msg.get_rcl_serialized_message ().buffer_length = goal_pose_byte.size ();
65
+ for (size_t i = 0 ; i < goal_pose_byte.size (); ++i) {
66
+ serialized_goal_msg.get_rcl_serialized_message ().buffer [i] = goal_pose_byte[i];
67
+ }
68
+ geometry_msgs::msg::Pose goal_pose;
69
+ static rclcpp::Serialization<geometry_msgs::msg::Pose> goal_serializer;
70
+ goal_serializer.deserialize_message (&serialized_goal_msg, &goal_pose);
71
+
72
+ return AstarSearch::makePlan (start_pose, goal_pose);
73
+ }
72
74
};
73
75
74
-
75
76
namespace py = pybind11;
76
77
77
78
PYBIND11_MODULE (freespace_planning_algorithms_python, p)
78
79
{
79
- auto pyAstarParam = py::class_<AstarParam>(p, " AstarParam" , py::dynamic_attr ())
80
- .def (py::init<>())
81
- .def_readwrite (" only_behind_solutions" , &AstarParam::only_behind_solutions)
82
- .def_readwrite (" use_back" , &AstarParam::use_back)
83
- .def_readwrite (" distance_heuristic_weight" , &AstarParam::distance_heuristic_weight);
84
- auto pyPlannerCommonParam = py::class_<PlannerCommonParam>(p, " PlannerCommonParam" , py::dynamic_attr ())
85
- .def (py::init<>())
86
- .def_readwrite (" time_limit" , &PlannerCommonParam::time_limit)
87
- .def_readwrite (" minimum_turning_radius" , &PlannerCommonParam::minimum_turning_radius)
88
- .def_readwrite (" maximum_turning_radius" , &PlannerCommonParam::maximum_turning_radius)
89
- .def_readwrite (" turning_radius_size" , &PlannerCommonParam::turning_radius_size)
90
- .def_readwrite (" theta_size" , &PlannerCommonParam::theta_size)
91
- .def_readwrite (" curve_weight" , &PlannerCommonParam::curve_weight)
92
- .def_readwrite (" reverse_weight" , &PlannerCommonParam::reverse_weight)
93
- .def_readwrite (" lateral_goal_range" , &PlannerCommonParam::lateral_goal_range)
94
- .def_readwrite (" longitudinal_goal_range" , &PlannerCommonParam::longitudinal_goal_range)
95
- .def_readwrite (" angle_goal_range" , &PlannerCommonParam::angle_goal_range)
96
- .def_readwrite (" obstacle_threshold" , &PlannerCommonParam::obstacle_threshold);
97
- auto pyVSehicleShape = py::class_<VehicleShape>(p, " VehicleShape" , py::dynamic_attr ())
98
- .def (py::init<>())
99
- .def (py::init<double , double , double >())
100
- .def_readwrite (" length" , &VehicleShape::length)
101
- .def_readwrite (" width" , &VehicleShape::width)
102
- .def_readwrite (" base2back" , &VehicleShape::base2back);
103
-
104
- py::class_<AbstractPlanningAlgorithm>(p, " AbstractPlanningAlgorithm" );
105
- py::class_<AstarSearch, AbstractPlanningAlgorithm>(p, " AstarSearchCpp" );
106
- py::class_<AstarSearchPython, AstarSearch>(p, " AstarSearch" )
107
- .def (py::init<PlannerCommonParam &, VehicleShape &, AstarParam &>())
108
- .def (" setMap" , &AstarSearchPython::setMapByte)
109
- .def (" makePlan" , &AstarSearchPython::makePlanByte);
80
+ auto pyAstarParam =
81
+ py::class_<AstarParam>(p, " AstarParam" , py::dynamic_attr ())
82
+ .def (py::init<>())
83
+ .def_readwrite (" only_behind_solutions" , &AstarParam::only_behind_solutions)
84
+ .def_readwrite (" use_back" , &AstarParam::use_back)
85
+ .def_readwrite (" distance_heuristic_weight" , &AstarParam::distance_heuristic_weight);
86
+ auto pyPlannerCommonParam =
87
+ py::class_<PlannerCommonParam>(p, " PlannerCommonParam" , py::dynamic_attr ())
88
+ .def (py::init<>())
89
+ .def_readwrite (" time_limit" , &PlannerCommonParam::time_limit)
90
+ .def_readwrite (" minimum_turning_radius" , &PlannerCommonParam::minimum_turning_radius)
91
+ .def_readwrite (" maximum_turning_radius" , &PlannerCommonParam::maximum_turning_radius)
92
+ .def_readwrite (" turning_radius_size" , &PlannerCommonParam::turning_radius_size)
93
+ .def_readwrite (" theta_size" , &PlannerCommonParam::theta_size)
94
+ .def_readwrite (" curve_weight" , &PlannerCommonParam::curve_weight)
95
+ .def_readwrite (" reverse_weight" , &PlannerCommonParam::reverse_weight)
96
+ .def_readwrite (" lateral_goal_range" , &PlannerCommonParam::lateral_goal_range)
97
+ .def_readwrite (" longitudinal_goal_range" , &PlannerCommonParam::longitudinal_goal_range)
98
+ .def_readwrite (" angle_goal_range" , &PlannerCommonParam::angle_goal_range)
99
+ .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);
106
+
107
+ py::class_<AbstractPlanningAlgorithm>(p, " AbstractPlanningAlgorithm" );
108
+ py::class_<AstarSearch, AbstractPlanningAlgorithm>(p, " AstarSearchCpp" );
109
+ py::class_<AstarSearchPython, AstarSearch>(p, " AstarSearch" )
110
+ .def (py::init<PlannerCommonParam &, VehicleShape &, AstarParam &>())
111
+ .def (" setMap" , &AstarSearchPython::setMapByte)
112
+ .def (" makePlan" , &AstarSearchPython::makePlanByte);
110
113
}
0 commit comments