Gazebo Sim

API Reference

8.7.0
PythonSystemLoader.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef GZ_SIM_SYSTEMS_PYTHONSYSTEMLOADER_HH_
19 #define GZ_SIM_SYSTEMS_PYTHONSYSTEMLOADER_HH_
20 
21 #include <pybind11/embed.h>
22 
23 #include <memory>
24 #include <sdf/Element.hh>
25 
27 #include "gz/sim/EventManager.hh"
28 #include "gz/sim/System.hh"
29 #include "gz/sim/config.hh"
30 #include "gz/sim/python-system-loader-system/Export.hh"
31 
32 namespace gz
33 {
34 namespace sim
35 {
36 // Inline bracket to help doxygen filtering.
37 inline namespace GZ_SIM_VERSION_NAMESPACE {
38 namespace systems
39 {
67 // TODO(azeey) Add ParameterConfigure
68 class GZ_SIM_PYTHON_SYSTEM_LOADER_SYSTEM_HIDDEN PythonSystemLoader final
69  : public System,
70  public ISystemConfigure,
71  public ISystemPreUpdate,
72  public ISystemUpdate,
73  public ISystemPostUpdate,
74  public ISystemReset
75 {
76  public: ~PythonSystemLoader() final;
77  // Documentation inherited
78  public: void Configure(const Entity &_entity,
79  const std::shared_ptr<const sdf::Element> &_sdf,
81  EventManager &_eventMgr) final;
82 
83  // Documentation inherited
84  public: void PreUpdate(const UpdateInfo &_info,
85  EntityComponentManager &_ecm) final;
86 
87  // Documentation inherited
88  public: void Update(const UpdateInfo &_info,
89  EntityComponentManager &_ecm) final;
90 
91  // Documentation inherited
92  public: void PostUpdate(const UpdateInfo &_info,
93  const EntityComponentManager &_ecm) final;
94 
95  // Documentation inherited
96  public: void Reset(const UpdateInfo &_info,
97  EntityComponentManager &_ecm) final;
98 
101  private: template <typename ...Args>
102  void CallPythonMethod(pybind11::object _method, Args&&...);
103 
108  private: bool validConfig{false};
110  private: pybind11::module_ pythonModule;
112  private: pybind11::object pythonSystem;
114  private: pybind11::object preUpdateMethod;
116  private: pybind11::object updateMethod;
118  private: pybind11::object postUpdateMethod;
120  private: pybind11::object resetMethod;
121 };
122 } // namespace systems
123 } // namespace GZ_SIM_VERSION_NAMESPACE
124 } // namespace sim
125 } // namespace gz
126 
127 #endif /* end of include guard: GZ_SIM_SYSTEMS_PYTHONSYSTEMLOADER_HH_ */