-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpyRosInit.cpp
More file actions
63 lines (46 loc) · 1.33 KB
/
pyRosInit.cpp
File metadata and controls
63 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <rclcpp/rclcpp.hpp>
#include <list>
bool init(std::string name, std::list<std::string> args)
{
if(rclcpp::ok())
{
//ROS_ERROR("Ros node already initialized with name %s",
// ros::this_node::getName().c_str());
RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "Ros node already initialized");
return false;
}
std::vector<const char *> args_vec;
for(auto& a : args)
{
args_vec.push_back(a.c_str());
}
int argc = args_vec.size();
char ** argv = (char **)args_vec.data();
name += "_cpp";
rclcpp::init(argc, argv);
auto node = rclcpp::Node::make_shared(name);
RCLCPP_INFO(node->get_logger(),
"Initialized roscpp under namespace %s with name %s",
node->get_namespace(),
node->get_name()
);
return true;
}
bool shutdown()
{
if(rclcpp::ok())
{
RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Shutting down ros node");
rclcpp::shutdown();
return true;
}
std::cerr << "Ros node not running" << std::endl;
return false;
}
namespace py = pybind11;
PYBIND11_MODULE(roscpp_utils, m) {
m.def("init", init);
m.def("shutdown", shutdown);
}