Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 92

runtime error after trying to set parameters in ROS2

$
0
0
When I try to set parameters, I'm getting the following error: `terminate called after throwing an instance of 'std::runtime_error'` `what(): Node has already been added to an executor.` I was able to get around this problem by creating another node within my constructor. I'm wondering if there is a better way to get around this problem. Please look at the code snippet below. Thanks. main.cpp int main(int argc, char **argv) { rclcpp::init(argc, argv); rclcpp::spin(std::make_shared()); rclcpp::shutdown(); return 0; } test_parameter.hpp class TestParameter : public rclcpp::Node { public: TestParameter(); ~TestParameter(); void subCB(); void saveParamToServer(); private: rclcpp::SyncParametersClient::SharedPtr parameters_client_; rclcpp::Subscription::ConstSharedPtr test_sub_; }; test_parameter.cpp TestParameter::TestParameter() : Node("TestParameter") { parameters_client_ = std::make_shared(std::shared_ptr(this)); test_sub_ = this->create_subscription( "testsub", std::bind(&TestParameter::initialPoseReceived, this, std::placeholders::_1)); } TestParameter::~TestParameter() { } void TestParameter::subCB() { this->saveParamToServer(); } void TestParameter::saveParamToServer() { parameters_client_->set_parameters({ rclcpp::Parameter("x", 0), rclcpp::Parameter("y", 0), }); } To fix this issue, I created another node for parameters within my constructor. test_node = rclcpp::Node::make_shared("TestNode"); parameters_client_ = std::make_shared(std::shared_ptr(test_node));

Viewing all articles
Browse latest Browse all 92

Trending Articles


FLASHBACK WITH SIRASA FM AT GALGAMUWA 2022


Mp3 Download: Mdu - Mazola


Imitation gun was fired at motorist in Leicester road-rage incident


Ndebele names


MCKINNEY EMALINE “EMMA” OF WES...


Okra & Motia — The Workshop (Prod by Hammer)


Skint TV teen to be sentenced


Moondru Mudichu 19-09-2017 – Polimer tv Serial


YOSVANI JAMES Arrested by Miami-Dade County Corrections on Jan 10, 2017


Stories • Goddess Stepmom



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>