-
Notifications
You must be signed in to change notification settings - Fork 1
/
rclcpp_1746.cpp
44 lines (33 loc) · 1.04 KB
/
rclcpp_1746.cpp
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
#include <chrono>
#include <iostream>
#include <memory>
#include <thread>
#include "lifecycle_msgs/msg/transition.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp/publisher.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "rcutils/logging_macros.h"
/// Get current node state in a loop
void checkState(std::shared_ptr<rclcpp_lifecycle::LifecycleNode> node) {
// infinite loop
while (1) {
// This call fails
node->get_current_state().id();
}
}
int main(int argc, char * argv[])
{
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
rclcpp::init(argc, argv);
std::shared_ptr<rclcpp_lifecycle::LifecycleNode> lc_node =
std::make_shared<rclcpp_lifecycle::LifecycleNode>("lc_talker");
lc_node->trigger_transition(lifecycle_msgs::msg::Transition::TRANSITION_CONFIGURE);
// Created multiple threads
std::thread thread_object_1(checkState, lc_node);
std::thread thread_object_2(checkState, lc_node);
// wait
thread_object_1.join();
thread_object_2.join();
rclcpp::shutdown();
return 0;
}