Skip to content

Commit 7eb306a

Browse files
committed
node constructors fixed
1 parent a90cbd1 commit 7eb306a

File tree

3 files changed

+49
-49
lines changed

3 files changed

+49
-49
lines changed

simple_node/include/simple_node/node.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ namespace simple_node {
3434
class Node : public rclcpp::Node {
3535

3636
public:
37-
Node(std::string name);
38-
Node(std::string name, rclcpp::Executor *executor);
39-
Node(std::string name, std::string _namespace);
40-
Node(std::string name, std::string _namespace, rclcpp::Executor *executor);
41-
Node(std::string name, std::string _namespace, const rclcpp::NodeOptions &options = rclcpp::NodeOptions());
37+
Node(const std::string &name,
38+
const rclcpp::NodeOptions &options = rclcpp::NodeOptions(),
39+
rclcpp::Executor::SharedPtr executor =
40+
std::make_shared<rclcpp::executors::MultiThreadedExecutor>());
41+
Node(const std::string &name, const std::string &namespace_,
42+
const rclcpp::NodeOptions &options = rclcpp::NodeOptions(),
43+
rclcpp::Executor::SharedPtr executor =
44+
std::make_shared<rclcpp::executors::MultiThreadedExecutor>());
4245
~Node();
4346

4447
void join_spin();
@@ -119,7 +122,7 @@ class Node : public rclcpp::Node {
119122

120123
private:
121124
rclcpp::CallbackGroup::SharedPtr group;
122-
rclcpp::Executor *executor;
125+
rclcpp::Executor::SharedPtr executor;
123126
std::thread *spin_thread;
124127

125128
void run_executor();

simple_node/simple_node/node.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919

2020
import time
2121
from threading import Thread
22-
from typing import Callable, Type
22+
from typing import List, Callable, Type
2323

2424
import rclpy
25-
from rclpy.node import Node as Node2
26-
from rclpy.executors import MultiThreadedExecutor, Executor
2725
from rclpy.client import Client
26+
from rclpy.context import Context
27+
from rclpy.node import Node as Node2
28+
from rclpy.parameter import Parameter
2829
from rclpy.callback_groups import ReentrantCallbackGroup
30+
from rclpy.executors import MultiThreadedExecutor, Executor
2931

3032
from simple_node.actions.action_client import ActionClient
3133
from simple_node.actions.action_server import ActionServer
@@ -34,29 +36,33 @@
3436
class Node(Node2):
3537
""" Node Class """
3638

37-
def __init__(self, node_name: str,
38-
context = None,
39-
cli_args = None,
40-
namespace = "",
41-
use_global_arguments = True,
42-
enable_rosout = True,
43-
start_parameter_services = True,
44-
parameter_overrides = None,
45-
allow_undeclared_parameters = False,
46-
automatically_declare_parameters_from_overrides = False,
47-
executor = None):
48-
49-
super().__init__(node_name,
50-
context = context,
51-
cli_args = cli_args,
52-
namespace = namespace,
53-
use_global_arguments = use_global_arguments,
54-
enable_rosout=enable_rosout,
55-
start_parameter_services=start_parameter_services,
56-
parameter_overrides=parameter_overrides,
57-
allow_undeclared_parameters=allow_undeclared_parameters,
58-
automatically_declare_parameters_from_overrides=automatically_declare_parameters_from_overrides
59-
)
39+
def __init__(
40+
self,
41+
node_name: str,
42+
context: Context = None,
43+
cli_args: List[str] = None,
44+
namespace: str = "",
45+
use_global_arguments: bool = True,
46+
enable_rosout: bool = True,
47+
start_parameter_services: bool = True,
48+
parameter_overrides: List[Parameter] = None,
49+
allow_undeclared_parameters: bool = False,
50+
automatically_declare_parameters_from_overrides: bool = False,
51+
executor: Executor = None
52+
) -> None:
53+
54+
super().__init__(
55+
node_name,
56+
context=context,
57+
cli_args=cli_args,
58+
namespace=namespace,
59+
use_global_arguments=use_global_arguments,
60+
enable_rosout=enable_rosout,
61+
start_parameter_services=start_parameter_services,
62+
parameter_overrides=parameter_overrides,
63+
allow_undeclared_parameters=allow_undeclared_parameters,
64+
automatically_declare_parameters_from_overrides=automatically_declare_parameters_from_overrides
65+
)
6066

6167
if not executor:
6268
self._executor = MultiThreadedExecutor()

simple_node/src/simple_node/node.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,22 @@
1717

1818
using namespace simple_node;
1919

20-
Node::Node(std::string name)
21-
: Node(name, "", new rclcpp::executors::MultiThreadedExecutor()) {}
20+
Node::Node(const std::string &name, const rclcpp::NodeOptions &options,
21+
const rclcpp::Executor::SharedPtr executor)
22+
: Node(name, "", options, executor) {}
2223

23-
Node::Node(std::string name, std::string _namespace)
24-
: Node(name, _namespace, new rclcpp::executors::MultiThreadedExecutor()) {}
25-
26-
Node::Node(std::string name, rclcpp::Executor *executor)
27-
: Node(name, "", executor) {}
28-
29-
Node::Node(std::string name, std::string _namespace, rclcpp::Executor *executor)
30-
: rclcpp::Node(name, _namespace) {
24+
Node::Node(const std::string &name, const std::string &namespace_,
25+
const rclcpp::NodeOptions &options,
26+
rclcpp::Executor::SharedPtr executor)
27+
: rclcpp::Node(name, namespace_, options), executor(executor) {
3128

3229
rclcpp::CallbackGroup::SharedPtr group =
3330
this->create_callback_group(rclcpp::CallbackGroupType::Reentrant);
3431

35-
this->executor = executor;
3632
this->spin_thread = new std::thread(&Node::run_executor, this);
3733
}
38-
Node::Node(std::string name, std::string _namespace, const rclcpp::NodeOptions &options):
39-
rclcpp::Node(name, _namespace, options) {}
4034

41-
Node::~Node() {
42-
delete this->executor;
43-
delete this->spin_thread;
44-
}
35+
Node::~Node() { delete this->spin_thread; }
4536

4637
void Node::join_spin() {
4738
this->spin_thread->join();

0 commit comments

Comments
 (0)