This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ================================================================== | |
// program : param.cpp | |
// author: Ar-Ray (https://github.com/Ar-Ray-code) | |
// Date: 2021-08-15 | |
// License: Apache License 2.0 | |
// ================================================================== | |
#include <rclcpp/rclcpp.hpp> | |
#include <std_msgs/msg/int32.hpp> | |
class param_example:public rclcpp::Node | |
{ | |
private: | |
rclcpp::Subscription<std_msgs::msg::Int32>::SharedPtr sub; | |
int number0, number1, number2, number3; | |
void show_log() | |
{ | |
RCLCPP_INFO(this->get_logger(),"get parameter\nnumber0:%3d\nnumber1:%3d\nnumber2:%3d\nnumber3:%3d\n", number0, number1, number2, number3); | |
RCLCPP_INFO(this->get_logger(),"end"); | |
} | |
public: | |
param_example(const std::string name, const rclcpp::NodeOptions & options):Node(name, options) | |
{ | |
this->declare_parameter("param0", -1); | |
this->declare_parameter("param1", -1); | |
this->declare_parameter("param2", -1); | |
this->declare_parameter("param3", -1); | |
number0 = this->get_parameter("param0").as_int(); | |
number1 = this->get_parameter("param1").as_int(); | |
number2 = this->get_parameter("param2").as_int(); | |
number3 = this->get_parameter("param3").as_int(); | |
show_log(); | |
} | |
}; | |
int main(int argc, char** argv) | |
{ | |
rclcpp::init(argc, argv); | |
rclcpp::NodeOptions options; | |
auto node = std::make_shared<param_example>("param_example",options); | |
rclcpp::spin(node); | |
rclcpp::shutdown(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment