Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into python_systems
Browse files Browse the repository at this point in the history
  • Loading branch information
azeey committed Aug 24, 2023
2 parents c3417d5 + 6dd0984 commit e0404df
Show file tree
Hide file tree
Showing 11 changed files with 456 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/gz/sim/Actor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace gz
/// Manually setting the trajectory pose will override the scripted
/// trajectory specified in SDF.
/// \param[in] _ecm Entity Component manager.
/// \param[in] _name Trajectory pose w.r.t. to the trajectory origin
/// \param[in] _pose Trajectory pose w.r.t. to the trajectory origin
/// \sa Pose
public: void SetTrajectoryPose(EntityComponentManager &_ecm,
const math::Pose3d &_pose);
Expand Down
4 changes: 4 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ endfunction()
set(BINDINGS_MODULE_NAME "sim${PROJECT_VERSION_MAJOR}")
pybind11_add_module(${BINDINGS_MODULE_NAME} MODULE
src/gz/sim/_gz_sim_pybind11.cc
src/gz/sim/Actor.cc
src/gz/sim/EntityComponentManager.cc
src/gz/sim/EventManager.cc
src/gz/sim/Joint.cc
src/gz/sim/Link.cc
src/gz/sim/Model.cc
src/gz/sim/TestFixture.cc
src/gz/sim/Sensor.cc
src/gz/sim/Server.cc
src/gz/sim/ServerConfig.cc
src/gz/sim/UpdateInfo.cc
Expand Down Expand Up @@ -80,9 +82,11 @@ configure_build_install_location(common)

if (BUILD_TESTING)
set(python_tests
actor_TEST
joint_TEST
link_TEST
model_TEST
sensor_TEST
testFixture_TEST
world_TEST
)
Expand Down
105 changes: 105 additions & 0 deletions python/src/gz/sim/Actor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (C) 2023 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.
*/

#include <pybind11/chrono.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <cstdint>

#include "Actor.hh"

namespace py = pybind11;

namespace gz
{
namespace sim
{
namespace python
{
void defineSimActor(py::object module)
{
py::class_<gz::sim::Actor>(module, "Actor")
.def(py::init<gz::sim::Entity>())
.def(py::init<gz::sim::Actor>())
.def("entity", &gz::sim::Actor::Entity,
"Get the entity which this actor is related to.")
.def("reset_entity", &gz::sim::Actor::ResetEntity,
"Reset Entity to a new one.")
.def("valid", &gz::sim::Actor::Valid,
py::arg("ecm"),
"Check whether this actor correctly refers to an entity that "
"has a components::Actor.")
.def("name", &gz::sim::Actor::Name,
py::arg("ecm"),
"Get the actor's unscoped name.")
.def("pose", &gz::sim::Actor::Pose,
py::arg("ecm"),
"Get the pose of the actor."
"If the actor has a trajectory, this will only return the origin "
"pose of the trajectory and not the actual world pose of the actor.")
.def("trajectory_pose", &gz::sim::Actor::TrajectoryPose,
py::arg("ecm"),
"Get the trajectory pose of the actor. There are two "
"ways that the actor can follow a trajectory: 1) SDF script, "
"2) manually setting trajectory pose. This function retrieves 2) the "
"manual trajectory pose set by the user. The Trajectory pose is "
"given relative to the trajectory pose origin returned by Pose().")
.def("set_trajectory_pose", &gz::sim::Actor::SetTrajectoryPose,
py::arg("ecm"),
py::arg("pose"),
"Set the trajectory pose of the actor. There are two "
"ways that the actor can follow a trajectory: 1) SDF script, "
"2) manually setting trajectory pose. This function enables option 2). "
"Manually setting the trajectory pose will override the scripted "
"trajectory specified in SDF.")
.def("world_pose", &gz::sim::Actor::WorldPose,
py::arg("ecm"),
"Get the world pose of the actor."
"This returns the current world pose of the actor computed by gazebo."
"The world pose is the combination of the actor's pose and its "
"trajectory pose. The currently trajectory pose is either manually set "
"via set_trajectory_pose or interpolated from waypoints in the SDF "
"script based on the current time.")
.def("set_animation_name", &gz::sim::Actor::SetAnimationName,
py::arg("ecm"),
py::arg("name"),
"Set the name of animation to use for this actor.")
.def("set_animation_time", &gz::sim::Actor::SetAnimationTime,
py::arg("ecm"),
py::arg("time"),
"Set the time of animation to use for this actor (the time argument "
"is expected in ms).")
.def("animation_name", &gz::sim::Actor::AnimationName,
py::arg("ecm"),
"Get the name of animation used by the actor.")
.def("animation_time", &gz::sim::Actor::AnimationTime,
py::arg("ecm"),
"Get the time of animation for this actor.")
.def("__copy__",
[](const gz::sim::Actor &self)
{
return gz::sim::Actor(self);
})
.def("__deepcopy__",
[](const gz::sim::Actor &self, pybind11::dict)
{
return gz::sim::Actor(self);
});
}
} // namespace python
} // namespace sim
} // namespace gz
40 changes: 40 additions & 0 deletions python/src/gz/sim/Actor.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2023 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.
*/

#ifndef GZ_SIM_PYTHON__ACTOR_HH_
#define GZ_SIM_PYTHON__ACTOR_HH_

#include <pybind11/pybind11.h>

#include <gz/sim/Actor.hh>

namespace gz
{
namespace sim
{
namespace python
{
/// Define a pybind11 wrapper for a gz::sim::Actor
/**
* \param[in] module a pybind11 module to add the definition to
*/
void
defineSimActor(pybind11::object module);
} // namespace python
} // namespace sim
} // namespace gz

#endif // GZ_SIM_PYTHON__ACTOR_HH_
71 changes: 71 additions & 0 deletions python/src/gz/sim/Sensor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2023 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.
*/


#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "Sensor.hh"

namespace py = pybind11;

namespace gz
{
namespace sim
{
namespace python
{
void defineSimSensor(py::object module)
{
py::class_<gz::sim::Sensor>(module, "Sensor")
.def(py::init<gz::sim::Entity>())
.def(py::init<gz::sim::Sensor>())
.def("entity", &gz::sim::Sensor::Entity,
"Get the entity which this sensor is related to.")
.def("reset_entity", &gz::sim::Sensor::ResetEntity,
"Reset Entity to a new one.")
.def("valid", &gz::sim::Sensor::Valid,
py::arg("ecm"),
"Check whether this sensor correctly refers to an entity that"
"has a components::Sensor.")
.def("name", &gz::sim::Sensor::Name,
py::arg("ecm"),
"Get the sensor's unscoped name.")
.def("pose", &gz::sim::Sensor::Pose,
py::arg("ecm"),
"Get the pose of the sensor. "
"If the sensor has a trajectory, this will only return the origin"
"pose of the trajectory and not the actual world pose of the sensor.")
.def("topic", &gz::sim::Sensor::Topic,
py::arg("ecm"),
"Get the topic of the sensor.")
.def("parent", &gz::sim::Sensor::Parent,
py::arg("ecm"),
"Get the parent entity. This can be a link or a joint.")
.def("__copy__",
[](const gz::sim::Sensor &self)
{
return gz::sim::Sensor(self);
})
.def("__deepcopy__",
[](const gz::sim::Sensor &self, pybind11::dict)
{
return gz::sim::Sensor(self);
});
}
} // namespace python
} // namespace sim
} // namespace gz
40 changes: 40 additions & 0 deletions python/src/gz/sim/Sensor.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2023 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.
*/

#ifndef GZ_SIM_PYTHON__SENSOR_HH_
#define GZ_SIM_PYTHON__SENSOR_HH_

#include <pybind11/pybind11.h>

#include <gz/sim/Sensor.hh>

namespace gz
{
namespace sim
{
namespace python
{
/// Define a pybind11 wrapper for a gz::sim::Sensor
/**
* \param[in] module a pybind11 module to add the definition to
*/
void
defineSimSensor(pybind11::object module);
} // namespace python
} // namespace sim
} // namespace gz

#endif // GZ_SIM_PYTHON__SENSOR_HH_
4 changes: 4 additions & 0 deletions python/src/gz/sim/_gz_sim_pybind11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

#include "gz/sim/Entity.hh"

#include "Actor.hh"
#include "EntityComponentManager.hh"
#include "EventManager.hh"
#include "Joint.hh"
#include "Link.hh"
#include "Model.hh"
#include "Sensor.hh"
#include "Server.hh"
#include "ServerConfig.hh"
#include "TestFixture.hh"
Expand All @@ -33,11 +35,13 @@
PYBIND11_MODULE(BINDINGS_MODULE_NAME, m) {
m.doc() = "Gazebo Sim Python Library.";
m.attr("K_NULL_ENTITY") = gz::sim::kNullEntity;
gz::sim::python::defineSimActor(m);
gz::sim::python::defineSimEntityComponentManager(m);
gz::sim::python::defineSimEventManager(m);
gz::sim::python::defineSimJoint(m);
gz::sim::python::defineSimLink(m);
gz::sim::python::defineSimModel(m);
gz::sim::python::defineSimSensor(m);
gz::sim::python::defineSimServer(m);
gz::sim::python::defineSimServerConfig(m);
gz::sim::python::defineSimTestFixture(m);
Expand Down
Loading

0 comments on commit e0404df

Please sign in to comment.