Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Python interfaces to some Ignition Gazebo methods #1219

Merged
merged 37 commits into from
Feb 25, 2022
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cd14e6a
Added Python interfaces to same Ignition Gazebo methods
ahcorde Nov 19, 2021
3bc8e37
Added feedback
ahcorde Nov 25, 2021
4106c2b
Fixed License style
ahcorde Nov 25, 2021
7a54950
Fix style in destroyable class
ahcorde Nov 25, 2021
dbe9c08
return optional
ahcorde Nov 30, 2021
894ed35
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
ahcorde Nov 30, 2021
b2b9f8c
Follow code conventions
ahcorde Dec 10, 2021
7cf6ce6
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
ahcorde Dec 10, 2021
4682207
Fix
ahcorde Dec 10, 2021
3a56759
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
ahcorde Dec 30, 2021
0b89181
Feedback
ahcorde Dec 30, 2021
517f110
Added tutorial
ahcorde Jan 5, 2022
81a732a
CMake changes
ahcorde Jan 11, 2022
673ad9b
Added feedback
ahcorde Jan 13, 2022
6a9d769
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
ahcorde Jan 13, 2022
999d6a6
Fixed python issue
ahcorde Jan 14, 2022
81d7a3e
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
ahcorde Jan 14, 2022
30d8e00
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
ahcorde Jan 17, 2022
51763e4
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
ahcorde Jan 19, 2022
bac0c08
added test
ahcorde Jan 20, 2022
5a27a27
Merge branch 'ahcorde/python/gazebo' of https://github.com/ignitionro…
ahcorde Jan 20, 2022
76ce104
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
chapulina Jan 21, 2022
d0f1365
Added feedback
ahcorde Jan 21, 2022
a727ebf
Merge branch 'ahcorde/python/gazebo' of https://github.com/ignitionro…
ahcorde Jan 21, 2022
f8a31d5
Added feedback
ahcorde Jan 21, 2022
5619121
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
ahcorde Jan 24, 2022
3eb5691
[python] Add worldEntity util (#1308)
chapulina Jan 25, 2022
5929ce9
upate license year
ahcorde Jan 25, 2022
eba46e7
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
ahcorde Jan 25, 2022
738d0ca
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
chapulina Jan 27, 2022
c1bd44b
Depend on python3-ignition-math on Focal
chapulina Jan 27, 2022
6bac808
expose python options
chapulina Jan 28, 2022
e5ded4c
Use CMAKE_INSTALL_LIBDIR to also support lib/x86_64-linux-gnu
chapulina Jan 29, 2022
7063380
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
j-rivero Feb 17, 2022
98fa03c
Merge branch 'ign-gazebo6' into ahcorde/python/gazebo
j-rivero Feb 24, 2022
85b540c
Merge remote-tracking branch 'origin/ign-gazebo6' into ahcorde/python…
ahcorde Feb 25, 2022
d5e34d5
fixed cmakelists
ahcorde Feb 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added feedback
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde committed Nov 25, 2021
commit 3bc8e374f32031daec88c104f625797fdc7e6368
13 changes: 13 additions & 0 deletions examples/python/helperFixture.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#!/usr/bin/python3
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
# Copyright (C) 2021 Open Source Robotics Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import time
2 changes: 0 additions & 2 deletions python/src/ignition/common/_ignition_common_pybind11.cc
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@

#include "console.hh"

namespace py = pybind11;

PYBIND11_MODULE(common, m) {
m.doc() = "Ignition Common Python Library.";

2 changes: 0 additions & 2 deletions python/src/ignition/common/console.hh
Original file line number Diff line number Diff line change
@@ -17,8 +17,6 @@

#include <pybind11/pybind11.h>

namespace py = pybind11;

namespace ignition
{
namespace common
6 changes: 2 additions & 4 deletions python/src/ignition/gazebo/_ignition_gazebo_pybind11.cc
Original file line number Diff line number Diff line change
@@ -24,14 +24,12 @@
#include "update_info.hh"
#include "world.hh"

namespace py = pybind11;

PYBIND11_MODULE(gazebo, m) {
m.doc() = "Ignition Gazebo Python Library.";

ignition::utils::python::define_destroyable(m);
ignition::gazebo::python::define_destroyable(m);

py::register_exception<ignition::utils::python::InvalidHandle>(
pybind11::register_exception<ignition::gazebo::python::InvalidHandle>(
m, "InvalidHandle", PyExc_RuntimeError);

ignition::gazebo::python::define_gazebo_entity_component_manager(m);
24 changes: 15 additions & 9 deletions python/src/ignition/gazebo/destroyable.cc
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@

namespace ignition
{
namespace utils
namespace gazebo
{
namespace python
{
@@ -43,10 +43,11 @@ Destroyable::enter()
}

void
Destroyable::exit(py::object, py::object, py::object)
Destroyable::exit(pybind11::object, pybind11::object, pybind11::object)
{
if (0u == use_count) {
throw std::runtime_error("Internal error: Destroyable use_count would be negative");
throw std::runtime_error("Internal error: "
"Destroyable use_count would be negative");
}

--use_count;
@@ -58,8 +59,10 @@ Destroyable::exit(py::object, py::object, py::object)
void
Destroyable::destroy()
{
// Normally would be pure virtual, but then pybind11 can't create bindings for this class
throw std::runtime_error("Internal error: Destroyable subclass didn't override destroy()");
// Normally would be pure virtual, but then pybind11 can't
// create bindings for this class
throw std::runtime_error("Internal error : "
"Destroyable subclass didn't override destroy()");
}

void
@@ -76,14 +79,17 @@ Destroyable::destroy_when_not_in_use()
}

void
define_destroyable(py::object module)
define_destroyable(pybind11::object module)
{
py::class_<Destroyable, std::shared_ptr<Destroyable>>(module, "Destroyable")
pybind11::class_<Destroyable, std::shared_ptr<Destroyable>>(
module, "Destroyable")
.def("__enter__", &Destroyable::enter)
.def("__exit__", &Destroyable::exit)
.def(
"destroy_when_not_in_use", &Destroyable::destroy_when_not_in_use,
"Forcefully destroy the rcl object as soon as it's not actively being used");
"destroy_when_not_in_use",
&Destroyable::destroy_when_not_in_use,
"Forcefully destroy the rcl object as soon as it's not actively "
"being used");
}
} // namespace python
} // namespace utils
12 changes: 6 additions & 6 deletions python/src/ignition/gazebo/destroyable.hh
Original file line number Diff line number Diff line change
@@ -17,11 +17,9 @@

#include <pybind11/pybind11.h>

namespace py = pybind11;

namespace ignition
{
namespace utils
namespace gazebo
{
namespace python
{
@@ -41,7 +39,9 @@ public:

/// Context manager __exit__ - unblock destruction
void
exit(py::object pytype, py::object pyvalue, py::object pytraceback);
exit(pybind11::object pytype,
pybind11::object pyvalue,
pybind11::object pytraceback);

/// Signal that the object should be destroyed as soon as it's not in use
void
@@ -60,11 +60,11 @@ private:
bool please_destroy_ = false;
};

/// Define a pybind11 wrapper for an rclpy::Destroyable
/// Define a pybind11 wrapper for an rclpybind11::Destroyable
/**
* \param[in] module a pybind11 module to add the definition to
*/
void define_destroyable(py::object module);
void define_destroyable(pybind11::object module);
} // namespace python
} // namespace ignition
} // namespace gazebo
17 changes: 10 additions & 7 deletions python/src/ignition/gazebo/entity_component_manager.cc
Original file line number Diff line number Diff line change
@@ -23,13 +23,15 @@ namespace gazebo
namespace python
{
/////////////////////////////////////////////////
EntityComponentManager::EntityComponentManager(const ignition::gazebo::EntityComponentManager &_ecm)
EntityComponentManager::EntityComponentManager(
const ignition::gazebo::EntityComponentManager &_ecm)
{
_entity_component_manager = &_ecm;
}

/////////////////////////////////////////////////
EntityComponentManager::EntityComponentManager(ignition::gazebo::EntityComponentManager &_ecm)
EntityComponentManager::EntityComponentManager(
ignition::gazebo::EntityComponentManager &_ecm)
{
_entity_component_manager_no_const = &_ecm;
}
@@ -45,12 +47,13 @@ void EntityComponentManager::destroy()
}

/////////////////////////////////////////////////
void define_gazebo_entity_component_manager(py::object module)
void define_gazebo_entity_component_manager(pybind11::object module)
{
py::class_<ignition::gazebo::python::EntityComponentManager,
ignition::utils::python::Destroyable,
std::shared_ptr<ignition::gazebo::python::EntityComponentManager>>(module, "EntityComponentManager")
.def(py::init<const ignition::gazebo::EntityComponentManager &>());
pybind11::class_<ignition::gazebo::python::EntityComponentManager,
ignition::gazebo::python::Destroyable,
std::shared_ptr<ignition::gazebo::python::EntityComponentManager>>(
module, "EntityComponentManager")
.def(pybind11::init<const ignition::gazebo::EntityComponentManager &>());
}
} // namespace python
} // namespace gazebo
24 changes: 13 additions & 11 deletions python/src/ignition/gazebo/entity_component_manager.hh
Original file line number Diff line number Diff line change
@@ -12,32 +12,33 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef IGNITION_GAZEBO_PYTHON__ENTITY_COMPONENT_MANAGER_HPP_
#define IGNITION_GAZEBO_PYTHON__ENTITY_COMPONENT_MANAGER_HPP_
#ifndef IGNITION_GAZEBO_PYTHON__ENTITY_COMPONENT_MANAGER_HH_
#define IGNITION_GAZEBO_PYTHON__ENTITY_COMPONENT_MANAGER_HH_

#include <pybind11/pybind11.h>

#include "ignition/gazebo/EntityComponentManager.hh"

#include "destroyable.hh"

namespace py = pybind11;

namespace ignition
{
namespace gazebo
{
namespace python
{

class EntityComponentManager : public ignition::utils::python::Destroyable,
public std::enable_shared_from_this<EntityComponentManager>
class EntityComponentManager :
public ignition::gazebo::python::Destroyable,
public std::enable_shared_from_this<EntityComponentManager>
{
/// \brief Constructor
public: EntityComponentManager(const ignition::gazebo::EntityComponentManager &_ecm);
public: EntityComponentManager(
const ignition::gazebo::EntityComponentManager &_ecm);

/// \brief Constructor
public: EntityComponentManager(ignition::gazebo::EntityComponentManager &_ecm);
public: EntityComponentManager(
ignition::gazebo::EntityComponentManager &_ecm);

/// \brief Destructor
public: ~EntityComponentManager();
@@ -55,18 +56,19 @@ namespace python

private:
const ignition::gazebo::EntityComponentManager * _entity_component_manager;
ignition::gazebo::EntityComponentManager * _entity_component_manager_no_const;
ignition::gazebo::EntityComponentManager *
_entity_component_manager_no_const;
};

/// Define a pybind11 wrapper for an ignition::gazebo::EntityComponentManager
/**
* \param[in] module a pybind11 module to add the definition to
*/
void
define_gazebo_entity_component_manager(py::object module);
define_gazebo_entity_component_manager(pybind11::object module);

} // namespace python
} // namespace gazebo
} // namespace ignition

#endif // IGNITION_GAZEBO_PYTHON__ENTITY_COMPONENT_MANAGER_HPP_
#endif // IGNITION_GAZEBO_PYTHON__ENTITY_COMPONENT_MANAGER_HH_
6 changes: 3 additions & 3 deletions python/src/ignition/gazebo/event_manager.cc
Original file line number Diff line number Diff line change
@@ -25,10 +25,10 @@ namespace gazebo
namespace python
{
/////////////////////////////////////////////////
void define_gazebo_event_manager(py::object module)
void define_gazebo_event_manager(pybind11::object module)
{
py::class_<ignition::gazebo::EventManager>(module, "EventManager")
.def(py::init<>());
pybind11::class_<ignition::gazebo::EventManager>(module, "EventManager")
.def(pybind11::init<>());
}
} // namespace python
} // namespace gazebo
4 changes: 1 addition & 3 deletions python/src/ignition/gazebo/event_manager.hh
Original file line number Diff line number Diff line change
@@ -17,8 +17,6 @@

#include <pybind11/pybind11.h>

namespace py = pybind11;

namespace ignition
{
namespace gazebo
@@ -30,7 +28,7 @@ namespace python
* \param[in] module a pybind11 module to add the definition to
*/
void
define_gazebo_event_manager(py::object module);
define_gazebo_event_manager(pybind11::object module);

} // namespace python
} // namespace gazebo
2 changes: 1 addition & 1 deletion python/src/ignition/gazebo/exceptions.hh
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@

namespace ignition
{
namespace utils
namespace gazebo
{
namespace python
{
18 changes: 10 additions & 8 deletions python/src/ignition/gazebo/helper_system.cc
Original file line number Diff line number Diff line change
@@ -66,7 +66,8 @@ void HelperSystem::PostUpdate(const UpdateInfo &_info,
const ignition::gazebo::EntityComponentManager &_ecm)
{
if (this->postUpdateCallback_internal)
this->postUpdateCallback_internal(_info, ignition::gazebo::python::EntityComponentManager(_ecm));
this->postUpdateCallback_internal(_info,
ignition::gazebo::python::EntityComponentManager(_ecm));
}

//////////////////////////////////////////////////
@@ -149,7 +150,7 @@ HelperFixture &HelperFixture::OnConfigure(std::function<void(

//////////////////////////////////////////////////
HelperFixture &HelperFixture::OnPreUpdate(std::function<void(
const UpdateInfo &, ignition::gazebo::python::EntityComponentManager &)> _cb)
const UpdateInfo &, ignition::gazebo::python::EntityComponentManager &)> _cb)
{
if (nullptr != this->dataPtr->helperSystem)
this->dataPtr->helperSystem->preUpdateCallback_internal = std::move(_cb);
@@ -158,7 +159,7 @@ HelperFixture &HelperFixture::OnPreUpdate(std::function<void(

//////////////////////////////////////////////////
HelperFixture &HelperFixture::OnUpdate(std::function<void(
const UpdateInfo &, ignition::gazebo::python::EntityComponentManager &)> _cb)
const UpdateInfo &, ignition::gazebo::python::EntityComponentManager &)> _cb)
{
if (nullptr != this->dataPtr->helperSystem)
this->dataPtr->helperSystem->updateCallback_internal = std::move(_cb);
@@ -167,7 +168,8 @@ HelperFixture &HelperFixture::OnUpdate(std::function<void(

//////////////////////////////////////////////////
HelperFixture &HelperFixture::OnPostUpdate(std::function<void(
const UpdateInfo &, const ignition::gazebo::python::EntityComponentManager &)> _cb)
const UpdateInfo &,
const ignition::gazebo::python::EntityComponentManager &)> _cb)
{
if (nullptr != this->dataPtr->helperSystem)
this->dataPtr->helperSystem->postUpdateCallback_internal = std::move(_cb);
@@ -181,12 +183,12 @@ std::shared_ptr<gazebo::Server> HelperFixture::Server() const
}

void
define_gazebo_helper_fixture(py::object module)
define_gazebo_helper_fixture(pybind11::object module)
{
py::class_<HelperFixture,
ignition::utils::python::Destroyable,
pybind11::class_<HelperFixture,
ignition::gazebo::python::Destroyable,
std::shared_ptr<HelperFixture>>(module, "HelperFixture")
.def(py::init<const std::string &>())
.def(pybind11::init<const std::string &>())
.def(
"server", &HelperFixture::Server,
"Get pointer to underlying server."
Loading