-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdefault.cpp
More file actions
62 lines (59 loc) · 1.98 KB
/
Copy pathdefault.cpp
File metadata and controls
62 lines (59 loc) · 1.98 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
// Copyright 2024 Simon Sagmeister
#include <iostream>
#include <param_management_cpp/base.hpp>
#include <param_management_cpp/param_value_manager.hpp>
#include <param_management_ros2_integration_cpp/helper_functions.hpp>
#include <rclcpp/node.hpp>
#include <rclcpp/rclcpp.hpp>
class MySoftwareModule
{
private:
tam::pmg::ParamValueManager::SharedPtr param_manager_ =
std::make_shared<tam::pmg::ParamValueManager>();
double val_;
void update_param_value()
{
val_ = param_manager_
->declare_and_get_value("a", 3.14, tam::pmg::ParameterType::DOUBLE, "Testparameter")
.as_double();
}
public:
MySoftwareModule()
{
// CAREFUL: Independent from the overwrite, you will always get the default value here
// since you create your module before connecting with a node or loading parameters
update_param_value();
std::cout << "Value (Constructor): " << val_ << std::endl;
}
void step()
{
update_param_value();
std::cout << "Value (Step): " << val_ << std::endl;
}
tam::pmg::MgmtInterface::SharedPtr get_param_manager() const { return param_manager_; }
};
class ExampleNode : public rclcpp::Node
{
private:
MySoftwareModule mod_;
public:
explicit ExampleNode(MySoftwareModule const && module)
: rclcpp::Node("TestNode"), mod_{std::move(module)}
{
// Connect your param manager to the callback
// Important: don't forget to store your callback handle here, otherwise it will get deallocated
auto callback_handle =
tam::pmg::connect_param_manager_to_ros_cb(this, mod_.get_param_manager());
// Declare all paramters from the param manager
tam::pmg::declare_ros_params_from_param_manager(this, mod_.get_param_manager().get());
// From now on, your module is supplied with the correct parameters from the overwrite file
mod_.step();
}
};
int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);
auto node = std::make_shared<ExampleNode>(MySoftwareModule());
rclcpp::spin(node);
rclcpp::shutdown();
}