SMACC2
Loading...
Searching...
No Matches
smacc2
src
smacc2
client_behaviors
cb_wait_topic.cpp
Go to the documentation of this file.
1
// Copyright 2021 RobosoftAI Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/*****************************************************************************************************************
16
*
17
* Authors: Pablo Inigo Blasco, Brett Aldrich
18
*
19
******************************************************************************************************************/
20
21
#include <
smacc2/client_behaviors/cb_wait_topic.hpp
>
22
23
namespace
smacc2
24
{
25
namespace
client_behaviors
26
{
27
CbWaitTopic::CbWaitTopic
(std::string
nodeName
) : topicName_(
nodeName
), rate_(5) {}
28
29
CbWaitTopic::~CbWaitTopic
() {}
30
31
void
CbWaitTopic::onEntry
()
32
{
33
bool
found
=
false
;
34
while
(!this->
isShutdownRequested
() && !found)
35
{
36
RCLCPP_INFO_STREAM_THROTTLE
(
37
getLogger
(), *(
getNode
()->
get_clock
()), 1000,
38
"["
<<
getName
() <<
"] waiting topic: "
<<
topicName_
);
39
std::stringstream
ss
;
40
auto
topicnames
=
getNode
()->get_topic_names_and_types();
41
42
for
(
auto
&
t
:
topicnames
)
43
{
44
ss
<<
t
.first << std::endl;
45
if
(
t
.first ==
topicName_
)
46
{
47
found
=
true
;
48
}
49
}
50
51
auto
totalstr
=
ss
.str();
52
RCLCPP_INFO_STREAM_THROTTLE
(
53
getLogger
(), *(
getNode
()->
get_clock
()), 5000,
54
"["
<<
getName
() <<
"] still waiting topic "
<<
topicName_
<<
", listing topics ("
55
<<
topicnames
.size() <<
")"
<< std::endl
56
<<
totalstr
);
57
58
rate_
.sleep();
59
}
60
61
if
(
found
)
62
{
63
this->
postSuccessEvent
();
64
}
65
else
66
{
67
this->
postFailureEvent
();
68
}
69
}
70
71
}
// namespace client_behaviors
72
}
// namespace smacc2
cb_wait_topic.hpp
smacc2::ISmaccClientBehavior::getName
std::string getName() const
Definition
smacc_client_behavior_base.cpp:36
smacc2::ISmaccClientBehavior::getLogger
virtual rclcpp::Logger getLogger() const
Definition
smacc_client_behavior_base.cpp:43
smacc2::ISmaccClientBehavior::getNode
virtual rclcpp::Node::SharedPtr getNode() const
Definition
smacc_client_behavior_base.cpp:38
smacc2::SmaccAsyncClientBehavior::postSuccessEvent
void postSuccessEvent()
Definition
smacc_client_async_behavior.cpp:153
smacc2::SmaccAsyncClientBehavior::isShutdownRequested
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...
Definition
smacc_client_async_behavior.cpp:165
smacc2::SmaccAsyncClientBehavior::postFailureEvent
void postFailureEvent()
Definition
smacc_client_async_behavior.cpp:155
smacc2::client_behaviors::CbWaitTopic::rate_
rclcpp::Rate rate_
Definition
cb_wait_topic.hpp:45
smacc2::client_behaviors::CbWaitTopic::onEntry
void onEntry() override
Definition
cb_wait_topic.cpp:31
smacc2::client_behaviors::CbWaitTopic::CbWaitTopic
CbWaitTopic(std::string topicName)
Definition
cb_wait_topic.cpp:27
smacc2::client_behaviors::CbWaitTopic::topicName_
std::string topicName_
Definition
cb_wait_topic.hpp:43
smacc2::client_behaviors::CbWaitTopic::~CbWaitTopic
virtual ~CbWaitTopic()
Definition
cb_wait_topic.cpp:29
smacc2
Definition
callback_counter_semaphore.hpp:30
smacc2::default_events::EvTopicMessage
Definition
smacc_default_events.hpp:155
Generated by
1.9.8