Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b8cac6

Browse files
author
Davide Faconti
committed
WIP
1 parent f3fb4cc commit 5b8cac6

File tree

5 files changed

+68
-46
lines changed

5 files changed

+68
-46
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ set(BT_Source
7272
src/loggers/bt_file_logger.cpp
7373
src/loggers/bt_minitrace_logger.cpp
7474

75-
src/pythonnode.cpp
76-
7775
3rdparty/tinyXML2/tinyxml2.cpp
7876
3rdparty/minitrace/minitrace.cpp
7977
)
@@ -112,6 +110,13 @@ add_subdirectory(tools)
112110
add_subdirectory(sample_nodes)
113111
add_subdirectory(examples)
114112

113+
add_executable(py_test
114+
python/py_main.cpp
115+
python/python_node.cpp
116+
)
117+
118+
target_link_libraries(py_test ${BEHAVIOR_TREE_LIBRARIES} )
119+
115120
######################################################
116121
# TESTS
117122
######################################################

python/py_main.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "python_node.h"
2+
3+
const std::string script_text = R"(
4+
5+
# define Action HelloPythonAction
6+
import BehaviorTree as BT
7+
8+
class HelloPythonAction:
9+
10+
def __init__(self, name):
11+
self.name = name
12+
13+
def tick(self):
14+
print("tick called.")
15+
return BT.NodeStatus.SUCCESS
16+
17+
def halt(self):
18+
print("halt called.")
19+
20+
def requiredNodeParameters():
21+
return [( "paramA", "1" ), ( "paramB", "2" )]
22+
23+
myAction = HelloPythonAction("myAction")
24+
print(myAction.tick())
25+
26+
)";
27+
28+
int main()
29+
{
30+
py::scoped_interpreter guard{};
31+
32+
py::exec( script_text );
33+
34+
return 0;
35+
}
Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
#ifndef PYTHONNODE_H
2-
#define PYTHONNODE_H
1+
#include "python_node.h"
32

4-
#include <pybind11/embed.h>
5-
#include <pybind11/stl.h>
6-
#include <pybind11/stl_bind.h>
7-
#include <pybind11/pybind11.h>
8-
#include <behavior_tree_core/action_node.h>
9-
10-
11-
namespace py = pybind11;
12-
using BT::NodeParameters;
13-
using BT::NodeStatus;
14-
// clang-format off
15-
16-
17-
18-
PYBIND11_MODULE(BehaviorTreePython, m)
3+
PYBIND11_EMBEDDED_MODULE(BehaviorTree, m)
194
{
20-
py::enum_<NodeStatus>(m, "ScopedEnum", py::arithmetic())
5+
py::enum_<NodeStatus>(m, "NodeStatus", py::arithmetic())
216
.value("SUCCESS", NodeStatus::SUCCESS)
227
.value("FAILURE", NodeStatus::FAILURE)
238
.value("RUNNING", NodeStatus::RUNNING)
@@ -49,27 +34,3 @@ PYBIND11_MODULE(BehaviorTreePython, m)
4934
//------------------------------------------
5035
}
5136

52-
const std::string xml_text = R"(
53-
54-
# define Action HelloPythonAction
55-
56-
class HelloPythonAction(ActionNode):
57-
58-
def __init__(self, name, params):
59-
ActionNode.__init__(self,name, params)
60-
61-
def tick(self):
62-
print("tick called.")
63-
return NodeStatus.SUCCESS;
64-
65-
def halt(self):
66-
print("halt called.")
67-
68-
def requiredNodeParameters()
69-
return [("paramA", "1"), ("paramB", "2")]
70-
)";
71-
72-
// clang-format on
73-
74-
75-
#endif // PYTHONNODE_H

python/python_node.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef PYTHONNODE_H
2+
#define PYTHONNODE_H
3+
4+
#include <pybind11/embed.h>
5+
#include <pybind11/stl.h>
6+
#include <pybind11/stl_bind.h>
7+
#include <pybind11/pybind11.h>
8+
#include <behavior_tree_core/action_node.h>
9+
10+
11+
namespace py = pybind11;
12+
using BT::NodeParameters;
13+
using BT::NodeStatus;
14+
// clang-format off
15+
16+
17+
18+
19+
20+
// clang-format on
21+
22+
23+
#endif // PYTHONNODE_H

src/pythonnode.cpp

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)