Skip to content

Commit

Permalink
node constructors fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mgonzs13 committed Aug 8, 2023
1 parent a90cbd1 commit 7eb306a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
15 changes: 9 additions & 6 deletions simple_node/include/simple_node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ namespace simple_node {
class Node : public rclcpp::Node {

public:
Node(std::string name);
Node(std::string name, rclcpp::Executor *executor);
Node(std::string name, std::string _namespace);
Node(std::string name, std::string _namespace, rclcpp::Executor *executor);
Node(std::string name, std::string _namespace, const rclcpp::NodeOptions &options = rclcpp::NodeOptions());
Node(const std::string &name,
const rclcpp::NodeOptions &options = rclcpp::NodeOptions(),
rclcpp::Executor::SharedPtr executor =
std::make_shared<rclcpp::executors::MultiThreadedExecutor>());
Node(const std::string &name, const std::string &namespace_,
const rclcpp::NodeOptions &options = rclcpp::NodeOptions(),
rclcpp::Executor::SharedPtr executor =
std::make_shared<rclcpp::executors::MultiThreadedExecutor>());
~Node();

void join_spin();
Expand Down Expand Up @@ -119,7 +122,7 @@ class Node : public rclcpp::Node {

private:
rclcpp::CallbackGroup::SharedPtr group;
rclcpp::Executor *executor;
rclcpp::Executor::SharedPtr executor;
std::thread *spin_thread;

void run_executor();
Expand Down
58 changes: 32 additions & 26 deletions simple_node/simple_node/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

import time
from threading import Thread
from typing import Callable, Type
from typing import List, Callable, Type

import rclpy
from rclpy.node import Node as Node2
from rclpy.executors import MultiThreadedExecutor, Executor
from rclpy.client import Client
from rclpy.context import Context
from rclpy.node import Node as Node2
from rclpy.parameter import Parameter
from rclpy.callback_groups import ReentrantCallbackGroup
from rclpy.executors import MultiThreadedExecutor, Executor

from simple_node.actions.action_client import ActionClient
from simple_node.actions.action_server import ActionServer
Expand All @@ -34,29 +36,33 @@
class Node(Node2):
""" Node Class """

def __init__(self, node_name: str,
context = None,
cli_args = None,
namespace = "",
use_global_arguments = True,
enable_rosout = True,
start_parameter_services = True,
parameter_overrides = None,
allow_undeclared_parameters = False,
automatically_declare_parameters_from_overrides = False,
executor = None):

super().__init__(node_name,
context = context,
cli_args = cli_args,
namespace = namespace,
use_global_arguments = use_global_arguments,
enable_rosout=enable_rosout,
start_parameter_services=start_parameter_services,
parameter_overrides=parameter_overrides,
allow_undeclared_parameters=allow_undeclared_parameters,
automatically_declare_parameters_from_overrides=automatically_declare_parameters_from_overrides
)
def __init__(
self,
node_name: str,
context: Context = None,
cli_args: List[str] = None,
namespace: str = "",
use_global_arguments: bool = True,
enable_rosout: bool = True,
start_parameter_services: bool = True,
parameter_overrides: List[Parameter] = None,
allow_undeclared_parameters: bool = False,
automatically_declare_parameters_from_overrides: bool = False,
executor: Executor = None
) -> None:

super().__init__(
node_name,
context=context,
cli_args=cli_args,
namespace=namespace,
use_global_arguments=use_global_arguments,
enable_rosout=enable_rosout,
start_parameter_services=start_parameter_services,
parameter_overrides=parameter_overrides,
allow_undeclared_parameters=allow_undeclared_parameters,
automatically_declare_parameters_from_overrides=automatically_declare_parameters_from_overrides
)

if not executor:
self._executor = MultiThreadedExecutor()
Expand Down
25 changes: 8 additions & 17 deletions simple_node/src/simple_node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,22 @@

using namespace simple_node;

Node::Node(std::string name)
: Node(name, "", new rclcpp::executors::MultiThreadedExecutor()) {}
Node::Node(const std::string &name, const rclcpp::NodeOptions &options,
const rclcpp::Executor::SharedPtr executor)
: Node(name, "", options, executor) {}

Node::Node(std::string name, std::string _namespace)
: Node(name, _namespace, new rclcpp::executors::MultiThreadedExecutor()) {}

Node::Node(std::string name, rclcpp::Executor *executor)
: Node(name, "", executor) {}

Node::Node(std::string name, std::string _namespace, rclcpp::Executor *executor)
: rclcpp::Node(name, _namespace) {
Node::Node(const std::string &name, const std::string &namespace_,
const rclcpp::NodeOptions &options,
rclcpp::Executor::SharedPtr executor)
: rclcpp::Node(name, namespace_, options), executor(executor) {

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

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

Node::~Node() {
delete this->executor;
delete this->spin_thread;
}
Node::~Node() { delete this->spin_thread; }

void Node::join_spin() {
this->spin_thread->join();
Expand Down

0 comments on commit 7eb306a

Please sign in to comment.