Skip to content

Commit

Permalink
Add pybinds for saving and loading geometry from a .scene file (#2971)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgill92 authored Aug 15, 2024
1 parent a693e3e commit 208f7f7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions moveit_py/moveit/core/planning_scene.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class PlanningScene:
def process_planning_scene_world(self, *args, **kwargs) -> Any: ...
def remove_all_collision_objects(self, *args, **kwargs) -> Any: ...
def set_object_color(self, *args, **kwargs) -> Any: ...
def save_geometry_to_file(self, file_name_and_path) -> Any: ...
def load_geometry_from_file(self, file_name_and_path) -> Any: ...
def __copy__(self) -> Any: ...
def __deepcopy__(self) -> Any: ...
@property
Expand Down
49 changes: 49 additions & 0 deletions moveit_py/src/moveit/moveit_core/planning_scene/planning_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@
#include <moveit_py/moveit_py_utils/ros_msg_typecasters.h>
#include <pybind11/operators.h>

#include <fstream>

namespace
{
bool saveGeometryToFile(std::shared_ptr<planning_scene::PlanningScene>& planning_scene,
const std::string& file_path_and_name)
{
std::ofstream file(file_path_and_name);
if (!file.is_open())
{
return false;
}
planning_scene->saveGeometryToStream(file);
file.close();
return true;
}

bool loadGeometryFromFile(std::shared_ptr<planning_scene::PlanningScene>& planning_scene,
const std::string& file_path_and_name)
{
std::ifstream file(file_path_and_name);
planning_scene->loadGeometryFromStream(file);
file.close();
return true;
}
} // namespace

namespace moveit_py
{
namespace bind_planning_scene
Expand Down Expand Up @@ -431,6 +458,28 @@ void initPlanningScene(py::module& m)
Returns:
bool: true if state is in self collision otherwise false.
)")

.def("save_geometry_to_file", &saveGeometryToFile, py::arg("file_path_and_name"),
R"(
Save the CollisionObjects in the PlanningScene to a file
Args:
file_path_and_name (str): The file to save the CollisionObjects to.
Returns:
bool: true if save to file was successful otherwise false.
)")

.def("load_geometry_from_file", &loadGeometryFromFile, py::arg("file_path_and_name"),
R"(
Load the CollisionObjects from a file to the PlanningScene
Args:
file_path_and_name (str): The file to load the CollisionObjects from.
Returns:
bool: true if load from file was successful otherwise false.
)");
}
} // namespace bind_planning_scene
Expand Down

0 comments on commit 208f7f7

Please sign in to comment.